"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { authFetch, getApiBase, getToken } from "../lib/auth"; import AdminShell from "../ui/AdminShell"; import { CONFIG_GROUPS, serviceStatusLabel } from "./configNavigation"; type ServiceState = { name: string; status: string }; export default function AdminLandingPage() { const router = useRouter(); const [services, setServices] = useState([]); const [ready, setReady] = useState(false); const [error, setError] = useState(""); useEffect(() => { let active = true; const load = async () => { if (!getToken()) { router.replace("/login"); return; } try { const response = await authFetch(`${getApiBase()}/auth/me`); if (!response.ok) { router.replace("/login"); return; } if ((await response.json())?.role !== "admin") { router.replace("/"); return; } if (!active) return; setReady(true); const status = await authFetch(`${getApiBase()}/status/services`); if (!status.ok) throw new Error("Status unavailable"); const data = await status.json(); if (active) setServices(Array.isArray(data.services) ? data.services : []); } catch { if (active) setError("Connection status is unavailable. Refresh the page to try again."); } }; void load(); return () => { active = false; }; }, [router]); return ( {!ready ? ( error ? (

{error}

) : (

Loading settings…

) ) : (
{error && (

{error}

)} {CONFIG_GROUPS.filter((group) => !group.advanced).map((group) => (

{group.title}

{group.description}

{group.items.map((item) => { const service = services.find((entry) => entry.name.toLowerCase() === item.service?.toLowerCase()); return ( {item.symbol && ( )} {item.label} {item.description} {item.service && ( {serviceStatusLabel(service?.status)} )} ); })}
))}
Advanced tools Hosting, logs, caches and recovery
{CONFIG_GROUPS.filter((group) => group.advanced) .flatMap((group) => group.items) .map((item) => ( {item.label} {item.description} ))}
)}
); }