From 2af2c3482648b5d5c0231c9d25e1d6fb4c170b87 Mon Sep 17 00:00:00 2001 From: Mohammed Al-yaseen Date: Tue, 2 Dec 2025 01:51:14 +0300 Subject: [PATCH] remove extra bottom sheet in checkout page make all them inside the page iteslef --- src/components/InputCard.tsx | 43 +++++++ src/components/ProPhoneInput.tsx | 10 +- src/features/order/orderSlice.ts | 10 ++ .../checkout/components/CarPlateCard.tsx | 37 ++++++ src/pages/checkout/components/GiftCard.tsx | 114 ++++++++++++++++++ src/pages/checkout/hooks/useOrder.ts | 34 +++--- src/pages/checkout/page.tsx | 32 +++-- src/redux/api/others.ts | 29 +++-- 8 files changed, 266 insertions(+), 43 deletions(-) create mode 100644 src/components/InputCard.tsx create mode 100644 src/pages/checkout/components/CarPlateCard.tsx create mode 100644 src/pages/checkout/components/GiftCard.tsx diff --git a/src/components/InputCard.tsx b/src/components/InputCard.tsx new file mode 100644 index 0000000..11e1988 --- /dev/null +++ b/src/components/InputCard.tsx @@ -0,0 +1,43 @@ +import { Form, Input } from "antd"; +import ProInputCard from "components/ProInputCard/ProInputCard.tsx"; +import { updateOrder } from "features/order/orderSlice"; +import { useAppDispatch } from "redux/hooks"; + +interface InputCardProps { + title: string; + name: string; + placeholder: string; + value: string; +} + +export default function InputCard({ + title, + name, + placeholder, + value, +}: InputCardProps) { + const dispatch = useAppDispatch(); + const handleChange = (e: React.ChangeEvent) => { + dispatch(updateOrder({ [name]: e.target.value })); + }; + return ( + <> + + + + + + + ); +} diff --git a/src/components/ProPhoneInput.tsx b/src/components/ProPhoneInput.tsx index 2b0b4f2..554fc20 100644 --- a/src/components/ProPhoneInput.tsx +++ b/src/components/ProPhoneInput.tsx @@ -1,6 +1,5 @@ import { Form } from "antd"; import useFormInstance from "antd/es/form/hooks/useFormInstance"; -import { TitleProps } from "antd/es/typography/Title"; import { PhoneNumberUtil } from "google-libphonenumber"; import { FunctionComponent, useMemo } from "react"; import { useTranslation } from "react-i18next"; @@ -8,16 +7,20 @@ import PhoneInput from "react-phone-input-2"; import { useAppSelector } from "redux/hooks"; import { ProBlack1 } from "ThemeConstants"; -interface ProPhoneInput extends TitleProps { +interface ProPhoneInput { propName?: string; label?: string; getValueCallback?: (value: string) => void; + value?: string; + onChange?: (value: string) => void; } const ProPhoneInput: FunctionComponent = ({ propName, label, getValueCallback, + value, + onChange, }) => { const form = useFormInstance(); const { t } = useTranslation(); @@ -51,8 +54,9 @@ const ProPhoneInput: FunctionComponent = ({ onChange={(value) => { form.setFieldValue(propName, value); getValueCallback?.(value); + onChange?.(value); }} - phone={form.getFieldValue(propName)} + phone={value || form.getFieldValue(propName)} themeName={themeName} placeholder={t("login.mobileNumber")} propName={propName} diff --git a/src/features/order/orderSlice.ts b/src/features/order/orderSlice.ts index 00c54fc..020f327 100644 --- a/src/features/order/orderSlice.ts +++ b/src/features/order/orderSlice.ts @@ -68,6 +68,7 @@ interface CartState { pickupDate: string; pickupTime: string; pickupType: string; + order: any; } // localStorage keys @@ -97,6 +98,7 @@ export const CART_STORAGE_KEYS = { PICKUP_DATE: "fascano_pickup_date", PICKUP_TIME: "fascano_pickup_time", PICKUP_TYPE: "fascano_pickup_type", + ORDER: "fascano_order", } as const; // Utility functions for localStorage @@ -182,6 +184,7 @@ const initialState: CartState = { pickupDate: getFromLocalStorage(CART_STORAGE_KEYS.PICKUP_DATE, ""), pickupTime: getFromLocalStorage(CART_STORAGE_KEYS.PICKUP_TIME, ""), pickupType: getFromLocalStorage(CART_STORAGE_KEYS.PICKUP_TYPE, ""), + order: getFromLocalStorage(CART_STORAGE_KEYS.ORDER, null), }; const orderSlice = createSlice({ @@ -623,6 +626,12 @@ const orderSlice = createSlice({ ); } }, + updateOrder(state, action: PayloadAction) { + state.order = action.payload; + if (typeof window !== "undefined") { + localStorage.setItem(CART_STORAGE_KEYS.ORDER, JSON.stringify(state.order)); + } + }, }, }); @@ -659,6 +668,7 @@ export const { updatePickupDate, updatePickupTime, updatePickUpType, + updateOrder, } = orderSlice.actions; // Tax calculation helper functions diff --git a/src/pages/checkout/components/CarPlateCard.tsx b/src/pages/checkout/components/CarPlateCard.tsx new file mode 100644 index 0000000..9debadd --- /dev/null +++ b/src/pages/checkout/components/CarPlateCard.tsx @@ -0,0 +1,37 @@ +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.plateCar); + return ( + <> + + + { + dispatch(updatePlateCar(e.target.value)); + }} + /> + + + + ); +} diff --git a/src/pages/checkout/components/GiftCard.tsx b/src/pages/checkout/components/GiftCard.tsx new file mode 100644 index 0000000..61c8726 --- /dev/null +++ b/src/pages/checkout/components/GiftCard.tsx @@ -0,0 +1,114 @@ +import { Checkbox, Form, Input } from "antd"; +import ProInputCard from "components/ProInputCard/ProInputCard"; +import ProPhoneInput from "components/ProPhoneInput"; +import ProText from "components/ProText"; +import { selectCart, updateOrder } from "features/order/orderSlice"; +import { useTranslation } from "react-i18next"; +import { useAppDispatch, useAppSelector } from "redux/hooks"; + +const { TextArea } = Input; + +export function GiftCard() { + const { t } = useTranslation(); + const { order } = useAppSelector(selectCart); + const dispatch = useAppDispatch(); + return ( + <> + + + + { + dispatch(updateOrder({ ...order, receiverPhone: e })); + }} + /> + + +