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");
} 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() {
}
/>
<Route
path="/:shopId/:tableId?invoice"
path="/:shopId/:tableId?/invoice"
element={
<>
<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) {
// 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) {

View File

@@ -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(
<div>Table not found. Please enter a valid table number.</div>,
);
setIsModalOpen(true);
} else {
goToInvoice(orderType, tableNumber, email);
goToInvoice(orderType, tableNumber || tableId, email);
}
} else {
setModalContent(<div>Please enter a table number.</div>);
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 }) {
<input
type="email"
id="email"
placeholder="log this transaction (optional)"
value={email}
onChange={handleEmailChange}
className={styles.EmailInput}
@@ -185,13 +202,13 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) {
value={orderType}
onChange={handleOrderTypeChange}
>
{tableId != null && (
<option value="serve">Serve to table {tableId}</option>
)}
<option value="pickup">Pickup</option>
{tableId == null && <option value="serve">Serve</option>}
{/* tableId harus di check terlebih dahulu untuk mendapatkan tableNo */}
{tableId != null && (
<option value="serve">Serve to table {tableId}</option>
)}
</select>
{orderType === "serve" && tableId == null && (
<input

View File

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

View File

@@ -20,7 +20,7 @@ const LoginPage = () => {
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");