diff --git a/backend/node_modules/.package-lock.json b/backend/node_modules/.package-lock.json index 4a61a847df321d977aa7a7f94186b5efe523080e..917cf7ee9b0f1989a9434707feec8f6c6c8af2bf 100644 --- a/backend/node_modules/.package-lock.json +++ b/backend/node_modules/.package-lock.json @@ -351,6 +351,12 @@ "@types/node": "*" } }, + "node_modules/@types/crypto-js": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.1.tgz", + "integrity": "sha512-FSPGd9+OcSok3RsM0UZ/9fcvMOXJ1ENE/ZbLfOPlBWj7BgXtEAM8VYfTtT760GiLbQIMoVozwVuisjvsVwqYWw==", + "dev": true + }, "node_modules/@types/debug": { "version": "4.1.12", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", @@ -1266,6 +1272,11 @@ "node": ">= 8" } }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/css-select": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", @@ -2097,20 +2108,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", diff --git a/backend/package-lock.json b/backend/package-lock.json index b773c4c5e776a242b4e0e81cc0ce4160326243f1..7ddebeea8ca6d13711004347897eb2168dd24e82 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -13,6 +13,7 @@ "axios": "^1.6.2", "body-parser": "^1.20.2", "cors": "^2.8.5", + "crypto-js": "^4.2.0", "dotenv": "^16.3.1", "express": "^4.18.2", "pg": "^8.11.3", @@ -26,6 +27,7 @@ }, "devDependencies": { "@types/cors": "^2.8.16", + "@types/crypto-js": "^4.2.1", "@types/express": "^4.17.21", "@types/node": "^20.9.0", "@types/react": "^18.2.38", @@ -386,6 +388,12 @@ "@types/node": "*" } }, + "node_modules/@types/crypto-js": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.1.tgz", + "integrity": "sha512-FSPGd9+OcSok3RsM0UZ/9fcvMOXJ1ENE/ZbLfOPlBWj7BgXtEAM8VYfTtT760GiLbQIMoVozwVuisjvsVwqYWw==", + "dev": true + }, "node_modules/@types/debug": { "version": "4.1.12", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", @@ -1301,6 +1309,11 @@ "node": ">= 8" } }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/css-select": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", diff --git a/backend/package.json b/backend/package.json index 22cd6be6ead433eb0f1f043d5ef449e2844bbdbc..9b8dc69067c28a53492032912f3afcefd7e9e236 100644 --- a/backend/package.json +++ b/backend/package.json @@ -19,6 +19,7 @@ "axios": "^1.6.2", "body-parser": "^1.20.2", "cors": "^2.8.5", + "crypto-js": "^4.2.0", "dotenv": "^16.3.1", "express": "^4.18.2", "pg": "^8.11.3", @@ -32,6 +33,7 @@ }, "devDependencies": { "@types/cors": "^2.8.16", + "@types/crypto-js": "^4.2.1", "@types/express": "^4.17.21", "@types/node": "^20.9.0", "@types/react": "^18.2.38", diff --git a/backend/src/services/api/joinedOrderPayment.ts b/backend/src/services/api/joinedOrderPayment.ts index 6db3138f77ed5e3c3befffaf60c9215b8ebd6cac..f244279d61c9f9a14b0a64f838be26a9d42c044e 100644 --- a/backend/src/services/api/joinedOrderPayment.ts +++ b/backend/src/services/api/joinedOrderPayment.ts @@ -1,5 +1,6 @@ import Axios from "axios"; import { useEffect, useState } from "react"; +import crypto from "crypto-js"; export default function joinedOrderPayment() { const [joinedData, setJoinedData] = useState([]); @@ -15,9 +16,12 @@ export default function joinedOrderPayment() { const result = orderData.map((order: { id: number; id_table: number; time: Date; status: string; id_tenant: string }) => { const matchingPayment = paymentData.find((payment: { id_order: number; }) => payment.id_order === order.id); + // Hash the paymentId using SHA-256 from crypto-js and take the first 5 characters + const hashedPaymentId = matchingPayment ? crypto.SHA256(matchingPayment.id.toString()).toString().substring(0, 5) : null; + return { orderId: order.id, - paymentId: matchingPayment ? matchingPayment.id : null, + paymentId: matchingPayment ? hashedPaymentId : null, tableId: order.id_table, time: order.time, orderStatus: order.status, @@ -27,7 +31,6 @@ export default function joinedOrderPayment() { }); setJoinedData(result); - }; useEffect(() => { @@ -37,4 +40,4 @@ export default function joinedOrderPayment() { console.log(joinedData); return joinedData; -} \ No newline at end of file +} diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 020f94c1c7a7aec2df7012bcb9598b173b9c06a2..c35407e207e5e7438e6b1ce7da21155de7a0ee57 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@supabase/supabase-js": "^2.38.5", "axios": "^1.6.2", + "crypto-js": "^4.2.0", "dotenv": "^16.3.1", "flowbite": "^2.1.1", "flowbite-react": "^0.6.4", @@ -22,6 +23,7 @@ "react-toastify": "^9.1.3" }, "devDependencies": { + "@types/crypto-js": "^4.2.1", "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "@typescript-eslint/eslint-plugin": "^6.0.0", @@ -1120,6 +1122,12 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/crypto-js": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.1.tgz", + "integrity": "sha512-FSPGd9+OcSok3RsM0UZ/9fcvMOXJ1ENE/ZbLfOPlBWj7BgXtEAM8VYfTtT760GiLbQIMoVozwVuisjvsVwqYWw==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -1839,6 +1847,11 @@ "node": ">= 8" } }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/cssesc": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index b816a8e84cd83efb0f67c0659bd3535ca7bca873..2f18e47a7841b27a3217876fc821c36373b42b9b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,6 +12,7 @@ "dependencies": { "@supabase/supabase-js": "^2.38.5", "axios": "^1.6.2", + "crypto-js": "^4.2.0", "dotenv": "^16.3.1", "flowbite": "^2.1.1", "flowbite-react": "^0.6.4", @@ -24,6 +25,7 @@ "react-toastify": "^9.1.3" }, "devDependencies": { + "@types/crypto-js": "^4.2.1", "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "@typescript-eslint/eslint-plugin": "^6.0.0", diff --git a/frontend/src/components/MenuCard.tsx b/frontend/src/components/MenuCard.tsx index 55144e76ec8e19dd087299f05de65d9483d2abb3..b725f01dac930b3afe667f8ca9143d4ac517136b 100644 --- a/frontend/src/components/MenuCard.tsx +++ b/frontend/src/components/MenuCard.tsx @@ -3,7 +3,7 @@ export default function MenuCard(props: any) { <div> <div className="w-60 h-52 bg-white rounded-3xl drop-shadow-lg font-nunito"> <div className="flex flex-col items-center justify-center"> - <img className="rounded-3xl w-40 h-24 object-cover" src={props.image} alt="" /> + <img className="rounded-3xl w-40 h-24 object-contain" src={props.image} alt="" /> </div> <div className="mt-3 px-4"> <h5 className="mb-2 text-md font-extrabold tracking-tight text-gray-900"> diff --git a/frontend/src/components/OrderDetailsCard.tsx b/frontend/src/components/OrderDetailsCard.tsx index c88ae4d623eb12bc347fccbdca4fe8a1c00ec9c1..6a85db598cf84b7639eae0aba1db4c69bef1cc1b 100644 --- a/frontend/src/components/OrderDetailsCard.tsx +++ b/frontend/src/components/OrderDetailsCard.tsx @@ -1,7 +1,7 @@ import moment from "moment"; interface OrderDetailsCardProps { orderid: number, - code: number, + code: string | null, tableid: number, time: Date, orderstatus: string, diff --git a/frontend/src/components/OrderSummaryCard.tsx b/frontend/src/components/OrderSummaryCard.tsx index fe556e37d0e01d04d7a4f973d69d0b4fb2fc0609..af106b5bd5c6e08fe083262f782638fe27725c40 100644 --- a/frontend/src/components/OrderSummaryCard.tsx +++ b/frontend/src/components/OrderSummaryCard.tsx @@ -4,11 +4,11 @@ type OrderSummaryCardProps = { orderlist: (string | number)[][]; } -export default function OrderSummaryCard({data}: {data: OrderSummaryCardProps[]}) { - const orderdetails = data.map(({id,name, orderlist}) => { +export default function OrderSummaryCard({ data, customer }: { data: OrderSummaryCardProps[], customer: boolean }) { + const orderdetails = data.map(({ id, name, orderlist }) => { const orderList = () => { const orderList = orderlist.map((order: any) => { - const price = order[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".") + const price = order[2].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".") return ( <div className="flex justify-between py-7"> <p className="w-full font-normal text-lg text-gray-500 text-left">{order[0]}</p> @@ -17,30 +17,33 @@ export default function OrderSummaryCard({data}: {data: OrderSummaryCardProps[]} </div> ) }) - + return orderList } - + const totalPrice = () => { let totalPrice = 0 orderlist.forEach((order: any) => { totalPrice += order[2] * order[1] }) - + return totalPrice.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."); } - + return ( <div className="flex bg-white md:flex-row mx-16"> <div className="flex flex-col w-full leading-normal"> <div className="flex justify-between border-b border-gray-300 py-5"> <h5 className="font-bold text-2xl text-gray-900">{name}</h5> <div className="flex items-center"> - <a href={`/tenant/${id}`}> - <svg xmlns="http://www.w3.org/2000/svg" width="13" height="22" viewBox="0 0 13 22" fill="none"> - <path d="M3.34838 21.5784C3.09007 21.8512 2.7613 22 2.37382 22C1.59887 22 0.976563 21.3551 0.976563 20.5366C0.976563 20.1274 1.14095 19.7554 1.411 19.4701L9.63018 10.9876L1.411 2.52988C1.14095 2.24464 0.976563 1.8602 0.976563 1.46336C0.976563 0.64487 1.59887 0 2.37382 0C2.7613 0 3.09007 0.148816 3.34838 0.421646L12.4834 9.84667C12.8122 10.1691 12.9648 10.566 12.9766 11C12.9766 11.434 12.8122 11.8061 12.4834 12.1409L3.34838 21.5784Z" fill="#020202"/> - </svg> - </a> + {customer && ( + <a href={`/tenant/${id}`}> + <svg xmlns="http://www.w3.org/2000/svg" width="13" height="22" viewBox="0 0 13 22" fill="none"> + <path d="M3.34838 21.5784C3.09007 21.8512 2.7613 22 2.37382 22C1.59887 22 0.976563 21.3551 0.976563 20.5366C0.976563 20.1274 1.14095 19.7554 1.411 19.4701L9.63018 10.9876L1.411 2.52988C1.14095 2.24464 0.976563 1.8602 0.976563 1.46336C0.976563 0.64487 1.59887 0 2.37382 0C2.7613 0 3.09007 0.148816 3.34838 0.421646L12.4834 9.84667C12.8122 10.1691 12.9648 10.566 12.9766 11C12.9766 11.434 12.8122 11.8061 12.4834 12.1409L3.34838 21.5784Z" fill="#020202" /> + </svg> + </a> + ) + } </div> </div> <div className="border-b border-gray-300"> diff --git a/frontend/src/pages/ManageOrderTenant.tsx b/frontend/src/pages/ManageOrderTenant.tsx index 6eadecfb00dd683ce8dbb5203e6e0b6258a37ecf..76ab837dccdf9a0ef127fef647d5b74f8d410ec1 100644 --- a/frontend/src/pages/ManageOrderTenant.tsx +++ b/frontend/src/pages/ManageOrderTenant.tsx @@ -8,6 +8,7 @@ import { useEffect, useState } from "react"; import ProfileDropDown from "../components/ProfileDropDown"; import Axios from "axios"; import { useParams } from "react-router-dom"; +import crypto from "crypto-js"; interface Order { id: number, @@ -41,13 +42,14 @@ interface Payment { } interface OrderSummary { + id: number, name: string, orderlist: (string | number)[][] } interface OrderDetails { orderid: number, - code: number, + code: string | null, tableid: number, time: Date, orderstatus: string, @@ -86,6 +88,7 @@ export default function OrderDetails() { }); return { + id: tenant?.id || 0, name: tenant?.name || 'Tenant Not Found', orderlist: listproduct }; @@ -115,18 +118,20 @@ export default function OrderDetails() { const result = OrderDataArray.map((order: Order) => { const matchingPayment = paymentData.find((payment: Payment) => payment.id_order === order.id); + // Hash the code (matchingPayment.id) using SHA-256 from crypto-js and take the first 5 characters + const hashedCode = matchingPayment ? crypto.SHA256(matchingPayment.id.toString()).toString().substring(0, 5) : null; + return { orderid: order.id, - code: matchingPayment.id, + code: hashedCode, tableid: order.id_table, time: order.time, orderstatus: order.status, - paymentstatus: matchingPayment.status + paymentstatus: matchingPayment ? matchingPayment.status : null }; }); setJoinedOrderDetailsData(result); - }; useEffect(() => { @@ -250,7 +255,7 @@ export default function OrderDetails() { <div className="ms-20 py-12 bg-white rounded-3xl"> <h2 className="text-mealshub-red text-3xl font-bold ms-16">Order Details</h2> <OrderDetailsCard data={joinedOrderDetailsData} /> - <OrderSummaryCard data={joinedOrderSummaryData} /> + <OrderSummaryCard data={joinedOrderSummaryData} customer={false} /> <div className="flex flex-col items-center"> <button onClick={buttonState.onClick} diff --git a/frontend/src/pages/ManagePayment.tsx b/frontend/src/pages/ManagePayment.tsx index 8e800ac6d1a2c082dffc0179e617145b0719a99f..fd3ea61e2bbc0f3f5bf8e9c456ed24ad0f6dc89d 100644 --- a/frontend/src/pages/ManagePayment.tsx +++ b/frontend/src/pages/ManagePayment.tsx @@ -9,6 +9,7 @@ import { useEffect, useState } from "react"; import ConfirmPopUp from "../components/ConfirmPopUp"; import Axios from "axios"; import { useParams } from "react-router-dom"; +import crypto from "crypto-js"; interface Order { id: number; @@ -42,13 +43,14 @@ interface Payment { } interface OrderSummary { - name: string; - orderlist: (string | number)[][]; + id: number, + name: string, + orderlist: (string | number)[][] } interface OrderDetails { orderid: number; - code: number; + code: string | null; tableid: number; time: Date; orderstatus: string; @@ -58,25 +60,19 @@ interface OrderDetails { const ManagePayment = () => { const { orderid } = useParams(); const paymentid = orderid; - const [confirmed, setConfirmed] = useState(false); const [showProfileDropDown, setShowProfileDropDown] = useState(false); - const [showConfirmPopUp, setShowConfirmPopUp] = useState(false); - const [joinedOrderDetailsData, setJoinedOrderDetailsData] = useState< - OrderDetails[] - >([]); + const [buttonState, setButtonState] = useState({ label: "Waiting for Payment", disabled: true, color: "mealshub-greenpalet", onClick: () => { }, }); + const [joinedOrderDetailsData, setJoinedOrderDetailsData] = useState<OrderDetails[]>([]); + const getOrderDetailsData = async () => { - const orderResponse = await Axios.get( - `http://localhost:8000/orders/${orderid}`, - ); - const paymentResponse = await Axios.get( - "http://localhost:8000/payments", - ); + const orderResponse = await Axios.get(`http://localhost:8000/orders/${orderid}`); + const paymentResponse = await Axios.get("http://localhost:8000/payments"); const orderData = orderResponse.data.data; const paymentData = paymentResponse.data.data; @@ -84,25 +80,73 @@ const ManagePayment = () => { // Perform the join based on the specified conditions const OrderDataArray = [orderData]; const result = OrderDataArray.map((order: Order) => { - const matchingPayment = paymentData.find( - (payment: Payment) => payment.id_order === order.id, - ); + const matchingPayment = paymentData.find((payment: Payment) => payment.id_order === order.id); + + // Hash the code (matchingPayment.id) using SHA-256 from crypto-js and take the first 5 characters + const hashedCode = matchingPayment ? crypto.SHA256(matchingPayment.id.toString()).toString().substring(0, 5) : null; return { orderid: order.id, - code: matchingPayment.id, + code: hashedCode, tableid: order.id_table, time: order.time, orderstatus: order.status, - paymentstatus: matchingPayment.status, + paymentstatus: matchingPayment ? matchingPayment.status : null }; }); setJoinedOrderDetailsData(result); }; - const [joinedOrderSummaryData, setJoinedOrderSummaryData] = useState< - OrderSummary[] - >([]); + + useEffect(() => { + getOrderDetailsData(); + }, []); + + console.log(joinedOrderDetailsData); + + const [joinedOrderSummaryData, setJoinedOrderSummaryData] = useState<OrderSummary[]>([]); + + const getOrderSummaryData = async () => { + const orderResponse = await Axios.get(`http://localhost:8000/orders/${orderid}`); + const productResponse = await Axios.get("http://localhost:8000/products"); + const orderProductResponse = await Axios.get("http://localhost:8000/orderproduct"); + const tenantResponse = await Axios.get("http://localhost:8000/tenants"); + + const orderData = orderResponse.data.data; + const productData = productResponse.data.data; + const orderProductData = orderProductResponse.data.data; + const tenantData = tenantResponse.data.data; + + // Perform the join based on the specified conditions + // OrderData is not an array, so we need to convert it into an array + const orderDataArray = [orderData]; + const result = orderDataArray.map((order: Order) => { + const tenant = tenantData.find((tenant: Tenant) => tenant.id === order.id_tenant); + const orderproduct = orderProductData.filter((orderProduct: OrderProduct) => orderProduct.id_order === order.id); + const listproduct = orderproduct.map((orderProduct: OrderProduct) => { + const product = productData.find((product: Product) => product.id === orderProduct.id_product); + return [product?.name || 'Product Not Found', orderProduct.num_product, product?.price || 0]; + }); + + return { + id: tenant?.id || 0, + name: tenant?.name || 'Tenant Not Found', + orderlist: listproduct + }; + }); + + setJoinedOrderSummaryData(result); + + }; + + useEffect(() => { + getOrderDetailsData(); + }, []); + useEffect(() => { + getOrderSummaryData(); + }, []); + + console.log(joinedOrderSummaryData); const handleProfileClick = () => { setShowProfileDropDown(!showProfileDropDown); @@ -135,64 +179,6 @@ const ManagePayment = () => { } }; - const getOrderSummaryData = async () => { - const orderResponse = await Axios.get( - `http://localhost:8000/orders/${orderid}`, - ); - const productResponse = await Axios.get( - "http://localhost:8000/products", - ); - const orderProductResponse = await Axios.get( - "http://localhost:8000/orderproduct", - ); - const tenantResponse = await Axios.get("http://localhost:8000/tenants"); - - const orderData = orderResponse.data.data; - const productData = productResponse.data.data; - const orderProductData = orderProductResponse.data.data; - const tenantData = tenantResponse.data.data; - - // Perform the join based on the specified conditions - // OrderData is not an array, so we need to convert it into an array - const orderDataArray = [orderData]; - const result = orderDataArray.map((order: Order) => { - const tenant = tenantData.find( - (tenant: Tenant) => tenant.id === order.id_tenant, - ); - const orderproduct = orderProductData.filter( - (orderProduct: OrderProduct) => - orderProduct.id_order === order.id, - ); - const listproduct = orderproduct.map( - (orderProduct: OrderProduct) => { - const product = productData.find( - (product: Product) => - product.id === orderProduct.id_product, - ); - return [ - product.name, - orderProduct.num_product, - product.price, - ]; - }, - ); - - return { - name: tenant.name, - orderlist: listproduct, - }; - }); - - setJoinedOrderSummaryData(result); - }; - useEffect(() => { - getOrderDetailsData(); - }, []); - useEffect(() => { - getOrderSummaryData(); - }, []); - - console.log(joinedOrderSummaryData); useEffect(() => { // Update button state based on payment and order status if (joinedOrderDetailsData.length > 0) { @@ -257,7 +243,7 @@ const ManagePayment = () => { Order Details </h2> <OrderDetailsCard data={joinedOrderDetailsData} /> - <OrderSummaryCard data={joinedOrderSummaryData} /> + <OrderSummaryCard data={joinedOrderSummaryData} customer={false} /> <div className="flex mx-16 justify-center"> <button onClick={buttonState.onClick} diff --git a/frontend/src/pages/OrderList.tsx b/frontend/src/pages/OrderList.tsx index f7379005c2f3dd3f142cff5fe3065e01a434fd4e..9481001dd3b9e6cb67114d91cecdd82dad6907e2 100644 --- a/frontend/src/pages/OrderList.tsx +++ b/frontend/src/pages/OrderList.tsx @@ -44,7 +44,7 @@ interface joinedData { } export default function OrderList() { - const tableid = 1; + const tableid = 101; const [joinedData, setJoinedData] = useState<joinedData[]>([]); const getData = async () => { @@ -65,36 +65,36 @@ export default function OrderList() { const result = ordertable.map((order: Order) => { const tenant = tenantData.find((tenant: Tenant) => tenant.id === order.id_tenant); const orderproduct = orderProductData.filter((orderProduct: OrderProduct) => orderProduct.id_order === order.id); - const listproduct = orderproduct.map((orderProduct: OrderProduct) => { - const product = productData.find((product: Product) => product.id === orderProduct.id_product); - - if (!product) { - return ["Product Not Found", orderProduct.num_product]; - } - - return [product.name, orderProduct.num_product]; + const listproduct = orderproduct.map((orderProduct: OrderProduct) => { + const product = productData.find((product: Product) => product.id === orderProduct.id_product); + + if (!product) { + return ["Product Not Found", orderProduct.num_product]; + } + + return [product.name, orderProduct.num_product]; + }); + + const totalprice = orderproduct.reduce((total: number, orderProduct: OrderProduct) => { + const product = productData.find((product: Product) => product.id === orderProduct.id_product); + + if (!product) { + return total; + } + + return total + product.price * orderProduct.num_product; + }, 0); + + return { + id: order.id, + image: tenant.image, + name: tenant.name, + status: order.status, + orderlist: listproduct, + price: totalprice, + }; }); - const totalprice = orderproduct.reduce((total: number, orderProduct: OrderProduct) => { - const product = productData.find((product: Product) => product.id === orderProduct.id_product); - - if (!product) { - return total; - } - - return total + product.price * orderProduct.num_product; - }, 0); - - return { - id: order.id, - image: tenant.image, - name: tenant.name, - status: order.status, - orderlist: listproduct, - price: totalprice, - }; - }); - setJoinedData(result); }; @@ -110,18 +110,18 @@ export default function OrderList() { <div className="grid grid-cols-5 grid-rows-8 bg-mealshub-cream min-h-screen"> {/* Sidebar */} <div className="col-span-1 row-span-8"> - <Sidebar customer={true} number={3} current={3} menu1="Home" page1="/" path1="M27 14.6465V29.4398C27 30.1188 26.7629 30.77 26.341 31.2501C25.919 31.7303 25.3467 32 24.75 32H19.125C18.5282 32 17.9559 31.7303 17.534 31.2501C17.112 30.77 16.875 30.1188 16.875 29.4398V23.0392C16.875 22.6997 16.7565 22.3741 16.5455 22.1341C16.3345 21.894 16.0484 21.7591 15.75 21.7591H11.25C10.9516 21.7591 10.6655 21.894 10.4545 22.1341C10.2435 22.3741 10.125 22.6997 10.125 23.0392V29.4398C10.125 30.1188 9.88794 30.77 9.46598 31.2501C9.04402 31.7303 8.47173 32 7.87499 32H2.25C1.65326 32 1.08097 31.7303 0.659009 31.2501C0.237052 30.77 2.59985e-08 30.1188 2.59985e-08 29.4398V14.6465C-4.73102e-05 14.2922 0.0645457 13.9417 0.189691 13.6172C0.314836 13.2928 0.497809 13.0014 0.72703 12.7616L11.977 0.683737L11.9925 0.666135C12.4067 0.237512 12.9464 0 13.5063 0C14.0662 0 14.6059 0.237512 15.0201 0.666135C15.0249 0.672397 15.0301 0.678277 15.0356 0.683737L26.2856 12.7616C26.5125 13.0027 26.6931 13.2946 26.8161 13.619C26.939 13.9434 27.0016 14.2933 27 14.6465Z" menu2="Shopping Cart" page2="/cart" path2="M22.2968 25.6C20.7499 25.6 19.5097 27.024 19.5097 28.8C19.5097 29.6487 19.8033 30.4626 20.326 31.0627C20.8487 31.6629 21.5576 32 22.2968 32C23.036 32 23.7449 31.6629 24.2675 31.0627C24.7902 30.4626 25.0839 29.6487 25.0839 28.8C25.0839 27.9513 24.7902 27.1374 24.2675 26.5373C23.7449 25.9371 23.036 25.6 22.2968 25.6ZM0 0V3.2H2.7871L7.80387 15.344L5.90864 19.264C5.69961 19.712 5.57419 20.24 5.57419 20.8C5.57419 21.6487 5.86783 22.4626 6.39051 23.0627C6.9132 23.6629 7.62211 24 8.36129 24H25.0839V20.8H8.94658C8.85418 20.8 8.76557 20.7579 8.70023 20.6828C8.6349 20.6078 8.59819 20.5061 8.59819 20.4C8.59819 20.32 8.61213 20.256 8.64 20.208L9.89419 17.6H20.2761C21.3213 17.6 22.241 16.928 22.7148 15.952L27.7037 5.6C27.8013 5.344 27.871 5.072 27.871 4.8C27.871 4.37565 27.7241 3.96869 27.4628 3.66863C27.2015 3.36857 26.847 3.2 26.4774 3.2H5.86684L4.5569 0M8.36129 25.6C6.81445 25.6 5.57419 27.024 5.57419 28.8C5.57419 29.6487 5.86783 30.4626 6.39051 31.0627C6.9132 31.6629 7.62211 32 8.36129 32C9.10047 32 9.80938 31.6629 10.3321 31.0627C10.8547 30.4626 11.1484 29.6487 11.1484 28.8C11.1484 27.9513 10.8547 27.1374 10.3321 26.5373C9.80938 25.9371 9.10047 25.6 8.36129 25.6Z" menu3="Orders" page3={`/order/list/${tableid}`} path3="M4.10306 1.10306C3 2.20612 3 3.97929 3 7.52941V24.4706C3 28.0207 3 29.7939 4.10306 30.8969C5.20612 32 6.97929 32 10.5294 32H21.8235C25.3736 32 27.1468 32 28.2499 30.8969C29.3529 29.7939 29.3529 28.0207 29.3529 24.4706V7.52941C29.3529 3.97929 29.3529 2.20612 28.2499 1.10306C27.1468 -1.12197e-07 25.3736 0 21.8235 0H10.5294C6.97929 0 5.20612 -1.12197e-07 4.10306 1.10306ZM10.5294 7.52941C10.0302 7.52941 9.5514 7.72773 9.19839 8.08074C8.84538 8.43375 8.64706 8.91253 8.64706 9.41176C8.64706 9.911 8.84538 10.3898 9.19839 10.7428C9.5514 11.0958 10.0302 11.2941 10.5294 11.2941H21.8235C22.3228 11.2941 22.8015 11.0958 23.1546 10.7428C23.5076 10.3898 23.7059 9.911 23.7059 9.41176C23.7059 8.91253 23.5076 8.43375 23.1546 8.08074C22.8015 7.72773 22.3228 7.52941 21.8235 7.52941H10.5294ZM10.5294 15.0588C10.0302 15.0588 9.5514 15.2571 9.19839 15.6102C8.84538 15.9632 8.64706 16.4419 8.64706 16.9412C8.64706 17.4404 8.84538 17.9192 9.19839 18.2722C9.5514 18.6252 10.0302 18.8235 10.5294 18.8235H21.8235C22.3228 18.8235 22.8015 18.6252 23.1546 18.2722C23.5076 17.9192 23.7059 17.4404 23.7059 16.9412C23.7059 16.4419 23.5076 15.9632 23.1546 15.6102C22.8015 15.2571 22.3228 15.0588 21.8235 15.0588H10.5294ZM10.5294 22.5882C10.0302 22.5882 9.5514 22.7866 9.19839 23.1396C8.84538 23.4926 8.64706 23.9714 8.64706 24.4706C8.64706 24.9698 8.84538 25.4486 9.19839 25.8016C9.5514 26.1546 10.0302 26.3529 10.5294 26.3529H18.0588C18.5581 26.3529 19.0368 26.1546 19.3898 25.8016C19.7429 25.4486 19.9412 24.9698 19.9412 24.4706C19.9412 23.9714 19.7429 23.4926 19.3898 23.1396C19.0368 22.7866 18.5581 22.5882 18.0588 22.5882H10.5294Z"/> + <Sidebar customer={true} number={3} current={3} menu1="Home" page1="/" path1="M27 14.6465V29.4398C27 30.1188 26.7629 30.77 26.341 31.2501C25.919 31.7303 25.3467 32 24.75 32H19.125C18.5282 32 17.9559 31.7303 17.534 31.2501C17.112 30.77 16.875 30.1188 16.875 29.4398V23.0392C16.875 22.6997 16.7565 22.3741 16.5455 22.1341C16.3345 21.894 16.0484 21.7591 15.75 21.7591H11.25C10.9516 21.7591 10.6655 21.894 10.4545 22.1341C10.2435 22.3741 10.125 22.6997 10.125 23.0392V29.4398C10.125 30.1188 9.88794 30.77 9.46598 31.2501C9.04402 31.7303 8.47173 32 7.87499 32H2.25C1.65326 32 1.08097 31.7303 0.659009 31.2501C0.237052 30.77 2.59985e-08 30.1188 2.59985e-08 29.4398V14.6465C-4.73102e-05 14.2922 0.0645457 13.9417 0.189691 13.6172C0.314836 13.2928 0.497809 13.0014 0.72703 12.7616L11.977 0.683737L11.9925 0.666135C12.4067 0.237512 12.9464 0 13.5063 0C14.0662 0 14.6059 0.237512 15.0201 0.666135C15.0249 0.672397 15.0301 0.678277 15.0356 0.683737L26.2856 12.7616C26.5125 13.0027 26.6931 13.2946 26.8161 13.619C26.939 13.9434 27.0016 14.2933 27 14.6465Z" menu2="Shopping Cart" page2="/cart" path2="M22.2968 25.6C20.7499 25.6 19.5097 27.024 19.5097 28.8C19.5097 29.6487 19.8033 30.4626 20.326 31.0627C20.8487 31.6629 21.5576 32 22.2968 32C23.036 32 23.7449 31.6629 24.2675 31.0627C24.7902 30.4626 25.0839 29.6487 25.0839 28.8C25.0839 27.9513 24.7902 27.1374 24.2675 26.5373C23.7449 25.9371 23.036 25.6 22.2968 25.6ZM0 0V3.2H2.7871L7.80387 15.344L5.90864 19.264C5.69961 19.712 5.57419 20.24 5.57419 20.8C5.57419 21.6487 5.86783 22.4626 6.39051 23.0627C6.9132 23.6629 7.62211 24 8.36129 24H25.0839V20.8H8.94658C8.85418 20.8 8.76557 20.7579 8.70023 20.6828C8.6349 20.6078 8.59819 20.5061 8.59819 20.4C8.59819 20.32 8.61213 20.256 8.64 20.208L9.89419 17.6H20.2761C21.3213 17.6 22.241 16.928 22.7148 15.952L27.7037 5.6C27.8013 5.344 27.871 5.072 27.871 4.8C27.871 4.37565 27.7241 3.96869 27.4628 3.66863C27.2015 3.36857 26.847 3.2 26.4774 3.2H5.86684L4.5569 0M8.36129 25.6C6.81445 25.6 5.57419 27.024 5.57419 28.8C5.57419 29.6487 5.86783 30.4626 6.39051 31.0627C6.9132 31.6629 7.62211 32 8.36129 32C9.10047 32 9.80938 31.6629 10.3321 31.0627C10.8547 30.4626 11.1484 29.6487 11.1484 28.8C11.1484 27.9513 10.8547 27.1374 10.3321 26.5373C9.80938 25.9371 9.10047 25.6 8.36129 25.6Z" menu3="Orders" page3={`/order/list/${tableid}`} path3="M4.10306 1.10306C3 2.20612 3 3.97929 3 7.52941V24.4706C3 28.0207 3 29.7939 4.10306 30.8969C5.20612 32 6.97929 32 10.5294 32H21.8235C25.3736 32 27.1468 32 28.2499 30.8969C29.3529 29.7939 29.3529 28.0207 29.3529 24.4706V7.52941C29.3529 3.97929 29.3529 2.20612 28.2499 1.10306C27.1468 -1.12197e-07 25.3736 0 21.8235 0H10.5294C6.97929 0 5.20612 -1.12197e-07 4.10306 1.10306ZM10.5294 7.52941C10.0302 7.52941 9.5514 7.72773 9.19839 8.08074C8.84538 8.43375 8.64706 8.91253 8.64706 9.41176C8.64706 9.911 8.84538 10.3898 9.19839 10.7428C9.5514 11.0958 10.0302 11.2941 10.5294 11.2941H21.8235C22.3228 11.2941 22.8015 11.0958 23.1546 10.7428C23.5076 10.3898 23.7059 9.911 23.7059 9.41176C23.7059 8.91253 23.5076 8.43375 23.1546 8.08074C22.8015 7.72773 22.3228 7.52941 21.8235 7.52941H10.5294ZM10.5294 15.0588C10.0302 15.0588 9.5514 15.2571 9.19839 15.6102C8.84538 15.9632 8.64706 16.4419 8.64706 16.9412C8.64706 17.4404 8.84538 17.9192 9.19839 18.2722C9.5514 18.6252 10.0302 18.8235 10.5294 18.8235H21.8235C22.3228 18.8235 22.8015 18.6252 23.1546 18.2722C23.5076 17.9192 23.7059 17.4404 23.7059 16.9412C23.7059 16.4419 23.5076 15.9632 23.1546 15.6102C22.8015 15.2571 22.3228 15.0588 21.8235 15.0588H10.5294ZM10.5294 22.5882C10.0302 22.5882 9.5514 22.7866 9.19839 23.1396C8.84538 23.4926 8.64706 23.9714 8.64706 24.4706C8.64706 24.9698 8.84538 25.4486 9.19839 25.8016C9.5514 26.1546 10.0302 26.3529 10.5294 26.3529H18.0588C18.5581 26.3529 19.0368 26.1546 19.3898 25.8016C19.7429 25.4486 19.9412 24.9698 19.9412 24.4706C19.9412 23.9714 19.7429 23.4926 19.3898 23.1396C19.0368 22.7866 18.5581 22.5882 18.0588 22.5882H10.5294Z" /> </div> {/* Header */} <div className="col-span-4"> <div className="ms-20"> <div className="row-span-1 mt-9 py-3 w-11/12"> - <WelcomingText name="Table 1"/> + <WelcomingText name="Table 1" /> </div> <div className="row-span-7 mt-6 mb-9 py-12 w-11/12 bg-white rounded-3xl"> <div className=""> <h2 className="text-mealshub-red text-3xl font-bold ms-16">Your Order</h2> - <OrderCard data={joinedData}/> + <OrderCard data={joinedData} /> </div> </div> </div> diff --git a/frontend/src/pages/OrderSummary.tsx b/frontend/src/pages/OrderSummary.tsx index 3a51405ece88b091c7affb107e70aac349860880..1355ea995d0fa79cb02246d163fb6baf11deb346 100644 --- a/frontend/src/pages/OrderSummary.tsx +++ b/frontend/src/pages/OrderSummary.tsx @@ -6,6 +6,7 @@ import BackButton from "../components/BackButton"; import { useEffect, useState } from "react"; import Axios from "axios"; import { useParams } from "react-router-dom"; +import crypto from "crypto-js"; interface Order { id: number, @@ -46,7 +47,7 @@ interface OrderSummary { interface OrderDetails { orderid: number, - code: number, + code: string | null, tableid: number, time: Date, orderstatus: string, @@ -110,18 +111,20 @@ export default function OrderSummary() { const result = OrderDataArray.map((order: Order) => { const matchingPayment = paymentData.find((payment: Payment) => payment.id_order === order.id); + // Hash the code (matchingPayment.id) using SHA-256 from crypto-js and take the first 5 characters + const hashedCode = matchingPayment ? crypto.SHA256(matchingPayment.id.toString()).toString().substring(0, 5) : null; + return { orderid: order.id, - code: matchingPayment.id, + code: hashedCode, tableid: order.id_table, time: order.time, orderstatus: order.status, - paymentstatus: matchingPayment.status + paymentstatus: matchingPayment ? matchingPayment.status : null }; }); setJoinedOrderDetailsData(result); - }; useEffect(() => { @@ -151,7 +154,7 @@ export default function OrderSummary() { <div className="ms-20 py-12 bg-white rounded-3xl"> <h2 className="text-mealshub-red text-3xl font-bold ms-16">Order Summary</h2> <OrderDetailsCard data={joinedOrderDetailsData} /> - <OrderSummaryCard data={joinedOrderSummaryData} /> + <OrderSummaryCard data={joinedOrderSummaryData} customer={true} /> {joinedOrderDetailsData.map((order) => { if (order.paymentstatus === "Waiting for Confirmation") { return (