import { NumericFormat } from 'react-number-format'; import { PATHS } from '@/shared/constants/paths'; import { useNavigate } from '@/shared/lib/hooks/use-navigate'; import { ListItemProps, TransactionCategory } from '../model/types'; import moment from 'moment'; import { useStore } from '@/shared/model/store'; import { getAllTransactionStatusCode, getPaymentMethodName } from '../model/contant'; import { useTranslation } from 'react-i18next'; export const ListItem = ({ transactionCategory, tid, mid, statusCode, installmentMonth, serviceName, serviceCode, serviceDetailName, goodsAmount, amount, customerName, issueNumber, approvalNumber, paymentMethod, processResult, transactionType, transactionDateTime, transactionAmount, deliveryStatus, settlementStatus, cancelStatus, billKey, orderNumber }: ListItemProps) => { const { navigate } = useNavigate(); const { t } = useTranslation(); const getItemClass = () => { let rs = ''; if(statusCode === '0'){ rs = ''; } else if(statusCode === '1'){ rs = 'approved'; } else if(statusCode === '2'){ rs = 'refund'; } return rs; }; const getDotClass = (str?: string) => { let rs = ''; if(statusCode === '0'){ rs = ''; } else if(statusCode === '1'){ rs = 'blue'; } else if(statusCode === '2'){ rs = 'gray'; } return rs; }; const onClickToNavigate = () => { if(transactionCategory === TransactionCategory.AllTransaction){ navigate(PATHS.transaction.allTransaction.detail, { state: { tid: tid, serviceCode: serviceCode } }); } else if(transactionCategory === TransactionCategory.CashReceipt){ navigate(PATHS.transaction.cashReceipt.detail, { state: { tid: tid } }); } else if(transactionCategory === TransactionCategory.Escrow){ navigate(PATHS.transaction.escrow.detail, { state: { tid: tid, serviceCode: serviceCode } }); } else if(transactionCategory === TransactionCategory.Billing){ navigate(PATHS.transaction.billing.detail, { state: { tid: tid, } }); } else{ alert(t('common.error')); } }; const getTime = () => { let timeStr = ''; if(transactionCategory === TransactionCategory.AllTransaction){ let time = transactionDateTime?.substring(8, 12); timeStr = time?.substring(0, 2) + ':' + time?.substring(2, 4); } else{ timeStr = moment(transactionDateTime).format('HH:mm'); } return timeStr }; const getTitle = () => { let str = ''; if(transactionCategory === TransactionCategory.AllTransaction){ let strDetailName = ''; if(serviceDetailName){ strDetailName = serviceDetailName?.split('|').join(','); } if(strDetailName){ let last = strDetailName.slice(-1); if(last === ','){ strDetailName = strDetailName.substring(0, strDetailName.length - 1); } str = `${serviceName}(${strDetailName})`; } else{ str = `${serviceName}`; } } else if(transactionCategory === TransactionCategory.CashReceipt){ str = `${customerName? customerName: '익명'}${issueNumber? '('+issueNumber+')': '' }` } else if(transactionCategory === TransactionCategory.Escrow){ str = `${customerName? customerName: '익명'}${issueNumber? '('+issueNumber+')': '' }` } else if(transactionCategory === TransactionCategory.Billing){ str = `${billKey}` } return str; }; const getStatusName = () => { let str; if(transactionCategory === TransactionCategory.AllTransaction){ const allTransactionStatusCode = getAllTransactionStatusCode(t); Loop1: for(let i=0;i { let rs = []; if(transactionCategory === TransactionCategory.AllTransaction){ rs.push(
{ getTime() } | { getStatusName() } | { mid } { (!!installmentMonth && parseInt(installmentMonth) > 1) && <> | { t('transaction.fields.installmentMonthly', { count: parseInt(installmentMonth) }) } }
); } else if(transactionCategory === TransactionCategory.CashReceipt){ rs.push(
{ getTime() } | { transactionType } | { getPaymentMethodName(t, paymentMethod) } | { processResult }
); } else if(transactionCategory === TransactionCategory.Escrow){ rs.push(
{ getTime() } | { deliveryStatus } | { settlementStatus } | { cancelStatus } { (!!installmentMonth && parseInt(installmentMonth) > 1) && <> | { t('transaction.fields.installmentMonthly', { count: parseInt(installmentMonth) }) } }
); } else if(transactionCategory === TransactionCategory.Billing){ rs.push(
{ getTime() } | { processResult } | { getPaymentMethodName(t, paymentMethod) }
); } return rs; }; return ( <>
onClickToNavigate() } >
{ getTitle() }
{ getDetail() }
{t('home.money', { value: new Intl.NumberFormat('en-US').format(goodsAmount || amount || transactionAmount || 0) })}
); };