diff --git a/src/features/order/orderSlice.ts b/src/features/order/orderSlice.ts index 4ff21a9..ff179d5 100644 --- a/src/features/order/orderSlice.ts +++ b/src/features/order/orderSlice.ts @@ -64,6 +64,7 @@ interface CartState { loyaltyValidationError: string | null; scheduledDate: string; discount: DiscountData; + plateCar: string; } // localStorage keys @@ -89,7 +90,8 @@ export const CART_STORAGE_KEYS = { RESTAURANT: "fascano_restaurant", SCHEDULED_DATE: "fascano_scheduled_date", DISCOUNT: "fascano_discount", -} as const; + PLATE: "fascano_plate_car", +} as const; // Utility functions for localStorage const getFromLocalStorage = (key: string, defaultValue: T): T => { @@ -170,6 +172,7 @@ const initialState: CartState = { isGift: false, isDiscount: false, }), + plateCar: getFromLocalStorage(CART_STORAGE_KEYS.PLATE, ""), }; const orderSlice = createSlice({ @@ -483,6 +486,16 @@ const orderSlice = createSlice({ ); } }, + updatePlateCar(state, action: PayloadAction) { + state.plateCar = action.payload; + + if (typeof window !== "undefined") { + localStorage.setItem( + CART_STORAGE_KEYS.PLATE, + JSON.stringify(state.plateCar), + ); + } + }, updateOrderType(state, action: PayloadAction) { state.orderType = action.payload; @@ -598,6 +611,7 @@ export const { updateCollectionMethod, updatePhone, updatePaymentMethod, + updatePlateCar, updateOrderType, updateUseLoyaltyPoints, validateLoyaltyPoints, diff --git a/src/pages/cart/components/CarPlateCard.tsx b/src/pages/cart/components/CarPlateCard.tsx index 51dac00..cb5024c 100644 --- a/src/pages/cart/components/CarPlateCard.tsx +++ b/src/pages/cart/components/CarPlateCard.tsx @@ -1,9 +1,14 @@ import { Form, Input } from "antd"; import ProInputCard from "components/ProInputCard/ProInputCard.tsx"; +import { updatePlateCar } from "features/order/orderSlice"; import { useTranslation } from "react-i18next"; +import { useAppDispatch, useAppSelector } from "redux/hooks"; export default function CarPlateCard() { const { t } = useTranslation(); + const dispatch = useAppDispatch() + + const {plateCar} = useAppSelector(state => state.order) return ( <> { + dispatch(updatePlateCar(e.target.value)); + }} /> diff --git a/src/pages/checkout/hooks/useOrder.ts b/src/pages/checkout/hooks/useOrder.ts index 4d85a84..80822ad 100644 --- a/src/pages/checkout/hooks/useOrder.ts +++ b/src/pages/checkout/hooks/useOrder.ts @@ -36,6 +36,7 @@ export default function useOrder() { giftDetails, location, discount, + plateCar, } = useAppSelector(selectCart); const highestLoyaltyItem = useAppSelector(selectHighestPricedLoyaltyItem); const { useLoyaltyPoints } = useAppSelector(selectCart); @@ -83,6 +84,7 @@ export default function useOrder() { uuid: user_uuid, pickup_comments: "", pickup_time: estimateTime, + car_plate: plateCar, delivery_pickup_interval: "", orderPrice: orderPrice, use_loylaty: useLoyaltyPoints && highestLoyaltyItem ? 1 : 0,