From bf756e64e7e05d6c916e523d0740b56e19e182a6 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 3 Dec 2025 15:51:38 +0330 Subject: [PATCH] payment: delivery method section --- .../checkout/[id]/components/ShippingSection.tsx | 14 +++++++++++--- .../(Dialogs)/order/checkout/hooks/useOrderData.ts | 7 +++++++ .../order/checkout/service/OrderService.ts | 7 +++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx index 17c5ab9..508e989 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx +++ b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx @@ -3,8 +3,9 @@ import Combobox from '@/components/combobox/Combobox'; import { Box } from 'iconsax-react'; import { useTranslation } from 'react-i18next'; -import { useGetShipmentMethod } from '../../hooks/useOrderData'; +import { useGetShipmentMethod, useSetDeliveryMethod } from '../../hooks/useOrderData'; import { DeliveryMethod } from '../../types/Types'; +import { useCheckoutStore } from '../../store/Store'; type ShippingSectionProps = { deliveryType: string; @@ -13,8 +14,10 @@ type ShippingSectionProps = { export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: ShippingSectionProps) => { - const { data: shipmentMethod } = useGetShipmentMethod(); const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); + const { data: shipmentMethod } = useGetShipmentMethod(); + const { mutate: setDeliveryMethod } = useSetDeliveryMethod(); + const { setIsSelectedShipment } = useCheckoutStore(); const options = shipmentMethod?.data .filter((item: DeliveryMethod) => item.enabled) @@ -33,7 +36,7 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping className='relative mt-6' icon={Box} title='' - placeholder={'انتخاب روش ارسال'} + placeholder={'انتخاب روش تحویل'} searchable={false} options={options} selectedId={deliveryType} @@ -41,6 +44,11 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping const selectedOption = options[i]; if (selectedOption) { onDeliveryTypeChange(selectedOption.id); + setDeliveryMethod(selectedOption.id, { + onSuccess: () => { + setIsSelectedShipment(true); + }, + }); } }} /> diff --git a/src/app/[name]/(Dialogs)/order/checkout/hooks/useOrderData.ts b/src/app/[name]/(Dialogs)/order/checkout/hooks/useOrderData.ts index 95db1b6..b390439 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/hooks/useOrderData.ts +++ b/src/app/[name]/(Dialogs)/order/checkout/hooks/useOrderData.ts @@ -3,6 +3,7 @@ import { getPaymentMethod, getShipmentMethod, setAddressCart, + setDeliveryMethod, } from "../service/OrderService"; export const useGetShipmentMethod = () => { @@ -24,3 +25,9 @@ export const useSetAddressCart = () => { mutationFn: setAddressCart, }); }; + +export const useSetDeliveryMethod = () => { + return useMutation({ + mutationFn: setDeliveryMethod, + }); +}; diff --git a/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts b/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts index 5470faf..7bf3056 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts +++ b/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts @@ -22,3 +22,10 @@ export const setAddressCart = async (id: string) => { const { data } = await api.patch("/public/cart/address", { addressId: id }); return data; }; + +export const setDeliveryMethod = async (id: string) => { + const { data } = await api.patch("/public/cart/delivery-method", { + deliveryMethodId: id, + }); + return data; +};