'use client'; import { useState } from 'react'; import Link from 'next/link'; import { ShieldAlert } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; import { useUIStore } from '@/stores/ui-store'; import { cn } from '@/lib/utils'; import { AlertCard, AlertCardEmpty } from './alert-card'; import { useAlertCount, useAlertList, useAlertRealtime } from './use-alerts'; export function AlertBell() { const portSlug = useUIStore((s) => s.currentPortSlug); const [open, setOpen] = useState(false); // Count is cheap (one aggregate query) - fire on every page so the badge stays live. // List is heavier - only fetch when the popover is actually open. const { data: count } = useAlertCount(); const { data: list, isLoading } = useAlertList('open', open); useAlertRealtime(); const total = count?.total ?? 0; const critical = count?.bySeverity.critical ?? 0; const alerts = list?.data ?? []; const top = alerts.slice(0, 5); return (

Active alerts

View all
{isLoading ? (
Loading…
) : top.length === 0 ? (
) : (
{top.map((a) => ( ))}
)}
); }