Hub 2.0 step 7: dashboard per product, revenue, linked products
Dashboard: monthly recurring revenue after discounts, overdue invoices, per-product installs, latest version, behind, critical and licences. Install page: the church's other products and whether they're listed to this site. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ 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 { PRODUCT_NAMES, type Product } 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";
|
||||
|
||||
@@ -24,6 +24,8 @@ type Detail = {
|
||||
heartbeats: { receivedAt: string; version: string | null; stats: Stats | null }[];
|
||||
ai: { status: AiStatus; months: AiMonth[]; helpers: AiHelperUse[] };
|
||||
update: { latestVersion: string | null; behind: boolean; unmetRequirements: UnmetRequirement[] };
|
||||
linkedProducts: { product: Product; installId: string; url: string }[];
|
||||
siblings: { id: string; product: Product; url: string; version: string | null; protocolVersion: number; hasPublicKey: boolean; lastHeartbeatAt: string | null }[];
|
||||
};
|
||||
|
||||
const NO_EVENTS: InstallEvent[] = [];
|
||||
@@ -86,6 +88,27 @@ export default function InstallPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card mb-6 text-sm">
|
||||
<h2 className="mb-2 font-semibold">The church's other products</h2>
|
||||
{d.siblings.length === 0 ? <p className="text-slate-500">None: this is the church's only product in use.</p> : (
|
||||
<>
|
||||
<table className="w-full">
|
||||
<tbody>
|
||||
{d.siblings.map(s => (
|
||||
<tr key={s.id} className="border-t border-slate-100 first:border-0">
|
||||
<td className="py-1.5 pr-3"><Link href={`/installs/${s.id}`} className="text-indigo-700 hover:underline">{PRODUCT_NAMES[s.product]}</Link></td>
|
||||
<td className="py-1.5 pr-3 text-slate-600">{s.url}</td>
|
||||
<td className="py-1.5 pr-3">{s.version || "—"}</td>
|
||||
<td className="py-1.5 text-right text-xs">{d.linkedProducts.some(l => l.installId === s.id) ? <span className="text-green-700">listed to this site</span> : <span className="text-slate-500">{s.hasPublicKey ? "not listed (licence revoked)" : `not listed (protocol ${s.protocolVersion}: no public key yet)`}</span>}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<p className="mt-2 text-xs text-slate-500">{d.protocolVersion >= 2 ? "This site is told about the products listed to it in each heartbeat reply (Linked products), so it can connect to them." : "This site uses protocol 1 (Cross Events before 2.4), so it isn't told about the others yet."}</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
<div className="card">
|
||||
<h2 className="mb-2 font-semibold">Health</h2>
|
||||
|
||||
@@ -12,10 +12,16 @@ import { Badge, Loading, PageTitle, Pager, SearchInput, Stat } from "@/component
|
||||
type Dashboard = {
|
||||
latestVersion: string | null;
|
||||
latestVersions: Partial<Record<Product, string>>;
|
||||
counts: { installs: number; healthy: number; warning: number; critical: number; behind: number; customers: number; openAlerts: number; licences: Record<string, number> };
|
||||
counts: { installs: number; healthy: number; warning: number; critical: number; behind: number; customers: number; openAlerts: number; licences: Record<string, number>; billedCustomers: number; overdueInvoices: number };
|
||||
// Hub 2.0: per product, and the money.
|
||||
byProduct: Record<Product, { installs: number; behind: number; critical: number; licences: Record<string, number> }>;
|
||||
monthlyRecurringCents: number;
|
||||
overdueCents: number;
|
||||
installs: InstallSummary[];
|
||||
};
|
||||
|
||||
const rands = (cents: number) => `R${Math.round(cents / 100).toLocaleString("en-ZA")}`;
|
||||
|
||||
type Health = "all" | InstallSummary["status"] | "behind";
|
||||
const HEALTH: { key: Health; label: string }[] = [
|
||||
{ key: "all", label: "All health" },
|
||||
@@ -65,9 +71,30 @@ export default function OverviewPage() {
|
||||
<Stat label="Behind latest" value={c.behind} tone={c.behind ? "amber" : undefined} />
|
||||
</div>
|
||||
|
||||
<div className="mb-6 grid grid-cols-2 gap-3 md:grid-cols-6">
|
||||
<Link href="/billing" className="col-span-2 md:col-span-1"><Stat label="Monthly recurring" value={rands(data.monthlyRecurringCents)} /></Link>
|
||||
<Link href="/billing" className="col-span-2 md:col-span-1"><Stat label="Overdue" value={c.overdueInvoices ? `${rands(data.overdueCents)} (${c.overdueInvoices})` : "None"} tone={c.overdueInvoices ? "red" : undefined} /></Link>
|
||||
{PRODUCTS.map(p => {
|
||||
const b = data.byProduct[p];
|
||||
const licences = Object.entries(b.licences).filter(([, n]) => n).map(([s, n]) => `${n} ${s}`).join(", ") || "no licences";
|
||||
return (
|
||||
<div key={p} className="card">
|
||||
<div className="text-sm text-slate-500">{PRODUCT_NAMES[p]}</div>
|
||||
<div className="mt-1 text-2xl font-semibold tabular-nums">{b.installs} <span className="text-sm font-normal text-slate-500">install{b.installs === 1 ? "" : "s"}</span></div>
|
||||
<div className="mt-1 text-xs text-slate-500">
|
||||
{data.latestVersions[p] ? `Latest ${data.latestVersions[p]}` : "No release yet"}
|
||||
{b.behind ? <span className="text-amber-700"> · {b.behind} behind</span> : null}
|
||||
{b.critical ? <span className="text-red-700"> · {b.critical} critical</span> : null}
|
||||
</div>
|
||||
<div className="text-xs text-slate-400">{licences}</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</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.
|
||||
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 setup (Cross Events, Website, App or Accounts).
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user