"use client"; import React, { useEffect, useMemo, useState } from "react"; import Link from "next/link"; import { api, errorText } from "@/lib/api"; import { ago, fmtDate } from "@/lib/format"; import { matches, usePaged } from "@/lib/paging"; import type { InstallSummary } from "@/lib/types"; import { PRODUCTS, PRODUCT_NAMES, type Product } from "@/lib/products"; import { Badge, Loading, PageTitle, Pager, SearchInput, Stat } from "@/components/ui"; type Dashboard = { latestVersion: string | null; latestVersions: Partial>; counts: { installs: number; healthy: number; warning: number; critical: number; behind: number; customers: number; openAlerts: number; licences: Record }; installs: InstallSummary[]; }; type Health = "all" | InstallSummary["status"] | "behind"; const HEALTH: { key: Health; label: string }[] = [ { key: "all", label: "All health" }, { key: "critical", label: "Critical" }, { key: "warning", label: "Warnings" }, { key: "ok", label: "Healthy" }, { key: "behind", label: "Behind latest" }, ]; /** Every install at a glance: health, version, licence, last heartbeat. */ export default function OverviewPage() { const [data, setData] = useState(null); const [error, setError] = useState(null); const [query, setQuery] = useState(""); const [health, setHealth] = useState("all"); useEffect(() => { const load = () => api("/api/admin/dashboard").then(d => { setData(d); setError(null); }).catch(e => setError(errorText(e))); load(); const t = setInterval(load, 60_000); return () => clearInterval(t); }, []); const shown = useMemo(() => (data?.installs || []).filter(i => (health === "all" || (health === "behind" ? i.behind : i.status === health)) && matches(query, i.customer?.name, i.name, i.url, i.version), ), [data, query, health]); const paged = usePaged(shown, `${query}|${health}`); if (error) return

{error}

; if (!data) return ; const c = data.counts; return ( <> data.latestVersions[p]) ? `Latest releases: ${PRODUCTS.filter(p => data.latestVersions[p]).map(p => `${PRODUCT_NAMES[p]} ${data.latestVersions[p]}`).join(" · ")}` : "Releases appear on the Releases page once they're tagged; then you can see who is behind."} />
{data.installs.length === 0 ? (
No installs yet. Add a customer, generate a licence, and enter its key in the church's Cross Events setup.
) : ( <>
{paged.rows.length === 0 && } {paged.rows.map(i => ( ))}
InstallHealthVersionLicenceLast heartbeat
No installs match.
{i.customer?.name || i.name}
{PRODUCT_NAMES[i.product]} · {i.url}
{i.problems.filter(p => p.level !== "info").map(p =>
{p.message}
)}
{i.version || "—"}{i.behind && (latest {i.latestVersion})} {i.licence ? <>{i.licence.expiresAt &&
to {fmtDate(i.licence.expiresAt, false)}
} : none}
{ago(i.lastHeartbeatAt)}
)} ); }