payment: delivery method section
This commit is contained in:
@@ -3,8 +3,9 @@
|
|||||||
import Combobox from '@/components/combobox/Combobox';
|
import Combobox from '@/components/combobox/Combobox';
|
||||||
import { Box } from 'iconsax-react';
|
import { Box } from 'iconsax-react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useGetShipmentMethod } from '../../hooks/useOrderData';
|
import { useGetShipmentMethod, useSetDeliveryMethod } from '../../hooks/useOrderData';
|
||||||
import { DeliveryMethod } from '../../types/Types';
|
import { DeliveryMethod } from '../../types/Types';
|
||||||
|
import { useCheckoutStore } from '../../store/Store';
|
||||||
|
|
||||||
type ShippingSectionProps = {
|
type ShippingSectionProps = {
|
||||||
deliveryType: string;
|
deliveryType: string;
|
||||||
@@ -13,8 +14,10 @@ type ShippingSectionProps = {
|
|||||||
|
|
||||||
export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: ShippingSectionProps) => {
|
export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: ShippingSectionProps) => {
|
||||||
|
|
||||||
const { data: shipmentMethod } = useGetShipmentMethod();
|
|
||||||
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
||||||
|
const { data: shipmentMethod } = useGetShipmentMethod();
|
||||||
|
const { mutate: setDeliveryMethod } = useSetDeliveryMethod();
|
||||||
|
const { setIsSelectedShipment } = useCheckoutStore();
|
||||||
|
|
||||||
const options = shipmentMethod?.data
|
const options = shipmentMethod?.data
|
||||||
.filter((item: DeliveryMethod) => item.enabled)
|
.filter((item: DeliveryMethod) => item.enabled)
|
||||||
@@ -33,7 +36,7 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping
|
|||||||
className='relative mt-6'
|
className='relative mt-6'
|
||||||
icon={Box}
|
icon={Box}
|
||||||
title=''
|
title=''
|
||||||
placeholder={'انتخاب روش ارسال'}
|
placeholder={'انتخاب روش تحویل'}
|
||||||
searchable={false}
|
searchable={false}
|
||||||
options={options}
|
options={options}
|
||||||
selectedId={deliveryType}
|
selectedId={deliveryType}
|
||||||
@@ -41,6 +44,11 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping
|
|||||||
const selectedOption = options[i];
|
const selectedOption = options[i];
|
||||||
if (selectedOption) {
|
if (selectedOption) {
|
||||||
onDeliveryTypeChange(selectedOption.id);
|
onDeliveryTypeChange(selectedOption.id);
|
||||||
|
setDeliveryMethod(selectedOption.id, {
|
||||||
|
onSuccess: () => {
|
||||||
|
setIsSelectedShipment(true);
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
getPaymentMethod,
|
getPaymentMethod,
|
||||||
getShipmentMethod,
|
getShipmentMethod,
|
||||||
setAddressCart,
|
setAddressCart,
|
||||||
|
setDeliveryMethod,
|
||||||
} from "../service/OrderService";
|
} from "../service/OrderService";
|
||||||
|
|
||||||
export const useGetShipmentMethod = () => {
|
export const useGetShipmentMethod = () => {
|
||||||
@@ -24,3 +25,9 @@ export const useSetAddressCart = () => {
|
|||||||
mutationFn: setAddressCart,
|
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 });
|
const { data } = await api.patch("/public/cart/address", { addressId: id });
|
||||||
return data;
|
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