fix shipment and payment method in payment cart
This commit is contained in:
@@ -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]);
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<section className="bg-container rounded-container box-shadow-normal p-4">
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
|
||||
export const getShipmentMethod = async (): Promise<ShipmentMethodsResponse> => {
|
||||
const { data } = await api.get<ShipmentMethodsResponse>(
|
||||
"/public/shipment-methods/restaurant"
|
||||
"/public/delivery-methods/restaurant"
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,22 @@ export interface RestaurantShipmentMethod {
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
export type ShipmentMethodsResponse = BaseResponse<RestaurantShipmentMethod[]>;
|
||||
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<DeliveryMethod[]>;
|
||||
|
||||
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<RestaurantPaymentMethod[]>;
|
||||
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<PaymentMethodResponse[]>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user