Hub 2.14.0: customer page as a summary and tabs, popups for every edit

- Customer page: header tiles (products, owing, next invoice, address, AI) and three
  tabs (Overview, Products, Invoices and payments), the tab in the URL; #billing links
  open Invoices and payments and Billing's links use ?tab=invoices.
- Every add or edit is a popup (new Modal in components/ui.tsx: Esc / click outside,
  asks before discarding changes, focus kept inside, full screen on a phone). The page
  shows only read views. Record payment is a popup on Billing and the invoice page too.
- One card per product: licence and billing fields in one Edit with one Save (each
  endpoint called only if its fields changed); suspend/revoke/reactivate/release in a
  ⋯ menu. Contact and billing details edited together. One page-level message.
- History as one timeline with a filter; each kind on its own keeps its sortable table.
- CustomerBilling.tsx split into components/customer/; plan in docs/CUSTOMER-PAGE-PLAN.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 11:14:05 +02:00
co-authored by Claude Opus 5.5
parent fc9e3faaf9
commit 590757e040
26 changed files with 1530 additions and 656 deletions
@@ -0,0 +1,60 @@
"use client";
import React, { useState } from "react";
import { api, errorText } from "@/lib/api";
import { CYCLE, day, type BillingCycle } from "@/lib/billing";
import { FormError, Modal } from "@/components/ui";
import { Field, Fields, ModalButtons, ReadCard } from "./ReadCard";
import { changed, type CustomerBillingData, type Done } from "./shared";
/** The church's billing schedule: one for all its products. The page holds the popup (the Next invoice popup opens it too). */
export function ScheduleCard({ b, onEdit }: { b: CustomerBillingData; onEdit: () => void }) {
const off = b.billingCycle === "none";
return (
<ReadCard title="Billing schedule" onEdit={onEdit}>
<Fields>
<Field label="Billing">{CYCLE[b.billingCycle]}</Field>
{!off && <Field label="Billing started">{b.billingStart && day(b.billingStart)}</Field>}
{!off && <Field label="Next invoice">{b.nextInvoiceDate && day(b.nextInvoiceDate)}</Field>}
{!off && <Field label="Next tier review">{b.reviewDate && day(b.reviewDate)}</Field>}
</Fields>
</ReadCard>
);
}
export function ScheduleModal({ b, onClose, onDone }: { b: CustomerBillingData; onClose: () => void; onDone: Done }) {
const form0 = { billingCycle: b.billingCycle, billingStart: b.billingStart || "", nextInvoiceDate: b.nextInvoiceDate || "", reviewDate: b.reviewDate || "" };
const [form, setForm] = useState(form0);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const off = form.billingCycle === "none";
const save = async (e: React.FormEvent) => {
e.preventDefault();
setBusy(true);
setError(null);
try {
await api(`/api/admin/billing/customers/${b.id}`, { method: "PUT", body: { billingCycle: form.billingCycle, billingStart: form.billingStart || null, nextInvoiceDate: form.nextInvoiceDate || null, reviewDate: form.reviewDate || null } });
onDone({ type: "ok", text: off ? "Saved: this church isn't billed." : "Billing saved. The next draft, for all the church's products, is made 14 days before the next invoice date." });
} catch (err) { setError(errorText(err)); } finally { setBusy(false); }
};
return (
<Modal title="Billing schedule" onClose={onClose} dirty={changed(form, form0)}>
<form onSubmit={save} className="space-y-3">
<div className="grid gap-3 sm:grid-cols-2">
<div>
<label className="label" htmlFor="cycle">Billing</label>
<select id="cycle" className="input" value={form.billingCycle} onChange={e => setForm({ ...form, billingCycle: e.target.value as BillingCycle })}>
{(Object.keys(CYCLE) as BillingCycle[]).map(k => <option key={k} value={k}>{CYCLE[k]}</option>)}
</select>
</div>
<div><label className="label" htmlFor="start">Billing started</label><input id="start" type="date" className="input" value={form.billingStart} onChange={e => setForm({ ...form, billingStart: e.target.value })} disabled={off} /></div>
<div><label className="label" htmlFor="next">Next invoice</label><input id="next" type="date" className="input" value={form.nextInvoiceDate} onChange={e => setForm({ ...form, nextInvoiceDate: e.target.value })} disabled={off} /></div>
<div><label className="label" htmlFor="review">Next tier review</label><input id="review" type="date" className="input" value={form.reviewDate} onChange={e => setForm({ ...form, reviewDate: e.target.value })} disabled={off} /></div>
</div>
<p className="text-xs text-slate-500">One invoice covers all the church&apos;s products, in advance, on the same day of the month as billing started. Leave the next invoice and review blank to start from the billing date and review a year later. Starting billing charges the products that aren&apos;t charged yet from the billing date; a product added later starts after its free month.</p>
<FormError error={error} />
<ModalButtons busy={busy} onCancel={onClose} />
</form>
</Modal>
);
}