import React, { useEffect, useState } from 'react'; import { apiConfig } from '@/config/api.config'; import { useCallApi } from '@/hooks'; const API_URL = apiConfig.api_dashboard; interface Props { startdate: string; enddate: string; } const TransactionValue = ({ startdate, enddate }: Props) => { const { GetData } = useCallApi(); const [responseTransactionValue, setResponseTransactionValue] = useState(null); useEffect(() => { const fetchDataTransactionValue = async () => { try { const res = await GetData(`${API_URL}/transaction-value`, { date_from: startdate, date_to: enddate, }); setResponseTransactionValue(res); } catch (error) { console.error('Error fetching transaction value:', error); } }; fetchDataTransactionValue(); }, [startdate, enddate, GetData]); let transactionData: any[] = []; if (responseTransactionValue?.data?.length > 0) { for (let i = 0; i < responseTransactionValue.data.length; i++) { let type = ""; let unit = ""; const amount = responseTransactionValue.data[i].total_amount; if (amount >= 1000 && amount < 1000000) { unit = "K"; } else if (amount >= 1000000 && amount < 1000000000) { unit = "M"; } else if (amount >= 1000000000) { unit = "B"; } switch (responseTransactionValue.data[i].kind) { case "P": type = "Purchase"; break; case "T": type = "Transfer"; break; case "U": type = "Top Up"; break; case "W": type = "Withdraw"; break; case "R": type = "Return"; break; case "N": type = "Top Up Partner"; break; case "E": type = "Reward"; break; default: type = "Unknown"; break; } transactionData.push({ label: type, value: amount, unit: unit }); } } const maxValue = transactionData.length > 0 ? Math.max(...transactionData.map(item => item.value)) : 1; return (

Transaction Value

{transactionData.length > 0 ? (
{transactionData.map((item, index) => (
{item.label}
{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(item.value)}{item.unit}
))}
) : (
No Data Available
)}
); }; export default TransactionValue;