Billing tiers on the install page, plan picker on licences (1.6.2)

- Install page shows the 12-month event-income band (Cross Events 2.0.2+),
  the tier it falls in with its price and founding price, and flags a
  licence whose plan is a different tier.
- Licence card: Plan picker (Trial or Seed to Network).
- Protocol doc: 14 income bands and eventIncome12m.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-03 12:18:02 +02:00
co-authored by Claude Opus 5.5
parent 922a17fbed
commit 219b08538f
10 changed files with 103 additions and 12 deletions
+13 -2
View File
@@ -6,6 +6,7 @@ import { useParams } from "next/navigation";
import { ArrowLeft, Copy, KeyRound } from "lucide-react";
import { api, errorText } from "@/lib/api";
import { ago, fmtDate } from "@/lib/format";
import { PLANS } from "@/lib/tiers";
import type { Customer, Licence, LicenceStatus } from "@/lib/types";
import { Badge, Loading, Message, PageTitle } from "@/components/ui";
@@ -16,6 +17,7 @@ const dateInput = (d: string | null) => (d ? d.slice(0, 10) : "");
function LicenceCard({ licence, onSaved, setMsg }: { licence: Licence; onSaved: () => void; setMsg: (m: Msg) => void }) {
const [form, setForm] = useState({
status: licence.status,
plan: licence.plan,
expiresAt: dateInput(licence.expiresAt),
graceDays: String(licence.graceDays),
aiRand: String(licence.aiMonthlyCapCents / 100),
@@ -32,6 +34,7 @@ function LicenceCard({ licence, onSaved, setMsg }: { licence: Licence; onSaved:
method: "PUT",
body: {
status: form.status,
plan: form.plan,
// End of the chosen day, South African time.
expiresAt: form.expiresAt ? `${form.expiresAt}T23:59:59+02:00` : null,
graceDays: form.graceDays,
@@ -67,7 +70,15 @@ function LicenceCard({ licence, onSaved, setMsg }: { licence: Licence; onSaved:
? <>Used by <Link href={`/installs/${licence.install.id}`} className="text-indigo-600 hover:underline">{licence.install.url}</Link> · last heartbeat {ago(licence.install.lastHeartbeatAt)}</>
: "Not used yet — enter this key in the church's Cross Events setup (or Site settings → Licence)."}
</div>
<div className="grid gap-3 sm:grid-cols-5">
<div className="grid gap-3 sm:grid-cols-6">
<div>
<label className="label" htmlFor={`plan-${licence.id}`}>Plan</label>
<select id={`plan-${licence.id}`} className="input" value={form.plan} onChange={e => setForm({ ...form, plan: e.target.value })}>
{!PLANS.includes(form.plan) && <option value={form.plan}>{form.plan}</option>}
{PLANS.map(p => <option key={p} value={p}>{p}</option>)}
</select>
<p className="mt-1 text-xs text-slate-500">Shown on the church&apos;s Licence page. Founding discount: note it below.</p>
</div>
<div>
<label className="label">Status</label>
<select className="input" value={form.status} onChange={e => setForm({ ...form, status: e.target.value as LicenceStatus })}>
@@ -98,7 +109,7 @@ function LicenceCard({ licence, onSaved, setMsg }: { licence: Licence; onSaved:
</div>
<div>
<label className="label">Notes</label>
<input className="input" value={form.notes} onChange={e => setForm({ ...form, notes: e.target.value })} placeholder="e.g. paid annually, invoice #123" />
<input className="input" value={form.notes} onChange={e => setForm({ ...form, notes: e.target.value })} placeholder="e.g. founding church, paid annually, invoice #123" />
</div>
<div className="flex flex-wrap gap-2">
<button className="btn-primary" onClick={save} disabled={busy}>{busy ? "Saving…" : "Save licence"}</button>
+11 -1
View File
@@ -7,6 +7,7 @@ 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 type { AiHelperUse, AiMonth, AiStatus, Health, InstallEvent, InstallSummary, Licence, Stats } from "@/lib/types";
import { Badge, Loading, Message, PageTitle, Pager } from "@/components/ui";
@@ -43,6 +44,7 @@ export default function InstallPage() {
if (!d) return msg ? <Message msg={msg} /> : <Loading />;
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<string, number>();
@@ -94,7 +96,7 @@ export default function InstallPage() {
<Row k="Tickets (30 days / total)" v={s.tickets ? `${s.tickets.last30d ?? 0} / ${s.tickets.total ?? 0}` : "—"} />
<Row k="Check-ins (30 days)" v={s.checkIns?.last30d ?? "—"} />
<Row k="Messages (30 days)" v={s.messages ? `${s.messages.email30d ?? 0} email, ${s.messages.whatsapp30d ?? 0} WhatsApp` : "—"} />
<Row k="Income (30 days / all time)" v={s.income ? `${s.income.last30d || "—"} / ${s.income.allTime || "—"}` : "—"} />
<Row k="Income (30 days / all time, with donations)" v={s.income ? `${s.income.last30d || "—"} / ${s.income.allTime || "—"}` : "—"} />
<Row k="Payment providers" v={s.paymentProviders?.join(", ") || "—"} />
<Row k="Campuses" v={s.campuses == null ? "—" : s.campuses ? `On${s.campusCount != null ? ` — ${s.campusCount} active` : ""}` : "Off"} />
{points.length > 1 && (
@@ -115,6 +117,14 @@ export default function InstallPage() {
<Row k="Status" v={<Badge value={d.licence.status} />} />
<Row k="Expires" v={d.licence.expiresAt ? fmtDate(d.licence.expiresAt, false) : "no end date"} />
<Row k="Grace" v={`${d.licence.graceDays} days`} />
<Row k="Plan" v={d.licence.plan || "—"} />
<Row k="Event income (12 months)" v={s.income?.eventIncome12m || "not sent (Cross Events before 2.0.2)"} />
{tier && (
<Row
k="Tier for that income"
v={<>{tier.name} · {tierPrice(tier)}{d.licence.plan !== tier.name && d.licence.plan !== "Trial" && <span className="ml-1 text-amber-700">(plan is {d.licence.plan})</span>}</>}
/>
)}
<Row k="AI cap" v={d.licence.aiMonthlyCapCents ? `${rand(d.licence.aiMonthlyCapCents)} / month` : "off"} />
<Row k="AI markup" v={d.licence.aiMarkupPercent == null ? "default" : `${d.licence.aiMarkupPercent}%`} />
<Link href={`/customers/${d.customer.id}`} className="mt-3 inline-block text-sm text-indigo-600 hover:underline">Change the licence →</Link>
+44
View File
@@ -0,0 +1,44 @@
// Cross Events licence tiers, billed on a site's event income over the last 12 months (the
// `eventIncome12m` band, Cross Events 2.0.2+). The public prices are in crosscode-site
// src/data/pricing.mjs: change both together. Every tier edge is also a band edge on the install
// (BAND_TOPS in hope-events backend/src/hub/report.js), so a band always falls in one tier.
export type Tier = { name: string; upTo: number | null; monthly: number | null; founding: number | null };
export const TIERS: Tier[] = [
{ name: "Seed", upTo: 50_000, monthly: 350, founding: 230 },
{ name: "Sprout", upTo: 150_000, monthly: 550, founding: 360 },
{ name: "Grow", upTo: 400_000, monthly: 850, founding: 550 },
{ name: "Flourish", upTo: 1_000_000, monthly: 1350, founding: 880 },
{ name: "Harvest", upTo: 2_500_000, monthly: 2100, founding: 1370 },
{ name: "Abundance", upTo: 5_000_000, monthly: 3200, founding: 2080 },
{ name: "Movement", upTo: 10_000_000, monthly: 4800, founding: 3120 },
{ name: "Network", upTo: null, monthly: null, founding: null }, // priced per church, from R7 500
];
/** Licence plans offered on a licence: the tiers, plus a trial. */
export const PLANS = ["Trial", ...TIERS.map(t => t.name)];
/** The highest rand amount in a band label ("R100 001–R150 000" → 150000; "over R10 000 000" → Infinity). */
function bandTop(band: string): number | null {
if (/^over /i.test(band)) return Infinity;
const parts = band.split("–");
if (parts.length !== 2) return null;
const n = Number(parts[1].replace(/[^\d]/g, ""));
return Number.isFinite(n) && parts[1].trim() !== "" ? n : null;
}
/**
* The tier a band falls in, or null when it can't tell. An older install's "over R100 000" can't
* be placed (it could be any tier from Sprout up).
*/
export function tierForBand(band: string | null | undefined): Tier | null {
if (!band) return null;
if (band === "over R100 000") return null;
const top = bandTop(band);
if (top == null) return null;
return TIERS.find(t => t.upTo == null || top <= t.upTo) || null;
}
export const tierPrice = (t: Tier) =>
t.monthly == null ? "priced per church" : `R${t.monthly.toLocaleString("en-ZA")}/month (founding R${t.founding?.toLocaleString("en-ZA")})`;
+1 -1
View File
@@ -61,7 +61,7 @@ export type Stats = {
paymentProviders?: string[];
campuses?: boolean;
campusCount?: number;
income?: { last30d?: string; allTime?: string };
income?: { last30d?: string; allTime?: string; eventIncome12m?: string };
};
export type InstallEvent = { id: string; type: string; level: Problem["level"]; message: string; createdAt: string; resolvedAt: string | null; install?: { id: string; name: string; url: string } };