From 6102db3f560dc813495adcb064989ef63cdfd54a Mon Sep 17 00:00:00 2001 From: frontend perkafean <165241731+frontendperkafean@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:00:10 +0000 Subject: [PATCH] ok --- src/App.js | 49 ++++++++++++------ src/components/Footer.js | 19 ++++--- src/components/Header.js | 4 +- src/components/Modal.js | 2 + src/components/QR.js | 29 +++++------ src/components/SearchInput.js | 8 +-- src/components/TableList.js | 83 ++++++++++++++++--------------- src/components/TablesPage.js | 5 +- src/helpers/navigationHelpers.js | 30 +++++------ src/helpers/transactionHelpers.js | 25 ++++++++++ src/pages/CafePage.js | 9 ++-- src/pages/Cart.js | 41 +++++++++------ src/pages/Invoice.js | 10 ++-- src/pages/SearchResult.js | 9 ++-- src/pages/Transaction_failed.js | 29 +++++++++++ src/pages/Transaction_success.js | 6 ++- src/pages/Transactions.js | 50 +++++++++++++++---- src/pages/Transactions.module.css | 4 ++ 18 files changed, 271 insertions(+), 141 deletions(-) create mode 100644 src/pages/Transaction_failed.js diff --git a/src/App.js b/src/App.js index 2cefcc6..6125ddd 100644 --- a/src/App.js +++ b/src/App.js @@ -23,6 +23,7 @@ import Footer from "./components/Footer"; import GuestSideLogin from "./pages/GuestSideLogin"; import GuestSide from "./pages/GuestSide"; import { getItemTypesWithItems } from "./helpers/itemHelper.js"; +import { getTableByCode } from "./helpers/tableHelper.js"; import { getConnectedGuestSides, @@ -44,7 +45,7 @@ function App() { const [guestSideOfClerk, setGuestSideOfClerk] = useState(null); const [guestSides, setGuestSides] = useState([]); const [shopId, setShopId] = useState(""); - const [tableId, setTableId] = useState(""); + const [table, setTable] = useState([]); const [totalItemsCount, setTotalItemsCount] = useState(0); const [deviceType, setDeviceType] = useState(""); const [shop, setShop] = useState([]); @@ -71,10 +72,13 @@ function App() { }; }, [shopId]); - const handleSetParam = ({ shopId, tableId }) => { - console.log(shopId, tableId); + const handleSetParam = async ({ shopId, tableCode }) => { setShopId(shopId); - setTableId(tableId); + + if (table.length == 0) { + const gettable = await getTableByCode(tableCode); + if (gettable) setTable(gettable); + } }; useEffect(() => { @@ -121,11 +125,17 @@ function App() { console.log("transaction notification"); setModal("transaction_pending"); }); + socket.on("transaction_success", async (data) => { console.log("transaction notification"); setModal("transaction_success"); }); + socket.on("transaction_failed", async (data) => { + console.log("transaction notification"); + setModal("transaction_failed"); + }); + //for clerk socket.on("transaction_created", async (data) => { console.log("transaction notification"); @@ -138,7 +148,10 @@ function App() { setDeviceType("guestDevice"); } else { setUser(data.data.user); - if (data.data.user.password == "unsetunsetunset") + if ( + data.data.user.password == "unsetunsetunset" && + localStorage.getItem("settings") + ) setModal("complete_account"); if (data.data.user.cafeId == shopId) { const connectedGuestSides = await getConnectedGuestSides(); @@ -190,7 +203,7 @@ function App() { }, [shopId]); useEffect(() => { - console.log(shopId + tableId); + console.log(shopId + table?.tableCode); }, [navigate]); // Function to open the modal @@ -247,10 +260,11 @@ function App() { } />