import { useEffect, useState, useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; import { AlertTriangle, Info, X, Settings, ExternalLink } from 'lucide-react'; import api from '../services/api'; import { Button } from '@/components/ui/button'; import { getDismissedNotices, addDismissedNotice, isUrgentNotice } from '../utils/dismissedNotices'; const ICONS = { warning: AlertTriangle, info: Info, error: AlertTriangle, critical: AlertTriangle, }; // The top banner is reserved for genuinely urgent notices, and only one at a time — // everything else lives in the notification center (see NotificationsContext). This // keeps the dashboard clear instead of stacking every setup hint at the top. export default function SystemNotices() { const navigate = useNavigate(); const [notices, setNotices] = useState([]); const [loading, setLoading] = useState(true); const [dismissed, setDismissedState] = useState(getDismissedNotices); const load = useCallback(async () => { try { const data = await api.getSystemNotices(); setNotices(data?.notices || []); } catch { // Non-admin or endpoint error — hide silently. setNotices([]); } finally { setLoading(false); } }, []); useEffect(() => { load(); }, [load]); const handleDismiss = (id) => { setDismissedState(addDismissedNotice(id).slice()); }; const handleAction = (notice) => { if (notice.action_path?.startsWith('http')) { window.open(notice.action_path, '_blank', 'noopener,noreferrer'); } else if (notice.action_path) { navigate(notice.action_path); } }; if (loading) return null; // Urgent only, and at most one — the rest are surfaced in the notification bell. const notice = notices.find((n) => isUrgentNotice(n) && !dismissed.includes(n.id)); if (!notice) return null; const Icon = ICONS[notice.level] || AlertTriangle; return (
{notice.title}
{notice.message}
); }