From a64b999a0520e02342fc588733031260529a6e79 Mon Sep 17 00:00:00 2001 From: zadit <75159257+insvrgent@users.noreply.github.com> Date: Sat, 15 Mar 2025 18:59:44 +0700 Subject: [PATCH] ok --- .vscode/settings.json | 2 + package-lock.json | 6 + package.json | 3 +- src/App.js | 58 ++++- src/components/ButtonWithReplica.css | 2 +- src/components/Header.js | 3 +- src/components/Modal.js | 10 +- src/components/PaymentOptions.js | 188 ++++++++++----- src/components/TablesPage.js | 71 +++--- src/config.js | 2 +- src/helpers/cafeHelpers.js | 53 ++++- src/helpers/transactionHelpers.js | 114 +++++++-- src/index.js | 6 +- src/pages/CafePage.js | 22 +- src/pages/Cart.js | 336 +++++++++++++++++++-------- src/pages/CreateCoupon.js | 2 +- src/pages/Dropdown.js | 162 +++++++++++++ src/pages/Dropdown.module.css | 60 +++++ src/pages/Invoice.module.css | 47 +++- src/pages/Payment_claimed.js | 4 +- src/pages/Reports.js | 4 + src/pages/Transaction.js | 88 +++++-- src/pages/Transaction_confirmed.js | 173 +++++++++----- src/pages/Transaction_end.js | 250 ++++++++++++++++++-- src/pages/Transaction_item.js | 139 +++++++++++ src/pages/Transaction_pending.js | 39 ++-- src/pages/Transaction_success.js | 272 ++++++++++++++++++---- src/pages/Transactions.js | 24 +- src/pages/Transactions.module.css | 28 ++- src/pages/Unavailable.js | 41 ++++ 30 files changed, 1818 insertions(+), 391 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/pages/Dropdown.js create mode 100644 src/pages/Dropdown.module.css create mode 100644 src/pages/Transaction_item.js create mode 100644 src/pages/Unavailable.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5036e53..dd11af5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@testing-library/user-event": "^13.5.0", "caniuse-lite": "^1.0.30001690", "crypto-js": "^4.2.0", + "dayjs": "^1.11.13", "html-to-image": "^1.11.11", "html2canvas": "^1.4.1", "jsqr": "^1.4.0", @@ -7760,6 +7761,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/dayjs": { + "version": "1.11.13", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz", + "integrity": "sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==" + }, "node_modules/debug": { "version": "4.3.5", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", diff --git a/package.json b/package.json index 5b8a6e9..86552a3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "groovebrew-mockup", "version": "0.1.0", "private": true, - "homepage": "https://kedaimaster.com", + "homepage": "https://dev.kedaimaster.com", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", @@ -12,6 +12,7 @@ "@testing-library/user-event": "^13.5.0", "caniuse-lite": "^1.0.30001690", "crypto-js": "^4.2.0", + "dayjs": "^1.11.13", "html-to-image": "^1.11.11", "html2canvas": "^1.4.1", "jsqr": "^1.4.0", diff --git a/src/App.js b/src/App.js index 3fb61f4..b3c6e3c 100644 --- a/src/App.js +++ b/src/App.js @@ -56,6 +56,7 @@ function App() { const [table, setTable] = useState([]); const [totalItemsCount, setTotalItemsCount] = useState(0); const [totalPrice, setTotalPrice] = useState(0); + const [lastTransaction, setLastTransaction] = useState(null); const [deviceType, setDeviceType] = useState(""); const [shop, setShop] = useState([]); const [shopItems, setShopItems] = useState([]); @@ -77,12 +78,22 @@ function App() { 'transaction_failed', ]; + const calculateTotalsFromLocalStorage = () => { + const { totalCount, totalPrice } = calculateTotals(shopId); + setTotalItemsCount(totalCount); + setTotalPrice(totalPrice); + + + // If 'lastTransaction' exists, proceed + const lastTransaction = JSON.parse(localStorage.getItem("lastTransaction")); + console.log(lastTransaction); + + if (lastTransaction != null) { + setLastTransaction(lastTransaction); + } + }; + useEffect(() => { - const calculateTotalsFromLocalStorage = () => { - const { totalCount, totalPrice } = calculateTotals(shopId); - setTotalItemsCount(totalCount); - setTotalPrice(totalPrice); - }; calculateTotalsFromLocalStorage(); @@ -181,12 +192,41 @@ function App() { console.log("transaction notification"); // Call `setModal` with content and parameters setModal("transaction_pending", data); + + localStorage.setItem('cart', []); + + calculateTotalsFromLocalStorage(); }); socket.on("transaction_confirmed", async (data) => { - console.log("transaction notification" + data); + console.log("transaction notification: " + data); setModal("transaction_confirmed", data); + + localStorage.setItem('cart', []); + + const startTime = Date.now(); // Capture the start time + const timeout = 10000; // 10 seconds timeout in milliseconds + + calculateTotalsFromLocalStorage(); + + while (localStorage.getItem("lastTransaction") === null) { + if (Date.now() - startTime > timeout) { + return; // Exit the function and don't proceed further + } + + await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait 1 second + } + + + // If 'lastTransaction' exists, proceed + const lastTransaction = JSON.parse(localStorage.getItem("lastTransaction")); + console.log(lastTransaction); + + if (lastTransaction != null) { + setLastTransaction(lastTransaction); + } }); + socket.on("transaction_success", async (data) => { console.log("transaction notification"); @@ -228,6 +268,7 @@ function App() { } else { console.log(data) setUser(data.data.user); + if(data.data.latestOpenBillTransaction != null) localStorage.setItem('lastTransaction', JSON.stringify(data.data.latestOpenBillTransaction)) if ( data.data.user.password == "unsetunsetunset" && localStorage.getItem("settings") @@ -567,6 +608,7 @@ function App() { queue={queue} cartItemsLength={totalItemsCount} totalPrice={totalPrice} + lastTransaction={lastTransaction} /> {/*