'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; } // We'd ideally fetch stats from API, but for now we calculate from live data or mock // To do this properly, we need an API endpoint returning stats. // Let's update `api/status` to also return stats or create `api/status/stats`. // For this step, I'll update the visual to SHOW where stats would be, // and we'll implement the backend stats aggregation in the next step. 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
{/* Mini bars visualization for history - Mocked visual for now until API is ready */}
{[...Array(20)].map((_, i) => (
0.95 ? 'bg-red-500' : 'bg-emerald-500'}`} /> ))}
24h: {service.uptime24h ?? 100}% 7d: {service.uptime7d ?? 100}%
))}
)}
); }