From 8ab83d02b1e183f4d9409dce6298563bb53da03e Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 3 Dec 2025 10:49:16 +0330 Subject: [PATCH] fix shipment and payment method in payment cart --- .../[id]/components/PaymentSection.tsx | 17 +++++---- .../[id]/components/ShippingSection.tsx | 14 +++++--- .../order/checkout/service/OrderService.ts | 2 +- .../(Dialogs)/order/checkout/types/Types.ts | 35 +++++++++++++++++-- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/PaymentSection.tsx b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/PaymentSection.tsx index e354bd6..7410c33 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/PaymentSection.tsx +++ b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/PaymentSection.tsx @@ -10,12 +10,11 @@ type PaymentSectionProps = { onPaymentTypeChange: (id: string) => void; }; -const getIconByKeyName = (keyName: string, isOnline: boolean): Icon => { - const normalizedKeyName = keyName.toLowerCase(); - if (normalizedKeyName.includes('online') || normalizedKeyName.includes('card') || isOnline) { +const getIconByMethod = (method: "CardOnDelivery" | "Cash" | "Online", gateway: string | null): Icon => { + if (method === "Online" || method === "CardOnDelivery") { return Card; } - if (normalizedKeyName.includes('cash') || normalizedKeyName.includes('delivery')) { + if (method === "Cash") { return Wallet2; } return Card; @@ -30,12 +29,12 @@ export const PaymentSection = ({ paymentType, onPaymentTypeChange }: PaymentSect if (!paymentMethod?.data) return []; return paymentMethod.data - .filter(item => item.isActive && item.paymentMethod.isActive) - .sort((a, b) => a.paymentMethod.order - b.paymentMethod.order) + .filter(item => item.enabled) + .sort((a, b) => a.order - b.order) .map(item => ({ - id: item.paymentMethod.id, - label: item.paymentMethod.name, - icon: getIconByKeyName(item.paymentMethod.keyName, item.paymentMethod.isOnline), + id: item.id, + label: item.title, + icon: getIconByMethod(item.method, item.gateway), })); }, [paymentMethod]); 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 e36c88a..17c5ab9 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx +++ b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/ShippingSection.tsx @@ -4,6 +4,7 @@ import Combobox from '@/components/combobox/Combobox'; import { Box } from 'iconsax-react'; import { useTranslation } from 'react-i18next'; import { useGetShipmentMethod } from '../../hooks/useOrderData'; +import { DeliveryMethod } from '../../types/Types'; type ShippingSectionProps = { deliveryType: string; @@ -15,11 +16,14 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping const { data: shipmentMethod } = useGetShipmentMethod(); const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); - const options = shipmentMethod?.data.map((item) => ({ - id: item.id, - title: item.shipmentMethod.title, - // icon: Box - })) || []; + const options = shipmentMethod?.data + .filter((item: DeliveryMethod) => item.enabled) + .sort((a: DeliveryMethod, b: DeliveryMethod) => a.order - b.order) + .map((item: DeliveryMethod) => ({ + id: item.id, + title: item.title, + icon: Box + })) || []; return (
diff --git a/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts b/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts index 0a1d1c4..14b5e06 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts +++ b/src/app/[name]/(Dialogs)/order/checkout/service/OrderService.ts @@ -6,7 +6,7 @@ import { export const getShipmentMethod = async (): Promise => { const { data } = await api.get( - "/public/shipment-methods/restaurant" + "/public/delivery-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 index e79d959..296cb19 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts +++ b/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts @@ -23,7 +23,22 @@ export interface RestaurantShipmentMethod { isActive: boolean; } -export type ShipmentMethodsResponse = BaseResponse; +export interface DeliveryMethod { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + title: string; + method: "dineIn" | "pickup" | "deliveryCar" | "deliveryCourier"; + restaurant: string; + deliveryFee: number; + minOrderPrice: number; + description: string; + enabled: boolean; + order: number; +} + +export type ShipmentMethodsResponse = BaseResponse; export interface ServiceArea { type: "Polygon"; @@ -56,6 +71,7 @@ export interface Restaurant { tagNames: string | null; images: string | null; vat: number; + domain: string; } export interface PaymentMethod { @@ -85,5 +101,20 @@ export interface RestaurantPaymentMethod { isActive: boolean; } -export type PaymentMethodsResponse = BaseResponse; +export interface PaymentMethodResponse { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + restaurant: Restaurant; + title: string; + method: "CardOnDelivery" | "Cash" | "Online"; + gateway: string | null; + description: string; + enabled: boolean; + order: number; + merchantId: string | null; +} + +export type PaymentMethodsResponse = BaseResponse;