Files
the-other-dude/frontend/src/components/alerts/AlertBadge.tsx
Jason Staack b840047e19 feat: The Other Dude v9.0.1 — full-featured email system
ci: add GitHub Pages deployment workflow for docs site

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 19:30:44 -05:00

32 lines
882 B
TypeScript

/**
* AlertBadge — renders a red badge with active alert count.
* Polls every 30 seconds. Returns null if count is 0.
*/
import { useQuery } from '@tanstack/react-query'
import { alertsApi } from '@/lib/alertsApi'
import { useAuth } from '@/lib/auth'
export function AlertBadge() {
const { user } = useAuth()
const tenantId = user?.tenant_id
const { data } = useQuery({
queryKey: ['alert-active-count', tenantId],
queryFn: () => alertsApi.getActiveAlertCount(tenantId!),
enabled: !!tenantId,
refetchInterval: 30_000,
})
if (!data?.count) return null
return (
<span
className="bg-error text-text-primary text-xs font-medium rounded-full px-1.5 py-0.5 leading-none min-w-[1.25rem] text-center"
title={`${data.count} active alert${data.count === 1 ? '' : 's'}`}
>
{data.count > 99 ? '99+' : data.count}
</span>
)
}