import ArabicPrice from "components/ArabicPrice"; import CartActionsButtons from "components/CartActionsButtons/CartActionsButtons"; import { CouponBottomSheet } from "components/CustomBottomSheet/CouponBottomSheet"; import { CouponDialog } from "components/CustomBottomSheet/CouponDialog"; import { SpecialRequestBottomSheet } from "components/CustomBottomSheet/SpecialRequestBottomSheet"; import { SpecialRequestDialog } from "components/CustomBottomSheet/SpecialRequestDialog"; import { TipBottomSheet } from "components/CustomBottomSheet/TipBottomSheet"; import { TipDialog } from "components/CustomBottomSheet/TipDialog"; import CouponHeartIcon from "components/Icons/cart/CouponHeart"; import DonateHandIcon from "components/Icons/cart/DonateHandIcon"; import DonateIcon from "components/Icons/cart/DonateIcon"; import EmptyOrdersIcon from "components/Icons/EmptyOrdersIcon"; import ImageWithFallback from "components/ImageWithFallback"; import ProHeader from "components/ProHeader/ProHeader"; import ProInputCard from "components/ProInputCard/ProInputCard"; import ProText from "components/ProText"; import ProTitle from "components/ProTitle"; import { removeTable, selectCart, selectCartTotal, updateCollectionMethod, updateCoupon, updateEstimateTime, updateSpecialRequest, updateTables, updateTip, } from "features/order/orderSlice"; import { useAppDispatch, useAppSelector } from "redux/hooks"; import { EditOutlined, PlusOutlined, RightOutlined } from "@ant-design/icons"; import { Button, Card, Col, Divider, Grid, Input, message, Row, Space, } from "antd"; import { EstimateTimeBottomSheet } from "components/CustomBottomSheet/EstimateTimeBottomSheet"; import EditIcon from "components/Icons/EditIcon"; import OrderSummary from "components/OrderSummary/OrderSummary"; import ProRatioGroups from "components/ProRatioGroups/ProRatioGroups"; import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useParams } from "react-router-dom"; import { colors, ProBlack2 } from "ThemeConstants"; import { CartItem } from "utils/types/appTypes"; import styles from "./cart.module.css"; // Import CSS module import YouMightAlsoLike from "./components/YouMightAlsoLike"; const { useBreakpoint } = Grid; export default function CartPage() { const { t } = useTranslation(); const dispatch = useAppDispatch(); const cart = useAppSelector(selectCart); const { items, specialRequest, coupon, tip, tables, estimateTimeDate, collectionMethod, } = cart; const subtotal = useAppSelector(selectCartTotal); const tax = subtotal * 0.1; // 10% tax const total = subtotal + tax; const { id } = useParams(); const { sm, md } = useBreakpoint(); // Mock responsive values for now const isMobile = !sm; const isTablet = sm && !md; const isDesktop = md; const isLargeDesktop = md; const getResponsiveClass = () => isDesktop ? "desktop" : isTablet ? "tablet" : "mobile"; const { themeName } = useAppSelector((state) => state.theme); const orderType = localStorage.getItem("orderType"); // Function to get translated table names const getTableOptions = () => [ { id: "1", name: t("table1") }, { id: "2", name: t("table2") }, { id: "3", name: t("table3") }, { id: "4", name: t("table4") }, { id: "5", name: t("table5") }, { id: "6", name: t("table6") }, { id: "7", name: t("table7") }, { id: "8", name: t("table8") }, { id: "9", name: t("table9") }, { id: "10", name: t("table10") }, ]; const [isSpecialRequestOpen, setIsSpecialRequestOpen] = useState(false); const [isCouponOpen, setIsCouponOpen] = useState(false); const [estimateWay, setEstimateWay] = useState("now"); const [isEstimateTimeOpen, setIsEstimateTimeOpen] = useState(false); const [isTipOpen, setIsTipOpen] = useState(false); // Prevent keyboard from appearing automatically on mobile useEffect(() => { // Blur any focused element when component mounts if (document.activeElement instanceof HTMLElement) { document.activeElement.blur(); } // Prevent focus on any input elements const inputs = document.querySelectorAll("input, textarea, select"); inputs.forEach((input) => { if (input instanceof HTMLElement) { input.blur(); } }); }, []); const handleSpecialRequestSave = (value: string) => { dispatch(updateSpecialRequest(value)); message.success(t("cart.specialRequest") + " " + t("updatedSuccessfully")); }; const handleSpecialRequestClose = () => { setIsSpecialRequestOpen(false); }; const handleCouponSave = (value: string) => { dispatch(updateCoupon(value)); message.success(t("cart.coupon") + " " + t("updatedSuccessfully")); }; const handleCouponClose = () => { setIsCouponOpen(false); }; const handleTipSave = (value: string) => { dispatch(updateTip(value)); message.success(t("cart.tip") + " " + t("updatedSuccessfully")); }; const handleTipClose = () => { setIsTipOpen(false); }; const handleEstimateTimeSave = (date: Date, time: string) => { dispatch(updateEstimateTime({ date, time })); message.success(t("cart.estimateTime") + " " + t("updatedSuccessfully")); }; const handleEstimateTimeClose = () => { setIsEstimateTimeOpen(false); }; const getCartLayoutStyle = () => { if (isMobile) { return { padding: "16px", maxWidth: "100%", paddingBottom: "12vh", }; } else if (isTablet) { return { padding: "24px", maxWidth: "100%", paddingBottom: "12vh", }; } else { return { padding: "32px", maxWidth: "1400px", margin: "0 auto", paddingBottom: "12vh", }; } }; const getCartItemStyle = () => { if (isMobile) { return { padding: "16px", borderRadius: "12px", }; } else if (isTablet) { return { padding: "20px", borderRadius: "16px", }; } else { return { padding: "24px", borderRadius: "20px", }; } }; const getMenuItemImageStyle = () => { if (isMobile) { return { width: 90, height: 80, }; } else if (isTablet) { return { width: 120, height: 120, }; } else { return { width: 140, height: 140, }; } }; // Enhanced desktop layout if (isDesktop || isLargeDesktop) { return ( <>
{/* Main Content Column */}
{/*
*/} {/* Cart Items Section */}
{t("cartItems")} ({items.length}) {items.length === 0 ? t("emptyCart") : `${items.length} ${ items.length === 1 ? t("item") : t("items") } ${t("inYourCart")}`}
{items.length === 0 ? (
{t("emptyCart")} {t("emptyCartMessage")}
) : (
{items.map((item, index) => (
{item.name} {item.description}
))}
)}
{/* Sidebar Column */}
{/* Special Request */}
setIsSpecialRequestOpen(true)} > {t("edit")} } />
{/* Coupon Code */}
setIsCouponOpen(true)} > {t("viewOffers")} } > {t("apply")} } />
{/* Reward Your Waiter */}
{t("rewardYourWaiter")} {t("rewardYourWaiter100")}
{/* Table Number */}
{ updateTables(value); }} onClear={() => { removeTable(); }} />
{/* Order Summary */} {t("orderSummary")}
{t("basketTotal")}
{t("discount")}
{t("riderTip")}
{t("totalAmount")}
{/* Checkout Button */}
{/* Desktop Dialogs */} ); } // Mobile/Tablet Layout (existing code) return ( <> {t("cart.title")}
{t("cart.yourOrder")}
{t("cart.addMore")}
{items.length >= 1 && ( )} {items.map((item, index) => (
{item.name}
{item.description}
{index !== items.length - 1 && ( )}
))}
{/* Mobile/Tablet layout */} {/* Special Request */} setIsSpecialRequestOpen(true)} > {t("cart.editNote")}
} /> {/* Coupon Code */} setIsCouponOpen(true)} > {t("cart.viewOffers")} } > {t("cart.apply")} } /> {/* Car Plate*/} {orderType === "pickup" && ( )} {/* Estimate Time */} {(orderType === "delivery" || orderType === "pickup") && ( { if (value === "now") { setEstimateWay(value); handleEstimateTimeSave(new Date(), "now"); } else { setEstimateWay(value); setIsEstimateTimeOpen(true); } }} /> )} {/* Collection Method */} {orderType === "pickup" && ( { if (value === "cod") { updateCollectionMethod(value); } else { updateCollectionMethod(value); } }} /> )} {/* Reward Your Waiter */}
{t("cart.rewardYourWaiter")} {t("cart.rewardYourWaiter100")}
{/* Table Number */} {orderType === "dine-in" && ( { updateTables(value); }} onClear={() => { removeTable(); }} /> )} {/* Invoice Summary */}
{/* Mobile/Tablet Bottom Sheets */} ); }