From 43a2ec337c02fc8f9b3d7af1c9477cd0d994395b Mon Sep 17 00:00:00 2001 From: nospeedlimitindonesia Date: Wed, 31 Jul 2024 06:16:50 +0000 Subject: [PATCH] working on login --- src/App.js | 6 ++++-- src/helpers/transactionHelpers.js | 5 +++-- src/pages/Cart.js | 33 +++++++++++++++++++++++-------- src/pages/Cart.module.css | 14 ++++++++++--- src/pages/LoginPage.js | 5 +++-- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/App.js b/src/App.js index d366576..7f85c9f 100644 --- a/src/App.js +++ b/src/App.js @@ -121,9 +121,11 @@ function App() { setDeviceType("guestDevice"); } else { setUser(data.data.user); - if (data.data.user.cafeId === shopId) { + console.log(data.data.user); + if (data.data.user.cafeId == shopId) { const connectedGuestSides = await getConnectedGuestSides(); setGuestSides(connectedGuestSides.sessionDatas); + console.log("getting guest side"); setDeviceType("clerk"); } else { setDeviceType("guestDevice"); @@ -258,7 +260,7 @@ function App() { } /> diff --git a/src/helpers/transactionHelpers.js b/src/helpers/transactionHelpers.js index 929c6e7..492e47f 100644 --- a/src/helpers/transactionHelpers.js +++ b/src/helpers/transactionHelpers.js @@ -92,7 +92,8 @@ export const handlePaymentFromGuestSide = async ( }), }, ); - + const res = await response.json(); + console.log(res); if (response.ok) { // Handle success response console.log("Transaction successful!"); @@ -100,7 +101,7 @@ export const handlePaymentFromGuestSide = async ( return true; } else { // Handle error response - console.error("Transaction failed:", response.statusText); + console.error("Transaction failed:", response.message); return false; } } catch (error) { diff --git a/src/pages/Cart.js b/src/pages/Cart.js index 09de286..bff7bf8 100644 --- a/src/pages/Cart.js +++ b/src/pages/Cart.js @@ -16,7 +16,7 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) { const { goToShop, goToInvoice } = useNavigationHelpers(shopId, tableId); const [cartItems, setCartItems] = useState([]); const [totalPrice, setTotalPrice] = useState(0); - const [orderType, setOrderType] = useState("pickup"); + const [orderType, setOrderType] = useState("serve"); const [tableNumber, setTableNumber] = useState(""); const [loading, setLoading] = useState(true); const [isModalOpen, setIsModalOpen] = useState(false); @@ -63,6 +63,22 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) { } }, [shopId]); + useEffect(() => { + const textarea = textareaRef.current; + + if (textarea) { + const handleResize = () => { + textarea.style.height = "auto"; + textarea.style.height = `${textarea.scrollHeight}px`; + }; + + handleResize(); // Initial resize + + textarea.addEventListener("input", handleResize); + return () => textarea.removeEventListener("input", handleResize); + } + }, [textareaRef.current]); + const refreshTotal = async () => { try { const items = await getItemsByCafeId(shopId); @@ -119,22 +135,22 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) { } if (orderType === "serve") { - if (tableNumber !== "") { - const table = await getTable(shopId, tableNumber); + if (tableNumber !== "" || tableId != null) { + const table = await getTable(shopId, tableNumber || tableId); if (!table) { setModalContent(
Table not found. Please enter a valid table number.
, ); setIsModalOpen(true); } else { - goToInvoice(orderType, tableNumber, email); + goToInvoice(orderType, tableNumber || tableId, email); } } else { setModalContent(
Please enter a table number.
); setIsModalOpen(true); } } else { - goToInvoice(orderType, tableNumber, email); + goToInvoice(orderType, tableNumber || tableId, email); } setIsCheckoutLoading(false); // Stop loading animation @@ -172,6 +188,7 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) { + {tableId != null && ( + + )} {tableId == null && } {/* tableId harus di check terlebih dahulu untuk mendapatkan tableNo */} - {tableId != null && ( - - )} {orderType === "serve" && tableId == null && ( { localStorage.setItem("auth", response.token); if (response.cafeId !== null) { - navigate(`/${response.cafeId}`); + window.location.href = response.cafeId; } else { let destination = "/"; @@ -41,7 +41,8 @@ const LoginPage = () => { } } - navigate(destination, { replace: true }); + // navigate(destination, { replace: true }); + window.location.href = window.location.hostname + destination; } } else { console.error("Login failed");