fix blank page on null data and set default value to 'Not Found'

This commit is contained in:
Wikzyy
2025-05-07 17:45:36 +07:00
parent 873d516988
commit 49ebe79a02
2 changed files with 168 additions and 111 deletions

View File

@ -29,7 +29,7 @@ const statusMap: Record<StatusCode, StatusInfo> = {
W: { label: 'Waiting Schedule', bg: 'bg-yellow-100', text: 'text-yellow-600' }, W: { label: 'Waiting Schedule', bg: 'bg-yellow-100', text: 'text-yellow-600' },
O: { label: 'On Process', bg: 'bg-blue-100', text: 'text-blue-600' }, O: { label: 'On Process', bg: 'bg-blue-100', text: 'text-blue-600' },
F: { label: 'Fail', bg: 'bg-red-100', text: 'text-red-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) => { export const renderStatusBadge = (statusRaw: string | null | undefined) => {
@ -37,13 +37,11 @@ export const renderStatusBadge = (statusRaw: string | null | undefined) => {
const { label, bg, text } = statusMap[status] ?? { const { label, bg, text } = statusMap[status] ?? {
label: 'Unknown', label: 'Unknown',
bg: 'bg-gray-100', bg: 'bg-gray-100',
text: 'text-gray-600', text: 'text-gray-600'
}; };
return ( return (
<span className={`px-2 py-1 text-xs font-semibold rounded-full ${bg} ${text}`}> <span className={`px-2 py-1 text-xs font-semibold rounded-full ${bg} ${text}`}>{label}</span>
{label}
</span>
); );
}; };
@ -58,18 +56,25 @@ const DetailTransaction = () => {
} = useTransactionContext(); } = useTransactionContext();
const [transactionDetails, setTransactionDetails] = useState<any>(null); const [transactionDetails, setTransactionDetails] = useState<any>(null);
const [isLoading, setIsLoading] = useState(false);
useEffect(() => { useEffect(() => {
const fetchTransactionDetails = async () => { const fetchTransactionDetails = async () => {
setIsLoading(true);
if (selectedTransactionId) { if (selectedTransactionId) {
try { try {
const response = await GetData(`${API_URL}/transaction/history/${selectedTransactionId}`, { const response = await GetData(
`${API_URL}/transaction/history/${selectedTransactionId}`,
{
id: selectedTransactionId id: selectedTransactionId
}); }
);
// console.log(response?.data); // console.log(response?.data);
setTransactionDetails(response?.data); setTransactionDetails(response?.data);
} catch (error) { } catch (error) {
console.error('Error fetching transaction', error); console.error('Error fetching transaction', error);
} finally {
setIsLoading(false);
} }
} }
}; };
@ -81,6 +86,16 @@ const DetailTransaction = () => {
const [activeTab, setActiveTab] = useState('detail'); // 'detail', 'log', 'approve' const [activeTab, setActiveTab] = useState('detail'); // 'detail', 'log', 'approve'
const resetForm = () => {
setTransactionDetails(null);
};
useEffect(() => {
if (!showDetailDialog) {
resetForm();
}
}, [showDetailDialog]);
return ( return (
<Dialog open={showDetailDialog} onOpenChange={setShowDetailDialog}> <Dialog open={showDetailDialog} onOpenChange={setShowDetailDialog}>
<DialogContent className="container-fixed max-w-[1024px] flex flex-col p-5 overflow-hidden"> <DialogContent className="container-fixed max-w-[1024px] flex flex-col p-5 overflow-hidden">
@ -92,6 +107,20 @@ const DetailTransaction = () => {
<div className="py-4 overflow-y-auto max-h-[400px]"> <div className="py-4 overflow-y-auto max-h-[400px]">
<div className="space-y-4"> <div className="space-y-4">
<div className="border rounded-lg overflow-x-auto"> <div className="border rounded-lg overflow-x-auto">
{isLoading ? (
<div className="flex flex-col items-center justify-center p-8">
<div className="animate-pulse flex space-x-4 w-full">
<div className="flex-1 space-y-4 py-1">
<div className="h-4 bg-gray-200 rounded w-3/4"></div>
<div className="space-y-2">
<div className="h-4 bg-gray-200 rounded"></div>
<div className="h-4 bg-gray-200 rounded w-5/6"></div>
</div>
</div>
</div>
<p className="mt-4 text-gray-500">Loading Provider Details...</p>
</div>
) : (
<table className="min-w-full table-auto"> <table className="min-w-full table-auto">
<thead> <thead>
<tr className="bg-gray-100"> <tr className="bg-gray-100">
@ -100,27 +129,55 @@ const DetailTransaction = () => {
<th className="px-4 py-2 text-left text-sm text-gray-500">Amount</th> <th className="px-4 py-2 text-left text-sm text-gray-500">Amount</th>
<th className="px-4 py-2 text-left text-sm text-gray-500">Status</th> <th className="px-4 py-2 text-left text-sm text-gray-500">Status</th>
<th className="px-4 py-2 text-left text-sm text-gray-500">Process Date</th> <th className="px-4 py-2 text-left text-sm text-gray-500">Process Date</th>
<th className="px-4 py-2 text-left text-sm text-gray-500">Invoice Number</th> <th className="px-4 py-2 text-left text-sm text-gray-500">
Invoice Number
</th>
<th className="px-4 py-2 text-left text-sm text-gray-500">Actions</th> <th className="px-4 py-2 text-left text-sm text-gray-500">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{transactionDetails?.log && transactionDetails?.log.length > 0 ? ( {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) => ( transactionDetails.log.map(
(
log: {
id: number;
customer: any;
amount: number;
remark: string;
reference: string;
request_date: string;
payment_response: string;
status: string;
},
index: number
) => (
<tr key={index} className="border-t"> <tr key={index} className="border-t">
<td className="px-4 py-2 text-sm text-gray-500">{log.customer.username ?? '-'}</td> <td className="px-4 py-2 text-sm text-gray-500">
<td className="px-4 py-2 text-sm text-gray-500">{log.customer.fullname ?? '-'}</td> {log.customer?.username ?? 'Not Found'}
<td className="px-4 py-2 text-sm text-gray-500">{log.amount ?? '-'}</td> </td>
<td className="px-4 py-2 text-sm text-gray-500">{renderStatusBadge(log.status) ?? '-'}</td> <td className="px-4 py-2 text-sm text-gray-500">
<td className="px-4 py-2 text-sm text-gray-500">{log.request_date && moment(log.request_date).isValid() ? moment(log.request_date).format('DD/MM/YYYY HH:mm:ss') : '-'}</td> {log.customer?.fullname ?? 'Not Found'}
<td className="px-4 py-2 text-sm text-gray-500">{log.reference ?? '-'}</td> </td>
<td className="px-4 py-2 text-sm text-gray-500">
{log.amount ?? '-'}
</td>
<td className="px-4 py-2 text-sm text-gray-500">
{renderStatusBadge(log.status) ?? '-'}
</td>
<td className="px-4 py-2 text-sm text-gray-500">
{log.request_date && moment(log.request_date).isValid()
? moment(log.request_date).format('DD/MM/YYYY HH:mm:ss')
: '-'}
</td>
<td className="px-4 py-2 text-sm text-gray-500">
{log.reference ?? '-'}
</td>
<td className="px-4 py-2 text-sm text-gray-500"> <td className="px-4 py-2 text-sm text-gray-500">
<div key={`actions-${log.id}`}> <div key={`actions-${log.id}`}>
<button <button
className="btn btn-sm btn-icon btn-clear btn-light" className="btn btn-sm btn-icon btn-clear btn-light"
onClick={() => { onClick={() => {
setDetailLogData(log) setDetailLogData(log);
setShowDetailLogDialog(true); setShowDetailLogDialog(true);
}} }}
> >
@ -128,9 +185,9 @@ const DetailTransaction = () => {
</button> </button>
</div> </div>
</td> </td>
</tr> </tr>
)) )
)
) : ( ) : (
<tr> <tr>
<td colSpan={8} className="px-4 py-2 text-center text-sm text-gray-500"> <td colSpan={8} className="px-4 py-2 text-center text-sm text-gray-500">
@ -140,9 +197,9 @@ const DetailTransaction = () => {
)} )}
</tbody> </tbody>
</table> </table>
)}
</div> </div>
</div> </div>
</div> </div>
</DialogBody> </DialogBody>
</DialogContent> </DialogContent>

View File

@ -31,7 +31,7 @@ const ListToolbar = () => {
const handleFilterData = useCallback(() => { const handleFilterData = useCallback(() => {
try { try {
table.getColumn('transaction_date')?.setFilterValue(trxDate); table.getColumn('execution_date')?.setFilterValue(trxDate);
} catch (error) { } catch (error) {
toast.error('Error applying filter'); toast.error('Error applying filter');
console.error('Error applying filter:', error); console.error('Error applying filter:', error);