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