This commit is contained in:
nospeedlimitindonesia
2024-07-30 06:40:37 +00:00
parent 1bef19f624
commit ab3732fe9d
7 changed files with 61 additions and 26 deletions

View File

@@ -163,6 +163,10 @@ function App() {
handleModalFromURL(); handleModalFromURL();
}, [shopId]); }, [shopId]);
useEffect(() => {
console.log(shopId + tableId);
}, [navigate]);
// Function to open the modal // Function to open the modal
const setModal = (content) => { const setModal = (content) => {
setIsModalOpen(true); setIsModalOpen(true);

View File

@@ -212,6 +212,7 @@ const Child = styled.div`
const Header = ({ const Header = ({
HeaderText, HeaderText,
shopId, shopId,
tableId,
showProfile, showProfile,
user, user,
isEdit, isEdit,
@@ -221,7 +222,7 @@ const Header = ({
removeConnectedGuestSides, removeConnectedGuestSides,
}) => { }) => {
const { goToLogin, goToGuestSideLogin, goToAdminCafes } = const { goToLogin, goToGuestSideLogin, goToAdminCafes } =
useNavigationHelpers(shopId); useNavigationHelpers(shopId, tableId);
const [showRectangle, setShowRectangle] = useState(false); const [showRectangle, setShowRectangle] = useState(false);
const [animate, setAnimate] = useState(""); const [animate, setAnimate] = useState("");
const rectangleRef = useRef(null); const rectangleRef = useRef(null);

View File

@@ -33,6 +33,7 @@ function CafePage({
const token = searchParams.get("token"); const token = searchParams.get("token");
const { shopId, tableId } = useParams(); const { shopId, tableId } = useParams();
sendParam({ shopId, tableId }); sendParam({ shopId, tableId });
const navigate = useNavigate(); const navigate = useNavigate();
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
@@ -97,6 +98,7 @@ function CafePage({
isEdit={() => setModal("edit")} isEdit={() => setModal("edit")}
isLogout={handleLogout} isLogout={handleLogout}
shopId={shopId} shopId={shopId}
tableId={tableId}
user={user} user={user}
guestSides={guestSides} guestSides={guestSides}
guestSideOfClerk={guestSideOfClerk} guestSideOfClerk={guestSideOfClerk}

View File

@@ -10,10 +10,10 @@ import { getItemsByCafeId } from "../helpers/cartHelpers"; // Import getItemsByC
import Modal from "../components/Modal"; // Import the reusable Modal component import Modal from "../components/Modal"; // Import the reusable Modal component
export default function Cart({ sendParam, totalItemsCount, deviceType }) { export default function Cart({ sendParam, totalItemsCount, deviceType }) {
const { shopId } = useParams(); const { shopId, tableId } = useParams();
sendParam(shopId); sendParam({ shopId, tableId });
const { goToShop, goToInvoice } = useNavigationHelpers(shopId); 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("pickup");
@@ -186,9 +186,14 @@ export default function Cart({ sendParam, totalItemsCount, deviceType }) {
onChange={handleOrderTypeChange} onChange={handleOrderTypeChange}
> >
<option value="pickup">Pickup</option> <option value="pickup">Pickup</option>
<option value="serve">Serve</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> </select>
{orderType === "serve" && ( {orderType === "serve" && tableId == null && (
<input <input
type="text" type="text"
placeholder="Table Number" placeholder="Table Number"

View File

@@ -12,7 +12,9 @@ import {
} from "../helpers/transactionHelpers"; } from "../helpers/transactionHelpers";
export default function Invoice({ sendParam, deviceType }) { export default function Invoice({ sendParam, deviceType }) {
const { shopId } = useParams(); const { shopId, tableId } = useParams();
sendParam({ shopId, tableId });
const location = useLocation(); // Use useLocation hook instead of useSearchParams const location = useLocation(); // Use useLocation hook instead of useSearchParams
const searchParams = new URLSearchParams(location.search); // Pass location.search directly const searchParams = new URLSearchParams(location.search); // Pass location.search directly
@@ -20,10 +22,6 @@ export default function Invoice({ sendParam, deviceType }) {
const orderType = searchParams.get("orderType"); const orderType = searchParams.get("orderType");
const tableNumber = searchParams.get("tableNumber"); const tableNumber = searchParams.get("tableNumber");
useEffect(() => {
sendParam(shopId);
}, [sendParam, shopId]);
const [cartItems, setCartItems] = useState([]); const [cartItems, setCartItems] = useState([]);
const [totalPrice, setTotalPrice] = useState(0); const [totalPrice, setTotalPrice] = useState(0);
const [isPaymentLoading, setIsPaymentLoading] = useState(false); // State for payment button loading animation const [isPaymentLoading, setIsPaymentLoading] = useState(false); // State for payment button loading animation

View File

@@ -1,16 +1,17 @@
import React from 'react'; import React from "react";
import { useNavigate, useLocation } from 'react-router-dom'; import { useNavigate, useLocation } from "react-router-dom";
import './LoginPage.css'; import "./LoginPage.css";
import RouletteWheel from '../components/RouletteWheel'; import RouletteWheel from "../components/RouletteWheel";
import { loginUser } from '../helpers/userHelpers'; // Import from userHelper.js import { loginUser } from "../helpers/userHelpers"; // Import from userHelper.js
const LoginPage = () => { const LoginPage = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); // Use useLocation hook instead of useSearchParams const location = useLocation(); // Use useLocation hook instead of useSearchParams
const searchParams = new URLSearchParams(location.search); // Pass location.search directly const searchParams = new URLSearchParams(location.search); // Pass location.search directly
const next = searchParams.get('next'); const next = searchParams.get("next");
console.log(next); const table = searchParams.get("table");
const handleLogin = async (email, username, password) => { const handleLogin = async (email, username, password) => {
try { try {
const response = await loginUser(username, password); const response = await loginUser(username, password);
@@ -21,14 +22,32 @@ const LoginPage = () => {
if (response.cafeId !== null) { if (response.cafeId !== null) {
navigate(`/${response.cafeId}`); navigate(`/${response.cafeId}`);
} else { } else {
if (next) navigate(`/${next}`); let destination = "/";
else navigate('/');
// Validate parameters and construct the destination URL
if (table && !next) {
console.error(
'Parameter "table" requires "next" to be present in the URL.',
);
// Navigate to a default route or handle this case as needed
navigate("/");
return;
}
if (next) {
destination = `/${next}`;
if (table) {
destination += `?table=${table}`;
}
}
navigate(destination, { replace: true });
} }
} else { } else {
console.error('Login failed'); console.error("Login failed");
} }
} catch (error) { } catch (error) {
console.error('Error occurred while logging in:', error.message); console.error("Error occurred while logging in:", error.message);
} }
}; };

View File

@@ -9,8 +9,9 @@ import Header from "../components/Header";
function SearchResult({ user, shopItems, sendParam }) { function SearchResult({ user, shopItems, sendParam }) {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const { shopId } = useParams(); const { shopId, tableId } = useParams();
sendParam(shopId); sendParam({ shopId, tableId });
const [searchValue, setSearchValue] = useState( const [searchValue, setSearchValue] = useState(
"dwadawa vvwqd21qb13 4kfawfdwa dhawldhawr dliawbdjawndlks", "dwadawa vvwqd21qb13 4kfawfdwa dhawldhawr dliawbdjawndlks",
); );
@@ -39,7 +40,12 @@ function SearchResult({ user, shopItems, sendParam }) {
return ( return (
<div className="App"> <div className="App">
<header className="App-header"> <header className="App-header">
<Header HeaderText={"Search"} shopId={shopId} user={user} /> <Header
HeaderText={"Search"}
shopId={shopId}
tableId={tableId}
user={user}
/>
<div style={{ marginTop: "5px" }}></div> <div style={{ marginTop: "5px" }}></div>
<SearchInput <SearchInput
shopId={shopId} shopId={shopId}