import * as React from 'react'; /** Shape of the /health API response. */ interface HealthResponse { status: 'ok' | 'degraded'; version?: string; uptime?: number; services: { postgres: 'connected' | 'disconnected'; redis: 'connected' | 'disconnected'; }; } type ServiceStatus = 'connected' | 'disconnected' | 'unknown'; interface HealthState { postgres: ServiceStatus; redis: ServiceStatus; version: string | null; uptime: number | null; lastChecked: Date | null; reachable: boolean; } const initialState: HealthState = { postgres: 'unknown', redis: 'unknown', version: null, uptime: null, lastChecked: null, reachable: true, }; /** Formats seconds into a human-readable uptime string. */ function formatUptime(seconds: number): string { const days = Math.floor(seconds / 86400); const hours = Math.floor((seconds % 86400) / 3600); const minutes = Math.floor((seconds % 3600) / 60); const parts: string[] = []; if (days > 0) parts.push(`${days}d`); if (hours > 0) parts.push(`${hours}h`); parts.push(`${minutes}m`); return parts.join(' '); } interface StatusCardProps { label: string; status: ServiceStatus; } /** Card displaying the connectivity status of a single service. */ function StatusCard({ label, status }: StatusCardProps): React.JSX.Element { const isConnected = status === 'connected'; const isUnknown = status === 'unknown'; return (
{label}
Last checked: {health.lastChecked.toLocaleTimeString()} — auto-refreshes every 30 seconds
)}