import React, { useState } from 'react'; import moment from 'moment'; import { useTransactionContext } from '../hooks/useTransactionContext'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogBody } from '@/components/ui/dialog'; interface LogType { id: string; amount: number; remark: string; reference: string; response_date: string; status: string; customer?: { username: string; fullname: string; }; payment_response?: string; } type StatusCode = 'W' | 'O' | 'F' | 'D'; interface StatusInfo { label: string; bg: string; text: string; } 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' }, }; 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', }; return ( {label} ); }; const TransactionLogViewer = () => { const { showDetailLogDialog, setShowDetailLogDialog, detailLogData } = useTransactionContext(); return ( Detail Record {/* Tab Content */} {detailLogData && detailLogData != null ? (
ID {detailLogData.customer.id}
Username {detailLogData.customer.username}
Name {detailLogData.customer.fullname}
Amount {detailLogData.amount}
Remark {detailLogData.remark}
Payment Request
{detailLogData.payment_request}
Payment Response
{detailLogData.payment_response}
Status {renderStatusBadge(detailLogData.status)}
Prosess Date {detailLogData.request_date && moment(detailLogData.request_date).isValid() ? moment(detailLogData.request_date).format('DD/MM/YYYY HH:mm:ss') : '-'}
Response Date {detailLogData.response_date && moment(detailLogData.response_date).isValid() ? moment(detailLogData.response_date).format('DD/MM/YYYY HH:mm:ss') : '-'}
Reference Number {detailLogData.reference}
) : (
)}
); }; export default TransactionLogViewer;