'use client'; import { useState } from 'react'; import Link from 'next/link'; import { ClipboardSignature, FileText, Eye } from 'lucide-react'; import { AggregatedSection } from './aggregated-section'; import { SigningDetailsDialog } from './signing-details-dialog'; import { useAggregatedFiles, useAggregatedWorkflows } from '@/hooks/use-aggregated-listing'; import { StatusPill, type StatusPillStatus } from '@/components/ui/status-pill'; import type { AggregatedWorkflow, AggregatedFile, AggregatedGroup, } from '@/hooks/use-aggregated-listing'; interface Props { portSlug: string; entityType: 'client' | 'company' | 'yacht'; entityId: string; } function mapWorkflowStatus(status: string): StatusPillStatus { const known: Record = { draft: 'draft', sent: 'sent', partially_signed: 'partial', completed: 'completed', expired: 'expired', cancelled: 'cancelled', }; return known[status] ?? 'pending'; } export function EntityFolderView({ portSlug, entityType, entityId }: Props) { const [detailsId, setDetailsId] = useState(null); // Hook data is the bare AggregatedGroup[] array (hooks unwrap the API envelope). const { data: workflowGroups = [], isLoading: workflowsLoading } = useAggregatedWorkflows( entityType, entityId, ); const { data: fileGroups = [], isLoading: filesLoading } = useAggregatedFiles( entityType, entityId, ); return (
} groups={workflowGroups} loading={workflowsLoading} emptyMessage="No workflows in flight for this entity." renderRow={(w: AggregatedWorkflow, _group: AggregatedGroup) => (
{w.title} {w.status.replace(/_/g, ' ')}
)} /> } groups={fileGroups} loading={filesLoading} emptyMessage="No files for this entity yet." renderRow={(f: AggregatedFile, _group: AggregatedGroup) => { const signedFromDocumentId = f.signedFromDocumentId; return (
{f.filename}
{new Date(f.createdAt).toLocaleDateString('en-GB')} {signedFromDocumentId ? ( ) : null}
); }} /> !open && setDetailsId(null)} />
); }