import { AlertTriangle, Database, ShieldAlert, XCircle } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { ScrollArea } from '@/components/ui/scroll-area'; import { formatDistanceToNow } from 'date-fns'; import { Link } from 'react-router-dom'; import type { ActivityEvent } from '@/hooks/admin/useRecentActivity'; interface RecentActivityTimelineProps { activity?: ActivityEvent[]; isLoading: boolean; } export function RecentActivityTimeline({ activity, isLoading }: RecentActivityTimelineProps) { if (isLoading) { return ( Recent Activity Loading activity... ); } if (!activity || activity.length === 0) { return ( Recent Activity (Last Hour) No recent activity ); } const getEventIcon = (event: ActivityEvent) => { switch (event.type) { case 'error': return XCircle; case 'approval': return Database; case 'alert': return AlertTriangle; } }; const getEventColor = (event: ActivityEvent) => { switch (event.type) { case 'error': return 'text-red-500'; case 'approval': return 'text-orange-500'; case 'alert': return 'text-yellow-500'; } }; const getEventDescription = (event: ActivityEvent) => { switch (event.type) { case 'error': return `${event.error_type} in ${event.endpoint}`; case 'approval': return `Approval failed: ${event.error_message}`; case 'alert': return event.message; } }; const getEventLink = (event: ActivityEvent) => { switch (event.type) { case 'error': return `/admin/error-monitoring`; case 'approval': return `/admin/error-monitoring?tab=approvals`; case 'alert': return `/admin/error-monitoring`; default: return undefined; } }; return ( Recent Activity (Last Hour) {activity.length} events {activity.map((event) => { const Icon = getEventIcon(event); const color = getEventColor(event); const description = getEventDescription(event); const link = getEventLink(event); const content = ( {event.type} {formatDistanceToNow(new Date(event.created_at), { addSuffix: true })} {description} ); return link ? ( {content} ) : ( {content} ); })} ); }
{description}