payment: delivery method section
This commit is contained in:
@@ -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);
|
||||
},
|
||||
});
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user