ok
This commit is contained in:
27
src/App.js
27
src/App.js
@@ -71,6 +71,8 @@ function App() {
|
||||
const [depth, setDepth] = useState(-1);
|
||||
const [queue, setQueue] = useState([]);
|
||||
|
||||
const [newTransaction, setNewTransaction] = useState({});
|
||||
|
||||
|
||||
const validTransactionStates = [
|
||||
'new_transaction',
|
||||
@@ -395,30 +397,32 @@ function App() {
|
||||
};
|
||||
}, [socket, shopId]);
|
||||
|
||||
async function checkIfStillViewingOtherTransaction() {
|
||||
async function checkIfStillViewingOtherTransaction(data) {
|
||||
|
||||
console.log("transaction notification");
|
||||
console.log(modalContent);
|
||||
|
||||
let response;
|
||||
response = await getTransactionsFromCafe(shopId, 0, true);
|
||||
transactionList.current = response;
|
||||
console.log(response);
|
||||
|
||||
// Get current URL's search parameters inside the socket event handler
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
let transaction_info = searchParams.get("transactionId") || ''; // Get transactionId or set it to empty string
|
||||
console.log(transaction_info); // Log the updated transaction_info
|
||||
|
||||
if(response[0].transactionId != transaction_info) transactionList.current = response;
|
||||
|
||||
let depthh = transactionList.current.findIndex(
|
||||
item => item.transactionId.toString() === transaction_info.toString()
|
||||
);
|
||||
if(depthh == 0 && transaction_info.toString() != '') depthh = 1;
|
||||
|
||||
if (transaction_info != response[0].transactionId)
|
||||
setDepth(depthh);
|
||||
else setModal("new_transaction", data);
|
||||
|
||||
console.log(transaction_info == response[0].transactionId)
|
||||
// If transaction_info is an empty string, set the modal
|
||||
if (transaction_info.toString() == '' || transaction_info.toString() == response[0].transactionId) return false;
|
||||
if (transaction_info.toString() == '') return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
@@ -426,12 +430,15 @@ function App() {
|
||||
// This will ensure that searchParams and transaction_info get updated on each render
|
||||
socket.on("transaction_created", async (data) => {
|
||||
console.log("transaction notification");
|
||||
const isViewingOtherTransaction = await checkIfStillViewingOtherTransaction();
|
||||
setNewTransaction(data);
|
||||
|
||||
if(!location.pathname.endsWith('/transactions')){
|
||||
const isViewingOtherTransaction = await checkIfStillViewingOtherTransaction(data);
|
||||
// If transaction_info is an empty string, set the modal
|
||||
if (!isViewingOtherTransaction) {
|
||||
setModal("new_transaction", data);
|
||||
}
|
||||
|
||||
}
|
||||
// Show browser notification
|
||||
let permission = Notification.permission;
|
||||
if (permission !== "granted") return;
|
||||
@@ -446,12 +453,15 @@ function App() {
|
||||
socket.on("transaction_canceled", async (data) => {
|
||||
console.log("transaction notification");
|
||||
|
||||
const isViewingOtherTransaction = await checkIfStillViewingOtherTransaction();
|
||||
setNewTransaction(data);
|
||||
if(location.pathname != '/transactions'){
|
||||
const isViewingOtherTransaction = await checkIfStillViewingOtherTransaction(data);
|
||||
// If transaction_info is an empty string, set the modal
|
||||
if (!isViewingOtherTransaction) {
|
||||
setModal("new_transaction", data);
|
||||
navigate(`?transactionId=${data.transactionId}`, { replace: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Clean up the socket event listener on unmount or when dependencies change
|
||||
@@ -789,6 +799,7 @@ function App() {
|
||||
deviceType={deviceType}
|
||||
paymentUrl={shop.qrPayment}
|
||||
setModal={setModal}
|
||||
newTransaction={newTransaction}
|
||||
/>
|
||||
{/* <Footer
|
||||
shopId={shopIdentifier}
|
||||
|
||||
@@ -6,9 +6,9 @@ import reportWebVitals from './reportWebVitals';
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
// Disable console methods
|
||||
// console.log = () => {};
|
||||
// console.warn = () => {};
|
||||
// console.error = () => {};
|
||||
console.log = () => {};
|
||||
console.warn = () => {};
|
||||
console.error = () => {};
|
||||
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
|
||||
@@ -297,7 +297,6 @@ const LinktreePage = ({ user, setModal }) => {
|
||||
Solusi berbasis web untuk memudahkan pengelolaan kedai, dengan fitur yang mempermudah pemilik, kasir, dan tamu berinteraksi.
|
||||
</div>
|
||||
|
||||
{getLocalStorage('auth') == null && (
|
||||
<div className={styles.LoginForm}>
|
||||
<div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
|
||||
<label htmlFor="username" className={styles.usernameLabel}>---- Masuk -----------------------------</label>
|
||||
@@ -340,7 +339,6 @@ const LinktreePage = ({ user, setModal }) => {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={styles.footer}>
|
||||
<div className={styles.footerLinks}>
|
||||
|
||||
@@ -253,7 +253,7 @@ export default function Transactions({ propsShopId, sendParam, deviceType, handl
|
||||
: `Diantar ke ${transaction.Table ? transaction.Table.tableNo : "N/A"
|
||||
}`}
|
||||
</h2>
|
||||
{transaction.notes != null && (
|
||||
{transaction.notes != '' && (
|
||||
<>
|
||||
<div className={styles.NoteContainer}>
|
||||
<span>Note :</span>
|
||||
|
||||
@@ -18,7 +18,7 @@ import ButtonWithReplica from "../components/ButtonWithReplica";
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export default function Transactions({ shop, shopId, propsShopId, sendParam, deviceType, paymentUrl, setModal }) {
|
||||
export default function Transactions({ shop, shopId, propsShopId, sendParam, deviceType, paymentUrl, setModal, newTransaction }) {
|
||||
const { shopIdentifier, tableId } = useParams();
|
||||
if (sendParam) sendParam({ shopIdentifier, tableId });
|
||||
|
||||
@@ -34,38 +34,38 @@ export default function Transactions({ shop, shopId, propsShopId, sendParam, dev
|
||||
setMatchedItems(searchAndAggregateItems(transactions, searchTerm));
|
||||
}, [searchTerm, transactions]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTransactions = async () => {
|
||||
try {
|
||||
|
||||
// response = await getMyTransactions(shopId || propsShopId, 5);
|
||||
// setMyTransactions(response);
|
||||
setLoading(true);
|
||||
let response = await getTransactionsFromCafe(shopId || propsShopId, 5, false);
|
||||
|
||||
setLoading(false);
|
||||
if (response) setTransactions(response);
|
||||
|
||||
|
||||
// response = await getMyTransactions(shopId || propsShopId, 5);
|
||||
// setMyTransactions(response);
|
||||
} catch (error) {
|
||||
console.error("Error fetching transactions:", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchTransactions();
|
||||
}, [deviceType]);
|
||||
}, [deviceType, newTransaction]);
|
||||
|
||||
const calculateTotalPrice = (detailedTransactions) => {
|
||||
return detailedTransactions.reduce((total, dt) => {
|
||||
return total + dt.qty * (dt.promoPrice ? dt.promoPrice : dt.price);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
const calculateAllTransactionsTotal = (transactions) => {
|
||||
return transactions.reduce((grandTotal, transaction) => {
|
||||
return transactions
|
||||
.filter(transaction => transaction.confirmed > 1) // Filter transactions where confirmed > 1
|
||||
.reduce((grandTotal, transaction) => {
|
||||
return grandTotal + calculateTotalPrice(transaction.DetailedTransactions);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
const searchAndAggregateItems = (transactions, searchTerm) => {
|
||||
if (!searchTerm.trim()) return [];
|
||||
|
||||
@@ -148,7 +148,7 @@ export default function Transactions({ shop, shopId, propsShopId, sendParam, dev
|
||||
return (
|
||||
<div className={styles.Transactions}>
|
||||
<h2 className={styles["Transactions-title"]}>
|
||||
Daftar transaksi Rp {calculateAllTransactionsTotal(transactions)}
|
||||
Transaksi selesai Rp {calculateAllTransactionsTotal(transactions)}
|
||||
</h2>
|
||||
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user