payment section
This commit is contained in:
@@ -1,20 +1,43 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Card, Icon, Wallet2 } from 'iconsax-react';
|
import { Card, Icon, Wallet2 } from 'iconsax-react';
|
||||||
|
import { useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useGetPaymentMethod } from '../../hooks/useOrderData';
|
||||||
|
|
||||||
type PaymentSectionProps = {
|
type PaymentSectionProps = {
|
||||||
paymentType: string;
|
paymentType: string;
|
||||||
onPaymentTypeChange: (id: string) => void;
|
onPaymentTypeChange: (id: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PaymentSection = ({ paymentType, onPaymentTypeChange }: PaymentSectionProps) => {
|
const getIconByKeyName = (keyName: string, isOnline: boolean): Icon => {
|
||||||
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
const normalizedKeyName = keyName.toLowerCase();
|
||||||
|
if (normalizedKeyName.includes('online') || normalizedKeyName.includes('card') || isOnline) {
|
||||||
|
return Card;
|
||||||
|
}
|
||||||
|
if (normalizedKeyName.includes('cash') || normalizedKeyName.includes('delivery')) {
|
||||||
|
return Wallet2;
|
||||||
|
}
|
||||||
|
return Card;
|
||||||
|
};
|
||||||
|
|
||||||
const paymentOptions: Array<{ id: string, label: string, icon: Icon }> = [
|
export const PaymentSection = ({ paymentType, onPaymentTypeChange }: PaymentSectionProps) => {
|
||||||
{ id: '0', label: t("SectionPayment.InputPaymentType.Options.Online"), icon: Card },
|
|
||||||
{ id: '1', label: t("SectionPayment.InputPaymentType.Options.CashOnDelivery"), icon: Wallet2 },
|
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
||||||
];
|
const { data: paymentMethod } = useGetPaymentMethod();
|
||||||
|
|
||||||
|
const paymentOptions = useMemo(() => {
|
||||||
|
if (!paymentMethod?.data) return [];
|
||||||
|
|
||||||
|
return paymentMethod.data
|
||||||
|
.filter(item => item.isActive && item.paymentMethod.isActive)
|
||||||
|
.sort((a, b) => a.paymentMethod.order - b.paymentMethod.order)
|
||||||
|
.map(item => ({
|
||||||
|
id: item.paymentMethod.id,
|
||||||
|
label: item.paymentMethod.name,
|
||||||
|
icon: getIconByKeyName(item.paymentMethod.keyName, item.paymentMethod.isOnline),
|
||||||
|
}));
|
||||||
|
}, [paymentMethod]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="bg-container rounded-container box-shadow-normal p-4">
|
<section className="bg-container rounded-container box-shadow-normal p-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user