diff --git a/frontend/src/pages/Uptime.tsx b/frontend/src/pages/Uptime.tsx index 6861a767..8bbcfada 100644 --- a/frontend/src/pages/Uptime.tsx +++ b/frontend/src/pages/Uptime.tsx @@ -6,6 +6,18 @@ import { Activity, ArrowUp, ArrowDown, Settings, X, Pause, RefreshCw, Plus, Load import { toast } from 'react-hot-toast' import { formatDistanceToNow } from 'date-fns'; +type BaseMonitorStatus = 'up' | 'down' | 'pending'; +type EffectiveMonitorStatus = BaseMonitorStatus | 'paused'; + +const normalizeMonitorStatus = (status: string | undefined): BaseMonitorStatus => { + const normalized = status?.toLowerCase(); + if (normalized === 'up' || normalized === 'down' || normalized === 'pending') { + return normalized; + } + + return 'down'; +}; + const MonitorCard: FC<{ monitor: UptimeMonitor; onEdit: (monitor: UptimeMonitor) => void; t: (key: string, options?: Record) => string }> = ({ monitor, onEdit, t }) => { const { data: history } = useQuery({ queryKey: ['uptimeHistory', monitor.id], @@ -64,27 +76,33 @@ const MonitorCard: FC<{ monitor: UptimeMonitor; onEdit: (monitor: UptimeMonitor) ? history.reduce((a, b) => new Date(a.created_at) > new Date(b.created_at) ? a : b) : null - const isPending = monitor.status === 'pending' && (!history || history.length === 0); - const isUp = latestBeat ? latestBeat.status === 'up' : monitor.status === 'up'; + const hasHistory = Boolean(history && history.length > 0); const isPaused = monitor.enabled === false; + const effectiveStatus: EffectiveMonitorStatus = isPaused + ? 'paused' + : latestBeat + ? (latestBeat.status === 'up' ? 'up' : 'down') + : monitor.status === 'pending' && !hasHistory + ? 'pending' + : normalizeMonitorStatus(monitor.status); return ( -
+
{/* Top Row: Name (left), Badge (center-right), Settings (right) */}

{monitor.name}

- {isPaused ? : isPending ?