"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"; interface RFAListProps { data: RFA[]; } export function RFAList({ data }: RFAListProps) { if (!data) return null; const columns: ColumnDef[] = [ { accessorKey: "rfa_number", header: "RFA No.", cell: ({ row }) => { const rev = row.original.revisions?.[0]; return {rev?.correspondence?.correspondenceNumber || '-'}; }, }, { accessorKey: "subject", header: "Subject", cell: ({ row }) => { const rev = row.original.revisions?.[0]; return (
{rev?.title || '-'}
); }, }, { accessorKey: "contract_name", // AccessorKey can be anything if we provide cell header: "Contract", cell: ({ row }) => { const rev = row.original.revisions?.[0]; return {rev?.correspondence?.project?.projectName || '-'}; }, }, { accessorKey: "discipline_name", header: "Discipline", cell: ({ row }) => {row.original.discipline?.name || '-'}, }, { accessorKey: "createdAt", header: "Created", cell: ({ row }) => { const date = row.original.revisions?.[0]?.correspondence?.createdAt; 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(); // Logic to find first attachment: Check items -> shopDrawingRevision -> attachments const firstAttachment = item.revisions?.[0]?.items?.[0]?.shopDrawingRevision?.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. alert("ไม่พบไฟล์แนบ (No file attached)"); } }; return (
); }, }, ]; return (
{/* Pagination component would go here */}
); }