Hub v1: install API, licences, health dashboard, alerts
- Protocol 1 (docs/hub-protocol.md): public key, register, signed heartbeats - Ed25519 licence tokens (30-day validity, status, expiry, grace, limits) - Dashboard: installs, install detail, customers and licences, alerts, settings and audit log; two-factor login required - Alert checks every 5 minutes, emailed once; heartbeat roll-up after 30 days - Unit tests for encryption, tokens, signatures, TOTP and alert rules Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { ago, fmtDate } from "@/lib/format";
|
||||
import type { InstallSummary } from "@/lib/types";
|
||||
import { Badge, Loading, PageTitle, Stat } from "@/components/ui";
|
||||
|
||||
type Dashboard = {
|
||||
latestVersion: string | null;
|
||||
counts: { installs: number; healthy: number; warning: number; critical: number; behind: number; customers: number; openAlerts: number; licences: Record<string, number> };
|
||||
installs: InstallSummary[];
|
||||
};
|
||||
|
||||
/** Every install at a glance: health, version, licence, last heartbeat. */
|
||||
export default function OverviewPage() {
|
||||
const [data, setData] = useState<Dashboard | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const load = () => api<Dashboard>("/api/admin/dashboard").then(d => { setData(d); setError(null); }).catch(e => setError(errorText(e)));
|
||||
load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
|
||||
if (error) return <p className="text-sm text-red-700">{error}</p>;
|
||||
if (!data) return <Loading />;
|
||||
const c = data.counts;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageTitle title="Installs" subtitle={data.latestVersion ? `Latest release: ${data.latestVersion}` : "Set the latest release in Settings to see who is behind."} />
|
||||
<div className="mb-6 grid grid-cols-2 gap-3 md:grid-cols-5">
|
||||
<Stat label="Installs" value={c.installs} />
|
||||
<Stat label="Healthy" value={c.healthy} tone="green" />
|
||||
<Stat label="Warnings" value={c.warning} tone={c.warning ? "amber" : undefined} />
|
||||
<Stat label="Critical" value={c.critical} tone={c.critical ? "red" : undefined} />
|
||||
<Stat label="Behind latest" value={c.behind} tone={c.behind ? "amber" : undefined} />
|
||||
</div>
|
||||
|
||||
{data.installs.length === 0 ? (
|
||||
<div className="card text-sm text-slate-600">
|
||||
No installs yet. Add a <Link href="/customers" className="text-indigo-600 hover:underline">customer</Link>, generate a licence, and enter its key in the church's Hope Events setup.
|
||||
</div>
|
||||
) : (
|
||||
<div className="card overflow-x-auto p-0">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="bg-slate-50 text-left text-xs text-slate-500">
|
||||
<tr><th className="p-3">Install</th><th className="p-3">Health</th><th className="p-3">Version</th><th className="p-3">Licence</th><th className="p-3">Last heartbeat</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.installs.map(i => (
|
||||
<tr key={i.id} className="border-t align-top hover:bg-slate-50">
|
||||
<td className="p-3">
|
||||
<Link href={`/installs/${i.id}`} className="font-medium text-indigo-700 hover:underline">{i.customer?.name || i.name}</Link>
|
||||
<div className="text-xs text-slate-500">{i.url}</div>
|
||||
</td>
|
||||
<td className="p-3">
|
||||
<Badge value={i.status} />
|
||||
{i.problems.filter(p => p.level !== "info").map(p => <div key={p.type} className="mt-1 text-xs text-slate-600">{p.message}</div>)}
|
||||
</td>
|
||||
<td className="p-3 whitespace-nowrap">{i.version || "—"}{i.behind && <span className="ml-1 text-xs text-amber-700">(behind)</span>}</td>
|
||||
<td className="p-3 whitespace-nowrap">
|
||||
{i.licence ? <><Badge value={i.licence.status} />{i.licence.expiresAt && <div className="mt-1 text-xs text-slate-500">to {fmtDate(i.licence.expiresAt, false)}</div>}</> : <span className="text-xs text-slate-400">none</span>}
|
||||
</td>
|
||||
<td className="p-3 whitespace-nowrap" title={fmtDate(i.lastHeartbeatAt)}>{ago(i.lastHeartbeatAt)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user