'use client'; import { useQuery } from '@tanstack/react-query'; import { formatDistanceToNow } from 'date-fns'; import { apiFetch } from '@/lib/api/client'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { CardSkeleton } from '@/components/shared/loading-skeleton'; import { WidgetErrorBoundary } from './widget-error-boundary'; interface ActivityItem { id: string; action: string; entityType: string; entityId: string | null; userId: string | null; metadata: Record | null; createdAt: string; } const ACTION_VARIANTS: Record = { create: 'default', update: 'secondary', delete: 'destructive', archive: 'outline', restore: 'secondary', }; function ActionBadge({ action }: { action: string }) { const variant = ACTION_VARIANTS[action] ?? 'outline'; return ( {action} ); } function ActivityFeedInner() { const { data, isLoading } = useQuery({ queryKey: ['dashboard', 'activity'], queryFn: () => apiFetch('/api/v1/dashboard/activity'), staleTime: 30_000, retry: 2, }); if (isLoading) { return ; } const items = data ?? []; return ( Recent Activity {items.length === 0 ? (

No recent activity yet — your team's actions (interests created, stages changed, invoices sent) will appear here.

) : (
{items.map((item) => (

{item.entityType} {item.entityId && ( {item.entityId.slice(0, 8)} )}

{formatDistanceToNow(new Date(item.createdAt), { addSuffix: true })}

))}
)}
); } export function ActivityFeed() { return ( ); }