'use client'; import { useQuery } from '@tanstack/react-query'; import { format } from 'date-fns'; import { Pencil, FileText, Clock, PlusCircle, Archive, RotateCcw } from 'lucide-react'; import { apiFetch } from '@/lib/api/client'; interface TimelineEvent { id: string; type: 'audit' | 'document_event'; action: string; description: string; userId: string | null; createdAt: string; metadata: Record; } interface InterestTimelineProps { interestId: string; } function eventIcon(event: TimelineEvent) { if (event.type === 'document_event') return ; if (event.action === 'create') return ; if (event.action === 'archive') return ; if (event.action === 'restore') return ; if (event.metadata?.type === 'stage_change') return ; return ; } export function InterestTimeline({ interestId }: InterestTimelineProps) { const { data, isLoading } = useQuery<{ data: TimelineEvent[] }>({ queryKey: ['interest-timeline', interestId], queryFn: () => apiFetch(`/api/v1/interests/${interestId}/timeline`), }); if (isLoading) { return (
{[...Array(5)].map((_, i) => (
))}
); } const events = data?.data ?? []; if (events.length === 0) { return (

No activity yet.

); } return (
{/* Vertical line */}
{events.map((event, _idx) => (
{/* Icon */}
{eventIcon(event)}

{event.description}

{format(new Date(event.createdAt), 'MMM d, yyyy HH:mm')} {event.userId && ` ยท by ${event.userId}`}

))}
); }