import type { AlertItem } from '@spendlight/shared'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { ArrowRight, CircleAlert, Lightbulb, PartyPopper, TriangleAlert, X } from 'lucide-react'; import { Link } from 'react-router'; import { api } from '@/lib/api'; import { cn } from '@/lib/utils'; const LOOK = { bad: { icon: CircleAlert, tone: 'bg-bad/12 text-bad-fg' }, warn: { icon: TriangleAlert, tone: 'bg-warn/14 text-warn-fg' }, good: { icon: PartyPopper, tone: 'bg-good/12 text-good-fg' }, info: { icon: Lightbulb, tone: 'bg-accent text-accent-foreground' }, } as const; /** One insight or alert: what happened, why it matters, and a way to see the transactions. */ export function AlertCard({ alert, compact }: { alert: AlertItem; compact?: boolean }) { const client = useQueryClient(); const dismiss = useMutation({ mutationFn: () => api(`/alerts/${alert.id}/dismiss`, { method: 'POST' }), onSuccess: () => client.invalidateQueries({ queryKey: ['alerts'] }), }); const { icon: Icon, tone } = LOOK[alert.severity]; return (
{alert.title}
{alert.body ?{alert.body}
: null} {alert.link ? ( See {alert.link.startsWith('/activity') ? 'transactions' : 'details'}