import { useMemo } from 'react'; import { Button, SectionHeader, useToast } from '@cameleer/design-system'; import { PageLoader } from '../../components/PageLoader'; import { useAlerts, useBulkReadAlerts } from '../../api/queries/alerts'; import { AlertRow } from './AlertRow'; import css from './alerts-page.module.css'; export default function InboxPage() { const { data, isLoading, error } = useAlerts({ state: ['FIRING', 'ACKNOWLEDGED'], limit: 100 }); const bulkRead = useBulkReadAlerts(); const { toast } = useToast(); const unreadIds = useMemo( () => (data ?? []).filter((a) => a.state === 'FIRING').map((a) => a.id), [data], ); if (isLoading) return ; if (error) return
Failed to load alerts: {String(error)}
; const rows = data ?? []; const onMarkAllRead = async () => { if (unreadIds.length === 0) return; try { await bulkRead.mutateAsync(unreadIds); toast({ title: `Marked ${unreadIds.length} as read`, variant: 'success' }); } catch (e) { toast({ title: 'Bulk read failed', description: String(e), variant: 'error' }); } }; return (
Inbox
{rows.length === 0 ? (
No open alerts for you in this environment.
) : ( rows.map((a) => ) )}
); }