fix shipment and payment method in payment cart
This commit is contained in:
@@ -10,12 +10,11 @@ type PaymentSectionProps = {
|
|||||||
onPaymentTypeChange: (id: string) => void;
|
onPaymentTypeChange: (id: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getIconByKeyName = (keyName: string, isOnline: boolean): Icon => {
|
const getIconByMethod = (method: "CardOnDelivery" | "Cash" | "Online", gateway: string | null): Icon => {
|
||||||
const normalizedKeyName = keyName.toLowerCase();
|
if (method === "Online" || method === "CardOnDelivery") {
|
||||||
if (normalizedKeyName.includes('online') || normalizedKeyName.includes('card') || isOnline) {
|
|
||||||
return Card;
|
return Card;
|
||||||
}
|
}
|
||||||
if (normalizedKeyName.includes('cash') || normalizedKeyName.includes('delivery')) {
|
if (method === "Cash") {
|
||||||
return Wallet2;
|
return Wallet2;
|
||||||
}
|
}
|
||||||
return Card;
|
return Card;
|
||||||
@@ -30,12 +29,12 @@ export const PaymentSection = ({ paymentType, onPaymentTypeChange }: PaymentSect
|
|||||||
if (!paymentMethod?.data) return [];
|
if (!paymentMethod?.data) return [];
|
||||||
|
|
||||||
return paymentMethod.data
|
return paymentMethod.data
|
||||||
.filter(item => item.isActive && item.paymentMethod.isActive)
|
.filter(item => item.enabled)
|
||||||
.sort((a, b) => a.paymentMethod.order - b.paymentMethod.order)
|
.sort((a, b) => a.order - b.order)
|
||||||
.map(item => ({
|
.map(item => ({
|
||||||
id: item.paymentMethod.id,
|
id: item.id,
|
||||||
label: item.paymentMethod.name,
|
label: item.title,
|
||||||
icon: getIconByKeyName(item.paymentMethod.keyName, item.paymentMethod.isOnline),
|
icon: getIconByMethod(item.method, item.gateway),
|
||||||
}));
|
}));
|
||||||
}, [paymentMethod]);
|
}, [paymentMethod]);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ 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 } from '../../hooks/useOrderData';
|
||||||
|
import { DeliveryMethod } from '../../types/Types';
|
||||||
|
|
||||||
type ShippingSectionProps = {
|
type ShippingSectionProps = {
|
||||||
deliveryType: string;
|
deliveryType: string;
|
||||||
@@ -15,11 +16,14 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping
|
|||||||
const { data: shipmentMethod } = useGetShipmentMethod();
|
const { data: shipmentMethod } = useGetShipmentMethod();
|
||||||
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
||||||
|
|
||||||
const options = shipmentMethod?.data.map((item) => ({
|
const options = shipmentMethod?.data
|
||||||
id: item.id,
|
.filter((item: DeliveryMethod) => item.enabled)
|
||||||
title: item.shipmentMethod.title,
|
.sort((a: DeliveryMethod, b: DeliveryMethod) => a.order - b.order)
|
||||||
// icon: Box
|
.map((item: DeliveryMethod) => ({
|
||||||
})) || [];
|
id: item.id,
|
||||||
|
title: item.title,
|
||||||
|
icon: Box
|
||||||
|
})) || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="bg-container rounded-container box-shadow-normal p-4">
|
<section className="bg-container rounded-container box-shadow-normal p-4">
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
|
|
||||||
export const getShipmentMethod = async (): Promise<ShipmentMethodsResponse> => {
|
export const getShipmentMethod = async (): Promise<ShipmentMethodsResponse> => {
|
||||||
const { data } = await api.get<ShipmentMethodsResponse>(
|
const { data } = await api.get<ShipmentMethodsResponse>(
|
||||||
"/public/shipment-methods/restaurant"
|
"/public/delivery-methods/restaurant"
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,7 +23,22 @@ export interface RestaurantShipmentMethod {
|
|||||||
isActive: boolean;
|
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 {
|
export interface ServiceArea {
|
||||||
type: "Polygon";
|
type: "Polygon";
|
||||||
@@ -56,6 +71,7 @@ export interface Restaurant {
|
|||||||
tagNames: string | null;
|
tagNames: string | null;
|
||||||
images: string | null;
|
images: string | null;
|
||||||
vat: number;
|
vat: number;
|
||||||
|
domain: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PaymentMethod {
|
export interface PaymentMethod {
|
||||||
@@ -85,5 +101,20 @@ export interface RestaurantPaymentMethod {
|
|||||||
isActive: boolean;
|
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