import * as React from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Label } from "@/components/ui/label"; import { cn } from "@/lib/utils"; // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- export type AlertSeverity = "NEED_ACTION" | "WATCH" | "INSIGHT"; export interface ReviewableAlert { id: string; name: string; severityCode: AlertSeverity; snoozedUntil?: string; dismissed?: boolean; } export interface ReviewAlertsDialogProps { open: boolean; onOpenChange: (open: boolean) => void; alerts: ReviewableAlert[]; onSave: ( alertId: string, action: { markDone: boolean; snooze: boolean }, ) => void; className?: string; } // --------------------------------------------------------------------------- // Severity config // --------------------------------------------------------------------------- const SEVERITY_CONFIG: Record = { NEED_ACTION: { dot: "bg-destructive", text: "text-destructive" }, WATCH: { dot: "bg-warning", text: "text-warning" }, INSIGHT: { dot: "bg-success", text: "text-success" }, }; // --------------------------------------------------------------------------- // ReviewAlertsDialog // --------------------------------------------------------------------------- export function ReviewAlertsDialog({ open, onOpenChange, alerts, onSave, className, }: ReviewAlertsDialogProps) { const [markDone, setMarkDone] = React.useState(false); const [snooze, setSnooze] = React.useState(false); const activeAlert = alerts.find((a) => !a.dismissed && !a.snoozedUntil); React.useEffect(() => { if (open) { setMarkDone(false); setSnooze(false); } }, [open, activeAlert?.id]); const canSave = (markDone || snooze) && !!activeAlert; return ( Alerts {/* Alert list */}
{alerts.length === 0 ? (

No alerts for this client.

) : ( alerts.map((alert) => { const { dot, text } = SEVERITY_CONFIG[alert.severityCode]; return (
{alert.name}
); }) )}
{/* Actions */} {activeAlert && (

Actions

setMarkDone(!!v)} />
setSnooze(!!v)} />
)}
); }