"use client"; import { useEffect, useState } from "react"; import { Badge } from "@/components/ui/badge"; import type { DashboardData } from "@/lib/dashboard/types"; export function DashboardHeader() { const [degraded, setDegraded] = useState(0); const [total, setTotal] = useState(0); const [time, setTime] = useState(""); useEffect(() => { const fetchStatus = async () => { try { const res = await fetch("/api/dashboard"); if (!res.ok) return; const data: DashboardData = await res.json(); setTotal(data.services.length); setDegraded( data.services.length - data.services.filter((s) => s.state === "running").length, ); } catch { /* ignore */ } }; fetchStatus(); const id = setInterval(fetchStatus, 15000); return () => clearInterval(id); }, []); useEffect(() => { const tick = () => setTime( new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", }), ); tick(); const id = setInterval(tick, 10000); return () => clearInterval(id); }, []); return (
AH

Asep Haryana

0 ? "border-amber-500/30 bg-amber-900/20 text-amber-500" : total > 0 ? "border-emerald-500/30 bg-emerald-900/20 text-emerald-400" : "" }`} > {total > 0 && ( 0 ? "bg-amber-500" : "bg-emerald-400" }`} /> )} {total === 0 ? "No services" : degraded > 0 ? `${degraded} degraded` : "All Systems Operational"} {time}
); }