diff --git a/src/pages/disbursement/history-transaction/blocks/DetailTransaction.tsx b/src/pages/disbursement/history-transaction/blocks/DetailTransaction.tsx index 5f5ff7b..e62a1bb 100644 --- a/src/pages/disbursement/history-transaction/blocks/DetailTransaction.tsx +++ b/src/pages/disbursement/history-transaction/blocks/DetailTransaction.tsx @@ -6,12 +6,12 @@ import { apiConfig } from '@/config/api.config'; import { useEffect, useState } from 'react'; import moment from 'moment'; import { - Dialog, - DialogBody, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle + Dialog, + DialogBody, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle } from '@/components/ui/dialog'; import TransactionLogViewer from './DetailTransactionLog'; @@ -29,125 +29,182 @@ const statusMap: Record = { W: { label: 'Waiting Schedule', bg: 'bg-yellow-100', text: 'text-yellow-600' }, O: { label: 'On Process', bg: 'bg-blue-100', text: 'text-blue-600' }, F: { label: 'Fail', bg: 'bg-red-100', text: 'text-red-600' }, - D: { label: 'Done', bg: 'bg-green-100', text: 'text-green-600' }, + D: { label: 'Done', bg: 'bg-green-100', text: 'text-green-600' } }; export const renderStatusBadge = (statusRaw: string | null | undefined) => { - const status = statusRaw as StatusCode; - const { label, bg, text } = statusMap[status] ?? { - label: 'Unknown', - bg: 'bg-gray-100', - text: 'text-gray-600', - }; + const status = statusRaw as StatusCode; + const { label, bg, text } = statusMap[status] ?? { + label: 'Unknown', + bg: 'bg-gray-100', + text: 'text-gray-600' + }; - return ( - - {label} - - ); + return ( + {label} + ); }; const DetailTransaction = () => { - const { GetData } = useCallApi(); - const { - showDetailDialog, - setShowDetailDialog, - selectedTransactionId, - setShowDetailLogDialog, - setDetailLogData - } = useTransactionContext(); + const { GetData } = useCallApi(); + const { + showDetailDialog, + setShowDetailDialog, + selectedTransactionId, + setShowDetailLogDialog, + setDetailLogData + } = useTransactionContext(); - const [transactionDetails, setTransactionDetails] = useState(null); + const [transactionDetails, setTransactionDetails] = useState(null); + const [isLoading, setIsLoading] = useState(false); - useEffect(() => { - const fetchTransactionDetails = async () => { - if (selectedTransactionId) { - try { - const response = await GetData(`${API_URL}/transaction/history/${selectedTransactionId}`, { - id: selectedTransactionId - }); - // console.log(response?.data); - setTransactionDetails(response?.data); - } catch (error) { - console.error('Error fetching transaction', error); - } + useEffect(() => { + const fetchTransactionDetails = async () => { + setIsLoading(true); + if (selectedTransactionId) { + try { + const response = await GetData( + `${API_URL}/transaction/history/${selectedTransactionId}`, + { + id: selectedTransactionId } - }; - - if (showDetailDialog && selectedTransactionId) { - fetchTransactionDetails(); + ); + // console.log(response?.data); + setTransactionDetails(response?.data); + } catch (error) { + console.error('Error fetching transaction', error); + } finally { + setIsLoading(false); } - }, [showDetailDialog, selectedTransactionId, GetData]); + } + }; - const [activeTab, setActiveTab] = useState('detail'); // 'detail', 'log', 'approve' + if (showDetailDialog && selectedTransactionId) { + fetchTransactionDetails(); + } + }, [showDetailDialog, selectedTransactionId, GetData]); - return ( - - - - Transaction Details - - - {/* Tab Content */} -
-
-
- - - - - - - - - - - - - - - {transactionDetails?.log && transactionDetails?.log.length > 0 ? ( - transactionDetails.log.map((log: { id: number, customer: any, amount: number, remark: string, reference: string, request_date: string, payment_response: string, status: string}, index: number) => ( - - - - - - - - - - - )) - ) : ( - - - - )} - -
UsernameFullnameAmountStatusProcess DateInvoice NumberActions
{log.customer.username ?? '-'}{log.customer.fullname ?? '-'}{log.amount ?? '-'}{renderStatusBadge(log.status) ?? '-'}{log.request_date && moment(log.request_date).isValid() ? moment(log.request_date).format('DD/MM/YYYY HH:mm:ss') : '-'}{log.reference ?? '-'} -
- -
-
- No logs available -
-
+ const [activeTab, setActiveTab] = useState('detail'); // 'detail', 'log', 'approve' + + const resetForm = () => { + setTransactionDetails(null); + }; + + useEffect(() => { + if (!showDetailDialog) { + resetForm(); + } + }, [showDetailDialog]); + + return ( + + + + Transaction Details + + + {/* Tab Content */} +
+
+
+ {isLoading ? ( +
+
+
+
+
+
+
- +
- - -
- ); +

Loading Provider Details...

+
+ ) : ( + + + + + + + + + + + + + + {transactionDetails?.log && transactionDetails.log.length > 0 ? ( + transactionDetails.log.map( + ( + log: { + id: number; + customer: any; + amount: number; + remark: string; + reference: string; + request_date: string; + payment_response: string; + status: string; + }, + index: number + ) => ( + + + + + + + + + + ) + ) + ) : ( + + + + )} + +
UsernameFullnameAmountStatusProcess Date + Invoice Number + Actions
+ {log.customer?.username ?? 'Not Found'} + + {log.customer?.fullname ?? 'Not Found'} + + {log.amount ?? '-'} + + {renderStatusBadge(log.status) ?? '-'} + + {log.request_date && moment(log.request_date).isValid() + ? moment(log.request_date).format('DD/MM/YYYY HH:mm:ss') + : '-'} + + {log.reference ?? '-'} + +
+ +
+
+ No logs available +
+ )} +
+ + +
+
+
+ ); }; export default DetailTransaction; diff --git a/src/pages/disbursement/history-transaction/blocks/ListToolbar.tsx b/src/pages/disbursement/history-transaction/blocks/ListToolbar.tsx index f810d53..1c6d73b 100644 --- a/src/pages/disbursement/history-transaction/blocks/ListToolbar.tsx +++ b/src/pages/disbursement/history-transaction/blocks/ListToolbar.tsx @@ -31,7 +31,7 @@ const ListToolbar = () => { const handleFilterData = useCallback(() => { try { - table.getColumn('transaction_date')?.setFilterValue(trxDate); + table.getColumn('execution_date')?.setFilterValue(trxDate); } catch (error) { toast.error('Error applying filter'); console.error('Error applying filter:', error);