- Product enum (events, accounts, website, app) on Licence and Install, Install.publicKey; existing rows are events - One open licence per product per customer: partial unique index, with a migration guard that names customers with duplicates (npm run check:hub2 lists them beforehand) - Licence keys per product (CEH-, CCA-, CCW-, CCP-); free Accounts licence created with the first other product licence - Protocol v1 registers Events licences only (409 WRONG_PRODUCT); only Events licences can be invoiced until billing per customer - Cross Code Hub in the UI, emails and PDFs - @crosscode/contracts 1.0.0 vendored (backend/vendor) - Steps merge into release/2.0, not main (plan updated) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
5.4 KiB
TypeScript
107 lines
5.4 KiB
TypeScript
"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 { PRODUCT_NAMES } from "@/lib/products";
|
|
import { Badge, Loading, PageTitle, Pager, SearchInput, 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[];
|
|
};
|
|
|
|
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<Dashboard | null>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [query, setQuery] = useState("");
|
|
const [health, setHealth] = useState<Health>("all");
|
|
|
|
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);
|
|
}, []);
|
|
|
|
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 <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}` : "Add the latest release on the Releases page 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 Cross Events setup.
|
|
</div>
|
|
) : (
|
|
<>
|
|
<div className="mb-3 flex flex-wrap gap-2">
|
|
<SearchInput className="w-full sm:w-72" value={query} onChange={setQuery} placeholder="Search church, address or version" />
|
|
<select className="input w-auto" aria-label="Health" value={health} onChange={e => setHealth(e.target.value as Health)}>
|
|
{HEALTH.map(h => <option key={h.key} value={h.key}>{h.label}</option>)}
|
|
</select>
|
|
</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>
|
|
{paged.rows.length === 0 && <tr><td colSpan={5} className="p-3 text-slate-500">No installs match.</td></tr>}
|
|
{paged.rows.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">{PRODUCT_NAMES[i.product]} · {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>
|
|
<Pager {...paged} />
|
|
</div>
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
}
|