import { useState, type FC } from 'react'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { Bell, X, Info, AlertTriangle, AlertCircle, CheckCircle, ExternalLink } from 'lucide-react'; import { getNotifications, markNotificationRead, markAllNotificationsRead, checkUpdates } from '../api/system'; const NotificationCenter: FC = () => { const [isOpen, setIsOpen] = useState(false); const queryClient = useQueryClient(); const { data: notifications = [] } = useQuery({ queryKey: ['notifications'], queryFn: () => getNotifications(true), refetchInterval: 30000, // Poll every 30s }); const { data: updateInfo } = useQuery({ queryKey: ['system-updates'], queryFn: checkUpdates, staleTime: 1000 * 60 * 60, // 1 hour }); const markReadMutation = useMutation({ mutationFn: markNotificationRead, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['notifications'] }); }, }); const markAllReadMutation = useMutation({ mutationFn: markAllNotificationsRead, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['notifications'] }); }, }); const unreadCount = notifications.length + (updateInfo?.available ? 1 : 0); const hasCritical = notifications.some(n => n.type === 'error'); const hasWarning = notifications.some(n => n.type === 'warning') || updateInfo?.available; const getBellColor = () => { if (hasCritical) return 'text-red-500 hover:text-red-600'; if (hasWarning) return 'text-yellow-500 hover:text-yellow-600'; return 'text-green-500 hover:text-green-600'; }; const getIcon = (type: string) => { switch (type) { case 'success': return ; case 'warning': return ; case 'error': return ; default: return ; } }; return (
{isOpen && ( <>
setIsOpen(false)} >

Notifications

{notifications.length > 0 && ( )}
{/* Update Notification */} {updateInfo?.available && (

Update Available: {updateInfo.latest_version}

View Changelog
)} {notifications.length === 0 && !updateInfo?.available ? (
No new notifications
) : ( notifications.map((notification) => (
{getIcon(notification.type)}

{notification.title}

{notification.message}

{new Date(notification.created_at).toLocaleString()}

)) )}
)}
); }; export default NotificationCenter;