diff --git a/client/package.json b/client/package.json index fe66bf07..93e9f7d3 100644 --- a/client/package.json +++ b/client/package.json @@ -7,7 +7,8 @@ "react-axios": "^2.0.3", "react-dom": "^16.9.0", "react-router-dom": "^5.0.1", - "react-scripts": "3.1.1" + "react-scripts": "3.1.1", + "sweetalert": "^2.1.2" }, "scripts": { "start": "react-scripts start", diff --git a/client/src/components/App/App.js b/client/src/components/App/App.js index 57255ac9..914c0fd6 100644 --- a/client/src/components/App/App.js +++ b/client/src/components/App/App.js @@ -1,11 +1,9 @@ -import React, { Component } from 'react' -import './App.css' -import { BrowserRouter as Router, Route } from 'react-router-dom' -import Home from '../Home' -import Shop from '../Shop' - - - +import React, { Component } from "react"; +import "./App.css"; +import { BrowserRouter as Router, Route } from "react-router-dom"; +import Home from "../Home"; +import Shop from "../Shop"; +import shipping_info from "../shipping_info"; class App extends Component { @@ -28,6 +26,7 @@ class App extends Component { + @@ -36,4 +35,4 @@ class App extends Component { } } -export default App \ No newline at end of file +export default App; diff --git a/client/src/components/shipping_info/index.js b/client/src/components/shipping_info/index.js new file mode 100644 index 00000000..052cc51a --- /dev/null +++ b/client/src/components/shipping_info/index.js @@ -0,0 +1,92 @@ +import React, { Component } from "react"; +import "./style.css"; +import swal from "sweetalert"; +import NavBar from "../Navbar"; +import axios from "axios"; + +class shippingInfo extends Component { + state = { + username: "", + phone: "", + Address: "", + Extra_Note: "" + }; + + changeInput = ({ target: { value, name } }) => { + this.setState({ [name]: value }); + }; + + handleSubmit = event => { + event.preventDefault(); + const { username, phone, Address, Extra_Note } = this.state; + + axios + .post("/shipping_info", { username, phone, Address, Extra_Note }) + .then(res => { + if (res.data) { + swal({ + title: + "Your Order is processed Contact us on phone No : 0598121490", + icon: "success", + button: "Home!" + }).then(function() { + window.location.href = "/"; + }); + } + }); + }; + + render() { + const { username, phone, Address, Extra_Note } = this.state; + return ( +
+ + +

Shipping info

+
+ + + + + + + + + + +
+
+ ); + } +} +export default shippingInfo; diff --git a/client/src/components/shipping_info/style.css b/client/src/components/shipping_info/style.css new file mode 100644 index 00000000..28a251fd --- /dev/null +++ b/client/src/components/shipping_info/style.css @@ -0,0 +1,31 @@ +.flex-container { + display: flex; + flex-direction: column; + border: 1px #000000; + } + .flex-container input[type="text"] { + border: 0px; + border-bottom: solid 1px; + width: 95%; + margin: 6% auto 6% auto; + font-size: 1.2em; + } + .confirm { + text-align: center; + align-items: center; + width: 193px; + height: 63px; + background-color: #50bb00; + border-radius: 5px; + border: 0px; + color: white; + margin: 20% 50% auto 24%; + font-size: 1.2em + } + .flex-container input[type="tel"] { + border: 0px; + border-bottom: solid 1px; + width: 95%; + margin: 6% auto 6% auto; + font-size: 1.2em; + } diff --git a/src/controller/add_order.js b/src/controller/add_order.js new file mode 100644 index 00000000..7a72908d --- /dev/null +++ b/src/controller/add_order.js @@ -0,0 +1,11 @@ +const postOrder = require('../database/queries/post_order') + +const addOrder = (req, res) => { + const { username, phone, Address, Extra_Note, orderID = 3 } = req.body + // The orderID will be token from the cookie after making the login page + + postOrder(username, phone, Address, Extra_Note, orderID) + .then(() => res.status(200).json({ res: 'success true' })) + .catch(err => err.status(500).json({ err: 'error for post shipping info' })) +} +module.exports = addOrder diff --git a/src/controller/getProducts.js b/src/controller/getProducts.js index d38ef30b..243d5f83 100644 --- a/src/controller/getProducts.js +++ b/src/controller/getProducts.js @@ -1,5 +1,5 @@ const getProduct = require('../database/queries/getAllProduct.js') exports.getAllProduct = (request, response) => { - getProduct().then(result => response.json(result)).catch(err => response.json(err)) -} \ No newline at end of file + getProduct().then(result => response.json(result)).catch(err => response.json(err)) +} diff --git a/src/controller/index.js b/src/controller/index.js index ed8204c7..f016a617 100644 --- a/src/controller/index.js +++ b/src/controller/index.js @@ -4,10 +4,11 @@ const { getAllProduct } = require('./getProducts.js') const { getAllcategoryProduct } = require('./get_category_products') const { searchForAllProduct } = require('./get_products_by_name') const getCategories = require('./get_category') +const add_order = require('./add_order') router.get('/shop/:category_id', getAllcategoryProduct) router.get('/search/:searchInput', searchForAllProduct) router.get('/shop', getAllProduct) - +router.post('/shipping_info', add_order) router.get('/category', getCategories) -module.exports = router \ No newline at end of file +module.exports = router diff --git a/src/database/db_connection.js b/src/database/db_connection.js index 13bbe36e..ebffc238 100644 --- a/src/database/db_connection.js +++ b/src/database/db_connection.js @@ -5,10 +5,10 @@ require('env2')('./config.env') const connectionString = process.env.DATABASE_URL if (!connectionString) { - throw new Error('Set a DATABASE_URL env variable') + throw new Error('Set a DATABASE_URL env variable') } module.exports = new Pool({ - connectionString, - ssl: !connectionString.includes('localhost') -}) \ No newline at end of file + connectionString, + ssl: !connectionString.includes('localhost') +}) diff --git a/src/database/queries/getAllProduct.js b/src/database/queries/getAllProduct.js index d386735b..2bacdf42 100644 --- a/src/database/queries/getAllProduct.js +++ b/src/database/queries/getAllProduct.js @@ -2,8 +2,8 @@ const dbConnection = require('../db_connection') const getProduct = () => { - return dbConnection.query('SELECT * FROM product') - .then(res => res.rows) - .catch(err => err) + return dbConnection.query('SELECT * FROM product') + .then(res => res.rows) + .catch(err => err) } -module.exports = getProduct \ No newline at end of file +module.exports = getProduct diff --git a/src/database/queries/post_order.js b/src/database/queries/post_order.js new file mode 100644 index 00000000..de2a3f14 --- /dev/null +++ b/src/database/queries/post_order.js @@ -0,0 +1,13 @@ +const dbConnection = require('../db_connection') + +const postOrder = (name, address, phone, note, ID) => { + return dbConnection + .query( + 'UPDATE "order" SET name=$1,address=$2,phone=$3,note=$4 WHERE ID=$5', + [name, address, phone, note, ID] + ) + .then(res => res.rows) + + .catch(err => err) +} +module.exports = postOrder