working on login

This commit is contained in:
nospeedlimitindonesia
2024-07-31 06:16:50 +00:00
parent ab3732fe9d
commit 43a2ec337c
5 changed files with 46 additions and 17 deletions

View File

@@ -121,9 +121,11 @@ function App() {
setDeviceType("guestDevice"); setDeviceType("guestDevice");
} else { } else {
setUser(data.data.user); 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(); const connectedGuestSides = await getConnectedGuestSides();
setGuestSides(connectedGuestSides.sessionDatas); setGuestSides(connectedGuestSides.sessionDatas);
console.log("getting guest side");
setDeviceType("clerk"); setDeviceType("clerk");
} else { } else {
setDeviceType("guestDevice"); setDeviceType("guestDevice");
@@ -258,7 +260,7 @@ function App() {
} }
/> />
<Route <Route
path="/:shopId/:tableId?invoice" path="/:shopId/:tableId?/invoice"
element={ element={
<> <>
<Invoice sendParam={handleSetParam} deviceType={deviceType} /> <Invoice sendParam={handleSetParam} deviceType={deviceType} />

View File

@@ -92,7 +92,8 @@ export const handlePaymentFromGuestSide = async (
}), }),
}, },
); );
const res = await response.json();
console.log(res);
if (response.ok) { if (response.ok) {
// Handle success response // Handle success response
console.log("Transaction successful!"); console.log("Transaction successful!");
@@ -100,7 +101,7 @@ export const handlePaymentFromGuestSide = async (
return true; return true;
} else { } else {
// Handle error response // Handle error response
console.error("Transaction failed:", response.statusText); console.error("Transaction failed:", response.message);
return false; return false;
} }
} catch (error) { } catch (error) {

View File

@@ -16,7 +16,7 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) {
const { goToShop, goToInvoice } = useNavigationHelpers(shopId, tableId); const { goToShop, goToInvoice } = useNavigationHelpers(shopId, tableId);
const [cartItems, setCartItems] = useState([]); const [cartItems, setCartItems] = useState([]);
const [totalPrice, setTotalPrice] = useState(0); const [totalPrice, setTotalPrice] = useState(0);
const [orderType, setOrderType] = useState("pickup"); const [orderType, setOrderType] = useState("serve");
const [tableNumber, setTableNumber] = useState(""); const [tableNumber, setTableNumber] = useState("");
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
@@ -63,6 +63,22 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) {
} }
}, [shopId]); }, [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 () => { const refreshTotal = async () => {
try { try {
const items = await getItemsByCafeId(shopId); const items = await getItemsByCafeId(shopId);
@@ -119,22 +135,22 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) {
} }
if (orderType === "serve") { if (orderType === "serve") {
if (tableNumber !== "") { if (tableNumber !== "" || tableId != null) {
const table = await getTable(shopId, tableNumber); const table = await getTable(shopId, tableNumber || tableId);
if (!table) { if (!table) {
setModalContent( setModalContent(
<div>Table not found. Please enter a valid table number.</div>, <div>Table not found. Please enter a valid table number.</div>,
); );
setIsModalOpen(true); setIsModalOpen(true);
} else { } else {
goToInvoice(orderType, tableNumber, email); goToInvoice(orderType, tableNumber || tableId, email);
} }
} else { } else {
setModalContent(<div>Please enter a table number.</div>); setModalContent(<div>Please enter a table number.</div>);
setIsModalOpen(true); setIsModalOpen(true);
} }
} else { } else {
goToInvoice(orderType, tableNumber, email); goToInvoice(orderType, tableNumber || tableId, email);
} }
setIsCheckoutLoading(false); // Stop loading animation setIsCheckoutLoading(false); // Stop loading animation
@@ -172,6 +188,7 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) {
<input <input
type="email" type="email"
id="email" id="email"
placeholder="log this transaction (optional)"
value={email} value={email}
onChange={handleEmailChange} onChange={handleEmailChange}
className={styles.EmailInput} className={styles.EmailInput}
@@ -185,13 +202,13 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) {
value={orderType} value={orderType}
onChange={handleOrderTypeChange} onChange={handleOrderTypeChange}
> >
{tableId != null && (
<option value="serve">Serve to table {tableId}</option>
)}
<option value="pickup">Pickup</option> <option value="pickup">Pickup</option>
{tableId == null && <option value="serve">Serve</option>} {tableId == null && <option value="serve">Serve</option>}
{/* tableId harus di check terlebih dahulu untuk mendapatkan tableNo */} {/* tableId harus di check terlebih dahulu untuk mendapatkan tableNo */}
{tableId != null && (
<option value="serve">Serve to table {tableId}</option>
)}
</select> </select>
{orderType === "serve" && tableId == null && ( {orderType === "serve" && tableId == null && (
<input <input

View File

@@ -24,6 +24,15 @@
position: fixed; position: fixed;
} }
.EmailContainer {
display: flex;
justify-content: space-between;
width: 80vw;
margin: 0 auto;
font-size: 1em;
padding: 10px 0;
margin-bottom: 7px;
}
.OrderTypeContainer { .OrderTypeContainer {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@@ -96,7 +105,6 @@
justify-content: center; justify-content: center;
} }
.BackToMenu { .BackToMenu {
text-align: center; text-align: center;
color: rgba(88, 55, 50, 1); color: rgba(88, 55, 50, 1);

View File

@@ -20,7 +20,7 @@ const LoginPage = () => {
localStorage.setItem("auth", response.token); localStorage.setItem("auth", response.token);
if (response.cafeId !== null) { if (response.cafeId !== null) {
navigate(`/${response.cafeId}`); window.location.href = response.cafeId;
} else { } else {
let destination = "/"; let destination = "/";
@@ -41,7 +41,8 @@ const LoginPage = () => {
} }
} }
navigate(destination, { replace: true }); // navigate(destination, { replace: true });
window.location.href = window.location.hostname + destination;
} }
} else { } else {
console.error("Login failed"); console.error("Login failed");