From 1abb63e8bda4e4ef154148a52497bb4428d5b130 Mon Sep 17 00:00:00 2001 From: Mohammed Al-yaseen Date: Tue, 28 Oct 2025 13:29:52 +0300 Subject: [PATCH] refactor the use of plain string order types --- .../PaymentMethods/PaymentMethods.tsx | 3 ++- src/features/order/orderSlice.ts | 8 ++++---- src/pages/address/page.tsx | 3 ++- .../cart/components/CartDesktopLayout.tsx | 10 +++++----- .../components/CartMobileTabletLayout.tsx | 12 ++++++------ .../checkout/components/AddressSummary.tsx | 8 ++++++-- src/pages/checkout/components/BriefMenu.tsx | 14 ++++++-------- .../checkout/components/CheckoutButton.tsx | 5 +++-- src/pages/checkout/components/GiftDetails.tsx | 7 ++++--- .../checkout/components/OfficeDetails.tsx | 9 +++++---- src/pages/checkout/components/RoomDetails.tsx | 9 +++++---- src/pages/checkout/components/phoneCard.tsx | 3 ++- src/pages/checkout/hooks/types.ts | 1 + src/pages/checkout/hooks/useOrder.ts | 5 +++-- .../menu/components/ResponsiveServices.tsx | 19 +++++++++++-------- src/pages/restaurant/RestaurantServices.tsx | 15 ++++++++------- 16 files changed, 73 insertions(+), 58 deletions(-) diff --git a/src/components/PaymentMethods/PaymentMethods.tsx b/src/components/PaymentMethods/PaymentMethods.tsx index 18d41c3..e5a82ad 100644 --- a/src/components/PaymentMethods/PaymentMethods.tsx +++ b/src/components/PaymentMethods/PaymentMethods.tsx @@ -13,6 +13,7 @@ import { useAppDispatch, useAppSelector } from "redux/hooks"; import { colors, ProGray1 } from "../../ThemeConstants"; import ProInputCard from "../ProInputCard/ProInputCard"; import styles from "./PaymentMethods.module.css"; +import { OrderType } from "pages/checkout/hooks/types.ts"; const PaymentMethods = () => { const { t } = useTranslation(); @@ -28,7 +29,7 @@ const PaymentMethods = () => { style?: React.CSSProperties; hideCurrency?: boolean; }[] = [ - ...(orderType !== "gift" + ...(orderType !== OrderType.Gift ? [ { label: t("checkout.cash"), diff --git a/src/features/order/orderSlice.ts b/src/features/order/orderSlice.ts index a0fa9cd..264c75e 100644 --- a/src/features/order/orderSlice.ts +++ b/src/features/order/orderSlice.ts @@ -53,7 +53,7 @@ interface CartState { collectionMethod: string; phone: string; paymentMethod: string; - orderType: string; + orderType: OrderType | ""; useLoyaltyPoints: boolean; loyaltyValidationError: string | null; } @@ -127,7 +127,7 @@ const initialState: CartState = { ), phone: getFromLocalStorage(CART_STORAGE_KEYS.PHONE, ""), paymentMethod: getFromLocalStorage(CART_STORAGE_KEYS.PAYMENT_METHOD, ""), - orderType: getFromLocalStorage(CART_STORAGE_KEYS.ORDER_TYPE, ""), + orderType: getFromLocalStorage(CART_STORAGE_KEYS.ORDER_TYPE, "" as OrderType | ""), useLoyaltyPoints: getFromLocalStorage( CART_STORAGE_KEYS.USE_LOYALTY_POINTS, false, @@ -435,7 +435,7 @@ const orderSlice = createSlice({ ); } }, - updateOrderType(state, action: PayloadAction) { + updateOrderType(state, action: PayloadAction) { state.orderType = action.payload; // Sync to localStorage @@ -604,7 +604,7 @@ export const selectGrandTotal = (state: RootState) => { const taxAmount = selectTaxAmount(state); const subtotal = selectCartTotal(state); const deliveryFee = - state.order.orderType != OrderType.DineIn + state.order.orderType !== OrderType.DineIn ? Number(state.order.restaurant?.delivery_fees) || 0 : 0; diff --git a/src/pages/address/page.tsx b/src/pages/address/page.tsx index 5742092..d826316 100644 --- a/src/pages/address/page.tsx +++ b/src/pages/address/page.tsx @@ -11,6 +11,7 @@ import { useAppSelector } from "redux/hooks"; import { colors, ProBlack2, ProGray1 } from "ThemeConstants"; import { AddressSummary } from "../checkout/components/AddressSummary"; import styles from "./address.module.css"; +import { OrderType } from "pages/checkout/hooks/types.ts"; export default function AddressPage() { const { t } = useTranslation(); @@ -165,7 +166,7 @@ export default function AddressPage() { to={`/${id}/menu?orderType=delivery`} style={{ width: "100%" }} onClick={() => { - localStorage.setItem("orderType", "delivery"); + localStorage.setItem("orderType", OrderType.Delivery); }} > - + {!shouldHidePickup && (