This commit is contained in:
everythingonblack
2025-05-13 09:42:04 +07:00
parent 5ddf09e3d9
commit bf7ea19d80
10 changed files with 238 additions and 137 deletions

View File

@@ -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}
/>
{/* <Footer
shopId={shopIdentifier}