"use client"; import React, { useCallback, useEffect, useState } from "react"; import Link from "next/link"; import { useParams } from "next/navigation"; import { ArrowLeft } from "lucide-react"; import { api, errorText } from "@/lib/api"; import { ago, bytes, fmtDate, rand, randFine } from "@/lib/format"; import { usePaged } from "@/lib/paging"; import { tierForBand, tierPrice } from "@/lib/tiers"; import { PRODUCT_NAMES } from "@/lib/products"; import type { AiHelperUse, AiMonth, AiStatus, Health, InstallEvent, InstallSummary, Licence, Stats, UnmetRequirement } from "@/lib/types"; import { Badge, Loading, Message, PageTitle, Pager } from "@/components/ui"; type Detail = { id: string; name: string; url: string; version: string | null; protocolVersion: number; timezone: string | null; notes: string | null; adminContact: { name?: string; email?: string } | null; server: { node?: string; postgres?: string; os?: string } | null; features: Record | null; registeredAt: string; lastHeartbeatAt: string | null; releasedAt: string | null; health: Health | null; stats: Stats | null; customer: { id: string; name: string }; licence: (Licence & { tokenPreview: { status: string; validUntil: string; licenceExpiresAt: string | null } }) | null; summary: InstallSummary; events: InstallEvent[]; heartbeats: { receivedAt: string; version: string | null; stats: Stats | null }[]; ai: { status: AiStatus; months: AiMonth[]; helpers: AiHelperUse[] }; update: { latestVersion: string | null; behind: boolean; unmetRequirements: UnmetRequirement[] }; }; const NO_EVENTS: InstallEvent[] = []; const Row =({ k, v }: { k: string; v: React.ReactNode }) => (
{k}{v}
); /** One install: health, usage, licence, history. */ export default function InstallPage() { const { id } = useParams<{ id: string }>(); const [d, setD] = useState(null); const [notes, setNotes] = useState(""); const [msg, setMsg] = useState<{ type: "ok" | "err"; text: string } | null>(null); const load = useCallback(() => api(`/api/admin/installs/${id}`).then(x => { setD(x); setNotes(x.notes || ""); }).catch(e => setMsg({ type: "err", text: errorText(e) })), [id]); useEffect(() => { load(); }, [load]); const history = usePaged(d?.events || NO_EVENTS, id, 20); if (!d) return msg ? : ; const h = d.health || {}; const s = d.stats || {}; const tier = tierForBand(s.income?.eventIncome12m); const diskPct = h.disk && h.disk.totalBytes ? Math.round((h.disk.freeBytes / h.disk.totalBytes) * 100) : null; // One point per day for the last 30 days: registrations in the last 30 days, as reported. const daily = new Map(); for (const b of d.heartbeats) daily.set(b.receivedAt.slice(0, 10), b.stats?.registrations?.last30d ?? 0); const points = [...daily.entries()]; const max = Math.max(1, ...points.map(([, v]) => v)); const saveNotes = async () => { try { await api(`/api/admin/installs/${id}`, { method: "PUT", body: { notes } }); setMsg({ type: "ok", text: "Notes saved." }); } catch (e) { setMsg({ type: "err", text: errorText(e) }); } }; return ( <> Installs {d.url}} actions={} /> {d.releasedAt &&
} {d.summary.problems.length > 0 && (
{d.summary.problems.map(p =>
{p.message}
)}
)} {d.update.unmetRequirements.length > 0 && (

Updating to {d.update.latestVersion} needs the church's other products first, so Request update is refused until then:

    {d.update.unmetRequirements.map(u => (
  • {PRODUCT_NAMES[u.product]} {u.version} or later{u.current ? ` (it runs ${u.current})` : " (not installed)"}
  • ))}
)}

Health

Usage

{points.length > 1 && (
Registrations in the last 30 days, per day reported
{points.map(([day, v]) =>
)}
)}

Licence

{d.licence ? ( <> {d.licence.key}} /> } /> {tier && ( {tier.name} · {tierPrice(tier)}{d.licence.plan !== tier.name && d.licence.plan !== "Trial" && (plan is {d.licence.plan})}} /> )} Change the licence → ) :

No licence (released).

}

About

` : ""}` : "—"} />