'use client'; import { Activity, RefreshCcw, AlertCircle } from 'lucide-react'; import { useState, useEffect } from 'react'; interface ServiceStatus { name: string; url: string; status: 'up' | 'down'; latency: number; uptime24h?: number; uptime7d?: number; history?: Array<{ hour: string; up: boolean }>; } export function UptimeCard() { const [services, setServices] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(false); const fetchStatus = async () => { try { const res = await fetch('/api/status'); if (!res.ok) throw new Error('Failed to fetch'); const data = await res.json(); setServices(data); setError(false); } catch (e) { console.error(e); setError(true); } finally { setLoading(false); } }; useEffect(() => { fetchStatus(); const interval = setInterval(fetchStatus, 30000); return () => clearInterval(interval); }, []); return (
Uptime Monitor {loading && }
{error ? (
Failed to load status
) : (
{services.map((service) => (
{service.name}
{service.status === 'up' ? 'UP' : 'DOWN'} {service.latency}ms
{service.history && service.history.length > 0 ? ( service.history.slice(-24).map((h, i) => (
)) ) : ( [...Array(24)].map((_, i) => (
)) )}
24h: {service.uptime24h ?? 100}% 7d: {service.uptime7d ?? 100}%
))}
)}
); }