From bf7ea19d808843bb2c36136a0682cd87c9c238de Mon Sep 17 00:00:00 2001 From: everythingonblack Date: Tue, 13 May 2025 09:42:04 +0700 Subject: [PATCH] ok --- src/App.js | 44 ++++- src/components/ButtonWithReplica.css | 6 + src/components/Modal.js | 2 +- src/helpers/transactionHelpers.js | 16 +- src/pages/Cart.js | 3 +- src/pages/Invoice.module.css | 3 +- src/pages/Transaction_confirmed.js | 17 +- src/pages/Transaction_pending.js | 2 +- src/pages/Transactions.js | 280 +++++++++++++++------------ src/pages/Transactions.module.css | 2 +- 10 files changed, 238 insertions(+), 137 deletions(-) diff --git a/src/App.js b/src/App.js index 34d5ebc..265b578 100644 --- a/src/App.js +++ b/src/App.js @@ -27,6 +27,7 @@ import { getTableByCode } from "./helpers/tableHelper.js"; import { getTransactionsFromCafe, + checkIsMyTransaction } from "./helpers/transactionHelpers"; import { getConnectedGuestSides, @@ -82,6 +83,7 @@ function App() { 'transaction_failed', ]; + const calculateTotalsFromLocalStorage = () => { const { totalCount, totalPrice } = calculateTotals(shopId); setTotalItemsCount(totalCount); @@ -93,24 +95,55 @@ function App() { console.log(lastTransaction); if (lastTransaction != null) { + console.log(lastTransaction) setLastTransaction(lastTransaction); } }; useEffect(() => { - - calculateTotalsFromLocalStorage(); - + const init = async () => { + await checkLastTransaction(); + }; + + init(); // call the async function + const handleStorageChange = () => { calculateTotalsFromLocalStorage(); }; - + window.addEventListener("localStorageUpdated", handleStorageChange); - + return () => { window.removeEventListener("localStorageUpdated", handleStorageChange); }; }, [shopId]); + + const checkLastTransaction = async () => { + const { totalCount, totalPrice } = calculateTotals(shopId); + setTotalItemsCount(totalCount); + setTotalPrice(totalPrice); + + const lastTransactionStr = localStorage.getItem("lastTransaction"); + + if (!lastTransactionStr) return; + + const lastTransaction = JSON.parse(lastTransactionStr); + console.log(lastTransaction); + + if (!lastTransaction || !lastTransaction.transactionId) { + localStorage.removeItem("lastTransaction"); + return; + } + + const myLastTransaction = await checkIsMyTransaction(lastTransaction.transactionId); + console.log(myLastTransaction) + if (myLastTransaction.isMyTransaction) { + setLastTransaction(lastTransaction); + } else { + localStorage.removeItem("lastTransaction"); + } + }; + const handleSetParam = async ({ shopIdentifier, tableCode }) => { setShopIdentifier(shopIdentifier); @@ -728,6 +761,7 @@ setDepth(depthh); shopId={shopId} sendParam={handleSetParam} deviceType={deviceType} + paymentUrl={shop.qrPayment} /> {/*