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 0a88e39..e36c88a 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx +++ b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx @@ -1,8 +1,9 @@ 'use client'; -import Combobox, { ComboboxOption } from '@/components/combobox/Combobox'; -import { Box, Icon, Shop, TruckTick } from 'iconsax-react'; +import Combobox from '@/components/combobox/Combobox'; +import { Box } from 'iconsax-react'; import { useTranslation } from 'react-i18next'; +import { useGetShipmentMethod } from '../../hooks/useOrderData'; type ShippingSectionProps = { deliveryType: string; @@ -10,13 +11,15 @@ type ShippingSectionProps = { }; export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: ShippingSectionProps) => { + + const { data: shipmentMethod } = useGetShipmentMethod(); const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); - const deliveryOptions: Array = [ - { id: '0', title: t("SectionShipping.InputDeliveryType.Options.Delivery"), icon: TruckTick }, - { id: '1', title: t("SectionShipping.InputDeliveryType.Options.Serve"), icon: Shop }, - { id: '2', title: t("SectionShipping.InputDeliveryType.Options.Pickup"), icon: Box }, - ]; + const options = shipmentMethod?.data.map((item) => ({ + id: item.id, + title: item.shipmentMethod.title, + // icon: Box + })) || []; return (
@@ -26,10 +29,16 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping className='relative mt-6' icon={Box} title='' + placeholder={'انتخاب روش ارسال'} searchable={false} - options={deliveryOptions} + options={options} selectedId={deliveryType} - onSelectionChange={(e, i) => onDeliveryTypeChange(String(i))} + onSelectionChange={(e, i) => { + const selectedOption = options[i]; + if (selectedOption) { + onDeliveryTypeChange(selectedOption.id); + } + }} />
diff --git a/src/app/[name]/(Dialogs)/order/checkout/hooks/useOrderData.ts b/src/app/[name]/(Dialogs)/order/checkout/hooks/useOrderData.ts index bcf2609..c9d7d3c 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/hooks/useOrderData.ts +++ b/src/app/[name]/(Dialogs)/order/checkout/hooks/useOrderData.ts @@ -1,5 +1,5 @@ import { useQuery } from "@tanstack/react-query"; -import { getShipmentMethod } from "../service/OrderService"; +import { getPaymentMethod, getShipmentMethod } from "../service/OrderService"; export const useGetShipmentMethod = () => { return useQuery({ @@ -7,3 +7,10 @@ export const useGetShipmentMethod = () => { queryFn: getShipmentMethod, }); }; + +export const useGetPaymentMethod = () => { + return useQuery({ + queryKey: ["payment-method"], + queryFn: getPaymentMethod, + }); +}; diff --git a/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts b/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts index 90168f9..0a1d1c4 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts +++ b/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts @@ -1,6 +1,19 @@ import { api } from "@/config/axios"; +import { + ShipmentMethodsResponse, + PaymentMethodsResponse, +} from "../types/Types"; -export const getShipmentMethod = async () => { - const { data } = await api.get("/public/shipment-methods/restaurant"); +export const getShipmentMethod = async (): Promise => { + const { data } = await api.get( + "/public/shipment-methods/restaurant" + ); + return data; +}; + +export const getPaymentMethod = async (): Promise => { + const { data } = await api.get( + "/public/payments/methods/restaurant" + ); return data; }; diff --git a/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts b/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts new file mode 100644 index 0000000..e79d959 --- /dev/null +++ b/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts @@ -0,0 +1,89 @@ +import { BaseResponse } from "@/app/[name]/(Main)/types/Types"; + +export interface ShipmentMethod { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + name: string; + title: string; + description: string; + isActive: boolean; +} + +export interface RestaurantShipmentMethod { + id: string; + restaurant: string; + shipmentMethod: ShipmentMethod; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + price: number; + minOrderPrice: number; + isActive: boolean; +} + +export type ShipmentMethodsResponse = BaseResponse; + +export interface ServiceArea { + type: "Polygon"; + coordinates: number[][][]; +} + +export interface Restaurant { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + name: string; + slug: string; + logo: string | null; + address: string | null; + menuColor: string | null; + latitude: number | null; + longitude: number | null; + serviceArea: ServiceArea; + isActive: boolean; + establishedYear: number | null; + phoneNumber: string | null; + phone: string; + instagram: string | null; + telegram: string | null; + whatsapp: string | null; + description: string | null; + seoTitle: string | null; + seoDescription: string | null; + tagNames: string | null; + images: string | null; + vat: number; +} + +export interface PaymentMethod { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + name: string; + keyName: string; + description: string; + icon: string | null; + isActive: boolean; + isOnline: boolean; + order: number; + paymentUrl: string | null; +} + +export interface RestaurantPaymentMethod { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + restaurant: Restaurant; + paymentMethod: PaymentMethod; + merchantId: string | null; + callbackUrl: string | null; + isActive: boolean; +} + +export type PaymentMethodsResponse = BaseResponse; +