import React from 'react'; import { useQuery } from '@tanstack/react-query'; import { formatDistanceToNow } from 'date-fns'; import { useAuth } from '@/hooks/useAuth'; import { api } from '@/lib/api'; import type { AuditLogEntry } from '@emberclone/shared'; export default function ActivityFeed() { const { user } = useAuth(); const { data: logs, isLoading, error } = useQuery({ queryKey: ['audit-log', 'recent'], queryFn: async () => { const res = await api.get('/audit-log/recent'); return res; }, enabled: !!user, }); if (!user) return null; // Hide widget if not admin and no logs available (or logic handled by backend) // Backend should filter, but we ensure UI consistency here if (!user.isAdmin && (!logs || logs.length === 0)) { return null; } return (

Recent Activity

{logs?.length || 0} entries
{isLoading ? (
Loading activity...
) : error ? (
Failed to load activity feed.
) : logs && logs.length > 0 ? (
    {logs.map((log) => (
  • {log.userName} {formatDistanceToNow(new Date(log.createdAt), { addSuffix: true })}

    {log.action} {log.resource}

  • ))}
) : (
No recent activity found.
)}
); }