ok
This commit is contained in:
44
src/App.js
44
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}
|
||||
/>
|
||||
{/* <Footer
|
||||
shopId={shopIdentifier}
|
||||
|
||||
Reference in New Issue
Block a user