cart refactor code
This commit is contained in:
@@ -9,25 +9,21 @@ import ImageWithFallback from "components/ImageWithFallback";
|
|||||||
import ArabicPrice from "components/ArabicPrice";
|
import ArabicPrice from "components/ArabicPrice";
|
||||||
import CartActionsButtons from "components/CartActionsButtons/CartActionsButtons.tsx";
|
import CartActionsButtons from "components/CartActionsButtons/CartActionsButtons.tsx";
|
||||||
import { CartItem } from "utils/types/appTypes.ts";
|
import { CartItem } from "utils/types/appTypes.ts";
|
||||||
import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
|
|
||||||
|
|
||||||
import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect.tsx";
|
import { selectCart, selectCartTotal } from "features/order/orderSlice.ts";
|
||||||
import {
|
|
||||||
updateTables,
|
|
||||||
removeTable,
|
|
||||||
selectCart,
|
|
||||||
selectCartTotal,
|
|
||||||
} from "features/order/orderSlice.ts";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useAppSelector } from "redux/hooks.ts";
|
import { useAppSelector } from "redux/hooks.ts";
|
||||||
import { getTableOptions } from "pages/cart/page.tsx";
|
|
||||||
import SpecialRequestCard from "pages/cart/components/SpecialRequestCard.tsx";
|
import SpecialRequestCard from "pages/cart/components/SpecialRequestCard.tsx";
|
||||||
import CouponCard from "pages/cart/components/CouponCard.tsx";
|
import CouponCard from "pages/cart/components/CouponCard.tsx";
|
||||||
import RewardWaiterCard from "pages/cart/components/RewardWaiterCard.tsx";
|
import RewardWaiterCard from "pages/cart/components/RewardWaiterCard.tsx";
|
||||||
|
import TableNumberCard from "pages/cart/components/TableNumberCard.tsx";
|
||||||
|
import CarPlateCard from "pages/cart/components/CarPlateCard.tsx";
|
||||||
|
|
||||||
export default function CartDesktopLayout() {
|
export default function CartDesktopLayout() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { items, tables } = useAppSelector(selectCart);
|
const { items } = useAppSelector(selectCart);
|
||||||
|
const orderType = localStorage.getItem("orderType");
|
||||||
|
|
||||||
const subtotal = useAppSelector(selectCartTotal);
|
const subtotal = useAppSelector(selectCartTotal);
|
||||||
const tax = subtotal * 0.1; // 10% tax
|
const tax = subtotal * 0.1; // 10% tax
|
||||||
const total = subtotal + tax;
|
const total = subtotal + tax;
|
||||||
@@ -184,6 +180,9 @@ export default function CartDesktopLayout() {
|
|||||||
>
|
>
|
||||||
<CouponCard />
|
<CouponCard />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{orderType === "pickup" && <CarPlateCard />}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={styles.desktopSidebarCard}
|
className={styles.desktopSidebarCard}
|
||||||
style={{ "--animation-order": 1 } as React.CSSProperties}
|
style={{ "--animation-order": 1 } as React.CSSProperties}
|
||||||
@@ -192,29 +191,14 @@ export default function CartDesktopLayout() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Table Number */}
|
{/* Table Number */}
|
||||||
|
{orderType === "dine-in" && (
|
||||||
<div
|
<div
|
||||||
className={styles.desktopSidebarCard}
|
className={styles.desktopSidebarCard}
|
||||||
style={{ "--animation-order": 3 } as React.CSSProperties}
|
style={{ "--animation-order": 3 } as React.CSSProperties}
|
||||||
>
|
>
|
||||||
<ProInputCard title={t("tableNumber")}>
|
<TableNumberCard />
|
||||||
<ProInModalMultiSelect
|
|
||||||
value={tables}
|
|
||||||
placeholder={t("tableNumberPlaceholder")}
|
|
||||||
size="large"
|
|
||||||
optionList={getTableOptions()}
|
|
||||||
style={{
|
|
||||||
width: "100%",
|
|
||||||
height: "50px",
|
|
||||||
}}
|
|
||||||
onSelect={(value) => {
|
|
||||||
updateTables(value);
|
|
||||||
}}
|
|
||||||
onClear={() => {
|
|
||||||
removeTable();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ProInputCard>
|
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Order Summary */}
|
{/* Order Summary */}
|
||||||
<Card
|
<Card
|
||||||
|
|||||||
@@ -14,16 +14,12 @@ import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
|
|||||||
import ProRatioGroups from "components/ProRatioGroups/ProRatioGroups.tsx";
|
import ProRatioGroups from "components/ProRatioGroups/ProRatioGroups.tsx";
|
||||||
import {
|
import {
|
||||||
updateCollectionMethod,
|
updateCollectionMethod,
|
||||||
updateTables,
|
|
||||||
removeTable,
|
|
||||||
updateEstimateTime,
|
updateEstimateTime,
|
||||||
selectCart,
|
selectCart,
|
||||||
} from "features/order/orderSlice.ts";
|
} from "features/order/orderSlice.ts";
|
||||||
|
|
||||||
import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect.tsx";
|
|
||||||
import OrderSummary from "components/OrderSummary/OrderSummary.tsx";
|
import OrderSummary from "components/OrderSummary/OrderSummary.tsx";
|
||||||
import { EstimateTimeBottomSheet } from "components/CustomBottomSheet/EstimateTimeBottomSheet.tsx";
|
import { EstimateTimeBottomSheet } from "components/CustomBottomSheet/EstimateTimeBottomSheet.tsx";
|
||||||
import { getTableOptions } from "pages/cart/page.tsx";
|
|
||||||
import { useAppSelector, useAppDispatch } from "redux/hooks.ts";
|
import { useAppSelector, useAppDispatch } from "redux/hooks.ts";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@@ -32,11 +28,12 @@ import useBreakPoint from "hooks/useBreakPoint.ts";
|
|||||||
import CouponCard from "pages/cart/components/CouponCard.tsx";
|
import CouponCard from "pages/cart/components/CouponCard.tsx";
|
||||||
import RewardWaiterCard from "pages/cart/components/RewardWaiterCard.tsx";
|
import RewardWaiterCard from "pages/cart/components/RewardWaiterCard.tsx";
|
||||||
import CarPlateCard from "pages/cart/components/CarPlateCard.tsx";
|
import CarPlateCard from "pages/cart/components/CarPlateCard.tsx";
|
||||||
|
import TableNumberCard from "pages/cart/components/TableNumberCard.tsx";
|
||||||
|
|
||||||
export default function CartMobileTabletLayout() {
|
export default function CartMobileTabletLayout() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { items, tables, estimateTimeDate, collectionMethod } =
|
const { items, estimateTimeDate, collectionMethod } =
|
||||||
useAppSelector(selectCart);
|
useAppSelector(selectCart);
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
@@ -290,30 +287,7 @@ export default function CartMobileTabletLayout() {
|
|||||||
<RewardWaiterCard />
|
<RewardWaiterCard />
|
||||||
|
|
||||||
{/* Table Number */}
|
{/* Table Number */}
|
||||||
{orderType === "dine-in" && (
|
{orderType === "dine-in" && <TableNumberCard />}
|
||||||
<ProInputCard
|
|
||||||
title={t("cart.tableNumber")}
|
|
||||||
className={styles.tableNumberCard}
|
|
||||||
>
|
|
||||||
<ProInModalMultiSelect
|
|
||||||
value={tables}
|
|
||||||
placeholder={t("tableNumber")}
|
|
||||||
size="large"
|
|
||||||
optionList={getTableOptions()}
|
|
||||||
style={{
|
|
||||||
width: "100%",
|
|
||||||
height: 50,
|
|
||||||
fontSize: 12,
|
|
||||||
}}
|
|
||||||
onSelect={(value) => {
|
|
||||||
updateTables(value);
|
|
||||||
}}
|
|
||||||
onClear={() => {
|
|
||||||
removeTable();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ProInputCard>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Invoice Summary */}
|
{/* Invoice Summary */}
|
||||||
<OrderSummary />
|
<OrderSummary />
|
||||||
|
|||||||
56
src/pages/cart/components/TableNumberCard.tsx
Normal file
56
src/pages/cart/components/TableNumberCard.tsx
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import styles from "pages/cart/cart.module.css";
|
||||||
|
import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect.tsx";
|
||||||
|
import {
|
||||||
|
updateTables,
|
||||||
|
removeTable,
|
||||||
|
selectCart,
|
||||||
|
} from "features/order/orderSlice.ts";
|
||||||
|
import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
|
||||||
|
import { useAppSelector } from "redux/hooks.ts";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import i18n from "i18n/i18n.ts";
|
||||||
|
|
||||||
|
// Function to get translated table names
|
||||||
|
export const getTableOptions = () => [
|
||||||
|
{ id: "1", name: i18n.t("table1") },
|
||||||
|
{ id: "2", name: i18n.t("table2") },
|
||||||
|
{ id: "3", name: i18n.t("table3") },
|
||||||
|
{ id: "4", name: i18n.t("table4") },
|
||||||
|
{ id: "5", name: i18n.t("table5") },
|
||||||
|
{ id: "6", name: i18n.t("table6") },
|
||||||
|
{ id: "7", name: i18n.t("table7") },
|
||||||
|
{ id: "8", name: i18n.t("table8") },
|
||||||
|
{ id: "9", name: i18n.t("table9") },
|
||||||
|
{ id: "10", name: i18n.t("table10") },
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function TableNumberCard() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { tables } = useAppSelector(selectCart);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ProInputCard
|
||||||
|
title={t("cart.tableNumber")}
|
||||||
|
className={styles.tableNumberCard}
|
||||||
|
>
|
||||||
|
<ProInModalMultiSelect
|
||||||
|
value={tables}
|
||||||
|
placeholder={t("tableNumber")}
|
||||||
|
size="large"
|
||||||
|
optionList={getTableOptions()}
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
height: 50,
|
||||||
|
fontSize: 12,
|
||||||
|
}}
|
||||||
|
onSelect={(value) => {
|
||||||
|
updateTables(value);
|
||||||
|
}}
|
||||||
|
onClear={() => {
|
||||||
|
removeTable();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ProInputCard>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,24 +1,9 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
import CartDesktopLayout from "pages/cart/components/CartDesktopLayout.tsx";
|
import CartDesktopLayout from "pages/cart/components/CartDesktopLayout.tsx";
|
||||||
import i18n from "i18n/i18n.ts";
|
|
||||||
import CartMobileTabletLayout from "pages/cart/components/CartMobileTabletLayout.tsx";
|
import CartMobileTabletLayout from "pages/cart/components/CartMobileTabletLayout.tsx";
|
||||||
import useBreakPoint from "hooks/useBreakPoint.ts";
|
import useBreakPoint from "hooks/useBreakPoint.ts";
|
||||||
|
|
||||||
// Function to get translated table names
|
|
||||||
export const getTableOptions = () => [
|
|
||||||
{ id: "1", name: i18n.t("table1") },
|
|
||||||
{ id: "2", name: i18n.t("table2") },
|
|
||||||
{ id: "3", name: i18n.t("table3") },
|
|
||||||
{ id: "4", name: i18n.t("table4") },
|
|
||||||
{ id: "5", name: i18n.t("table5") },
|
|
||||||
{ id: "6", name: i18n.t("table6") },
|
|
||||||
{ id: "7", name: i18n.t("table7") },
|
|
||||||
{ id: "8", name: i18n.t("table8") },
|
|
||||||
{ id: "9", name: i18n.t("table9") },
|
|
||||||
{ id: "10", name: i18n.t("table10") },
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function CartPage() {
|
export default function CartPage() {
|
||||||
const { isDesktop } = useBreakPoint();
|
const { isDesktop } = useBreakPoint();
|
||||||
// Prevent keyboard from appearing automatically on mobile
|
// Prevent keyboard from appearing automatically on mobile
|
||||||
|
|||||||
Reference in New Issue
Block a user