'use client'; import { RFA } from '@/types/rfa'; import { DataTable } from '@/components/common/data-table'; import { ColumnDef } from '@tanstack/react-table'; import { StatusBadge } from '@/components/common/status-badge'; import { Button } from '@/components/ui/button'; import { Eye, Edit, FileText } from 'lucide-react'; import Link from 'next/link'; import { format } from 'date-fns'; import { toast } from 'sonner'; interface RFAListProps { data: RFA[]; } export function RFAList({ data }: RFAListProps) { if (!data) return null; const columns: ColumnDef[] = [ { accessorKey: 'rfa_number', header: 'RFA No.', cell: ({ row }) => { return {row.original.correspondence?.correspondenceNumber || '-'}; }, }, { accessorKey: 'subject', header: 'Subject', cell: ({ row }) => { const rev = row.original.revisions?.[0]; return (
{rev?.subject || '-'}
); }, }, { accessorKey: 'project_name', header: 'Project', cell: ({ row }) => { return {row.original.correspondence?.project?.projectName || '-'}; }, }, { accessorKey: 'discipline_name', header: 'Discipline', cell: ({ row }) => {row.original.discipline?.name || '-'}, }, { accessorKey: 'createdAt', header: 'Created', cell: ({ row }) => { const date = row.original.correspondence?.createdAt || row.original.revisions?.[0]?.createdAt; // Fallback or strict? // In backend I set RFA -> Correspondence (createdAt is in Correspondence base) // But RFA revision also has createdAt? // Use correspondence.createdAt usually for document date. return date ? format(new Date(date), 'dd MMM yyyy') : '-'; }, }, { accessorKey: 'status', header: 'Status', cell: ({ row }) => { const status = row.original.revisions?.[0]?.statusCode?.statusName || row.original.revisions?.[0]?.statusCode?.statusCode; return ; }, }, { id: 'actions', cell: ({ row }) => { const item = row.original; const handleViewFile = (e: React.MouseEvent) => { e.preventDefault(); const firstItem = item.revisions?.[0]?.items?.[0]; const firstAttachment = firstItem?.shopDrawingRevision?.attachments?.[0] || firstItem?.asBuiltDrawingRevision?.attachments?.[0]; if (firstAttachment?.url) { window.open(firstAttachment.url, '_blank'); } else { // Use alert or toast. Assuming toast is available or use generic alert for now if toast not imported // But rfa.service.ts in use-rfa.ts uses 'sonner', so 'sonner' is likely available. // I will try to use toast from 'sonner' if I import it, or just window.alert for safety. // User said "หน้าต่างแจ้งเตือน" -> Alert window. toast.error('ไม่พบไฟล์แนบ (No file attached)'); } }; return (
); }, }, ]; return (
{/* Pagination component would go here */}
); }