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
@@ -146,7 +146,7 @@ function InvoiceDetail({ id }: { id: string }) {
<Link href="/billing" className="mb-2 inline-flex items-center gap-1 text-sm text-slate-500 hover:underline"><ArrowLeft className="h-4 w-4" /> Billing</Link>
<PageTitle
title={`Invoice ${inv.number}`}
subtitle={<><Link className="text-indigo-600 hover:underline" href={`/customers/${inv.customerId}#billing`}>{inv.customer?.name}</Link>{inv.customer?.founding && <span className="ml-2 inline-flex items-center gap-1 text-amber-700"><Star className="h-3.5 w-3.5 fill-amber-400 text-amber-400" /> founding church</span>}</>}
subtitle={<><Link className="text-indigo-600 hover:underline" href={`/customers/${inv.customerId}?tab=invoices`}>{inv.customer?.name}</Link>{inv.customer?.founding && <span className="ml-2 inline-flex items-center gap-1 text-amber-700"><Star className="h-3.5 w-3.5 fill-amber-400 text-amber-400" /> founding church</span>}</>}
actions={<StateBadge state={inv.state} />}
/>
<div className="mb-4"><Message msg={msg} /></div>
@@ -184,7 +184,7 @@ function InvoiceDetail({ id }: { id: string }) {
</div>
)}
{paying && <div className="mb-4"><RecordPayment invoice={inv} onClose={() => setPaying(false)} onSaved={m => { setMsg(m); setPaying(false); load(); }} /></div>}
{paying && <RecordPayment invoice={inv} onClose={() => setPaying(false)} onSaved={m => { setMsg(m); setPaying(false); load(); }} />}
<div className="grid gap-6 lg:grid-cols-[2fr_1fr]">
<div className="card space-y-4">
+3 -3
View File
@@ -139,7 +139,7 @@ export default function BillingPage() {
)}
{paying && accounts && (
<div className="mb-6"><RecordPayment customers={accounts.map(a => ({ id: a.id, name: a.name }))} onClose={() => setPaying(false)} onSaved={(m) => { setMsg(m); setPaying(false); loadOverview(); loadPayments(); loadInvoices(); }} /></div>
<RecordPayment customers={accounts.map(a => ({ id: a.id, name: a.name }))} onClose={() => setPaying(false)} onSaved={(m) => { setMsg(m); setPaying(false); loadOverview(); loadPayments(); loadInvoices(); }} />
)}
<Tabs tabs={TABS} active={tab} onChange={openTab} />
@@ -184,7 +184,7 @@ export default function BillingPage() {
{payPaged.rows.map(p => (
<tr key={p.id} className="border-t border-slate-100">
<td className="p-3 font-medium">{p.receiptNumber}<div className="text-xs text-slate-500">{METHOD[p.method] || p.method}{p.reference ? ` · ${p.reference}` : ""}</div></td>
<td className="p-3"><Link className="hover:underline" href={`/customers/${p.customerId}#billing`}>{p.customer?.name}</Link></td>
<td className="p-3"><Link className="hover:underline" href={`/customers/${p.customerId}?tab=invoices`}>{p.customer?.name}</Link></td>
<td className="p-3 whitespace-nowrap">{day(p.paidOn)}</td>
<td className="p-3">{p.invoice ? <Link className="text-indigo-700 hover:underline" href={`/billing/invoices/${p.invoice.id}`}>{p.invoice.number}</Link> : "On account"}</td>
<td className="p-3 text-right tabular-nums">{money(p.amountCents)}</td>
@@ -208,7 +208,7 @@ export default function BillingPage() {
<tbody>
{accSorted.rows.map(a => (
<tr key={a.id} className="border-t border-slate-100 align-top">
<td className="p-3"><Link className="font-medium text-indigo-700 hover:underline" href={`/customers/${a.id}#billing`}>{a.name}</Link><div className="text-xs text-slate-500">{a.billingEmail || ""}</div></td>
<td className="p-3"><Link className="font-medium text-indigo-700 hover:underline" href={`/customers/${a.id}?tab=invoices`}>{a.name}</Link><div className="text-xs text-slate-500">{a.billingEmail || ""}</div></td>
<td className="p-3">
<label className="inline-flex items-center gap-2"><input type="checkbox" checked={a.founding} onChange={() => toggleFounding(a)} /> {a.founding ? "Founding" : "No"}</label>
{a.founding && <div className="text-xs text-slate-500">{a.foundingSince ? `since ${day(a.foundingSince)}` : ""}{a.foundingNote ? ` · ${a.foundingNote}` : ""}</div>}
+118 -196
View File
@@ -3,237 +3,159 @@
import React, { useCallback, useEffect, useState } from "react";
import Link from "next/link";
import { useParams } from "next/navigation";
import { Archive, ArchiveRestore, ArrowLeft, Copy, KeyRound } from "lucide-react";
import { KeyRound, X } from "lucide-react";
import { api, errorText } from "@/lib/api";
import { ago, fmtDate } from "@/lib/format";
import { PLANS_BY_PRODUCT } from "@/lib/tiers";
import { KEY_WHERE, PRODUCTS, PRODUCT_NAMES, byProduct, type Product } from "@/lib/products";
import type { Customer, Licence, LicenceStatus } from "@/lib/types";
import { Badge, Loading, Message, PageTitle } from "@/components/ui";
import { CustomerBilling } from "@/components/billing/CustomerBilling";
import { EmailList } from "@/components/EmailList";
import { PRODUCTS, byProduct } from "@/lib/products";
import type { Customer } from "@/lib/types";
import { Loading, Message, Tabs } from "@/components/ui";
import { RecordPayment } from "@/components/billing/RecordPayment";
import { OneOffInvoice } from "@/components/billing/OneOffInvoice";
import { CustomerHeader, type HeaderAction } from "@/components/customer/CustomerHeader";
import { DetailsCard } from "@/components/customer/DetailsCard";
import { ScheduleCard, ScheduleModal } from "@/components/customer/ScheduleCard";
import { AddressCard, AddressModal } from "@/components/customer/AddressCard";
import { AiCard, AiModal } from "@/components/customer/AiCard";
import { SitesCard } from "@/components/customer/SitesCard";
import { ProductCard } from "@/components/customer/ProductCard";
import { AddProductModal } from "@/components/customer/AddProductModal";
import { NextInvoiceModal } from "@/components/customer/NextInvoice";
import { Statement } from "@/components/customer/Statement";
import { History } from "@/components/customer/History";
import type { CustomerBillingData, Done, Msg, Preview } from "@/components/customer/shared";
type Msg = { type: "ok" | "err"; text: string } | null;
const dateInput = (d: string | null) => (d ? d.slice(0, 10) : "");
type Tab = "overview" | "products" | "invoices";
const TABS: { key: Tab; label: string }[] = [
{ key: "overview", label: "Overview" },
{ key: "products", label: "Products" },
{ key: "invoices", label: "Invoices and payments" },
];
type Popup = Exclude<HeaderAction, "history"> | "schedule" | null;
/** One licence: its key, and the settings that go into the next token the install receives. */
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),
notes: licence.notes || "",
});
const [busy, setBusy] = useState(false);
const save = async () => {
if (form.status !== licence.status && form.status !== "active" && !confirm(`${form.status === "revoked" ? "Revoke" : "Suspend"} this licence? The site becomes read-only after its next heartbeat (tickets still scan, data can still be exported).`)) return;
setBusy(true);
try {
await api(`/api/admin/licences/${licence.id}`, {
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,
notes: form.notes,
},
});
setMsg({ type: "ok", text: "Licence saved. The site picks it up with its next heartbeat (within 15 minutes)." });
onSaved();
} catch (e) { setMsg({ type: "err", text: errorText(e) }); } finally { setBusy(false); }
};
const release = async () => {
if (!confirm("Release this licence from its site? The site's heartbeats are refused from now on, and the key can be registered again from a new address.")) return;
try {
await api(`/api/admin/licences/${licence.id}/release`, { method: "POST" });
setMsg({ type: "ok", text: "Released." });
onSaved();
} catch (e) { setMsg({ type: "err", text: errorText(e) }); }
};
return (
<div className="card space-y-3">
<div className="flex flex-wrap items-center gap-2">
<KeyRound className="h-4 w-4 text-slate-400" />
<span className="font-semibold">{PRODUCT_NAMES[licence.product]}</span>
<code className="text-sm font-semibold tracking-wide">{licence.key}</code>
<button className="text-xs text-indigo-600 hover:underline" onClick={() => navigator.clipboard?.writeText(licence.key)} aria-label="Copy key"><Copy className="inline h-3.5 w-3.5" /> Copy</button>
<span className="ml-auto"><Badge value={licence.status} /></span>
</div>
<div className="text-sm text-slate-600">
{licence.install
? <>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 ${KEY_WHERE[licence.product]}.`}
</div>
<div className="grid gap-3 sm:grid-cols-6">
<div>
<label className="label" htmlFor={`plan-${licence.id}`}>Plan</label>
{licence.product === "accounts" ? (
<input id={`plan-${licence.id}`} className="input" value="Included" disabled />
) : (
<select id={`plan-${licence.id}`} className="input" value={form.plan} onChange={e => setForm({ ...form, plan: e.target.value })}>
{!PLANS_BY_PRODUCT[licence.product].includes(form.plan) && <option value={form.plan}>{form.plan}</option>}
{PLANS_BY_PRODUCT[licence.product].map(p => <option key={p} value={p}>{p}</option>)}
</select>
)}
<p className="mt-1 text-xs text-slate-500">
{licence.product === "accounts"
? "Free: comes with the church's other products."
: "Shown on the church's Licence page. Billing and founding status are under Billing 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 })}>
<option value="active">Active</option>
<option value="suspended">Suspended</option>
<option value="revoked">Revoked</option>
</select>
</div>
<div>
<label className="label">Expires</label>
<input type="date" className="input" value={form.expiresAt} onChange={e => setForm({ ...form, expiresAt: e.target.value })} />
<p className="mt-1 text-xs text-slate-500">{form.expiresAt ? "" : "No end date"}</p>
</div>
<div>
<label className="label">Grace (days)</label>
<input type="number" min={0} max={90} className="input" value={form.graceDays} onChange={e => setForm({ ...form, graceDays: e.target.value })} />
</div>
</div>
<div>
<label className="label">Notes</label>
<input className="input" value={form.notes} onChange={e => setForm({ ...form, notes: e.target.value })} placeholder="Anything worth remembering about this licence" />
</div>
<div className="flex flex-wrap gap-2">
<button className="btn-primary" onClick={save} disabled={busy}>{busy ? "Saving…" : "Save licence"}</button>
{licence.install && <button className="btn-danger" onClick={release}>Release from site</button>}
<span className="self-center text-xs text-slate-400">Created {fmtDate(licence.createdAt, false)}</span>
</div>
</div>
);
/** The tab in the address (?tab=products); the old #billing link opens Invoices and payments. */
function tabFromUrl(): Tab {
const q = new URLSearchParams(window.location.search).get("tab");
if (TABS.some(t => t.key === q)) return q as Tab;
return window.location.hash === "#billing" ? "invoices" : "overview";
}
/**
* Hub 2.14.0: a customer as a summary header and three tabs (Overview, Products, Invoices and
* payments). Every add or edit is a popup; the page only shows read views. The customer, its
* billing and the next-invoice preview are loaded here once and passed down.
*/
export default function CustomerPage() {
const { id } = useParams<{ id: string }>();
const [c, setC] = useState<Customer | null>(null);
const [form, setForm] = useState({ name: "", contactName: "", email: "", phone: "", notes: "", aiRand: "0", aiMarkup: "" });
const [newLicence, setNewLicence] = useState<{ product: Product | ""; expiresAt: string; graceDays: string }>({ product: "", expiresAt: "", graceDays: "14" });
const [b, setB] = useState<CustomerBillingData | null>(null);
const [preview, setPreview] = useState<Preview | null>(null);
const [previewError, setPreviewError] = useState<string | null>(null);
const [msg, setMsg] = useState<Msg>(null);
const [tab, setTab] = useState<Tab>("overview");
const [popup, setPopup] = useState<Popup>(null);
const load = useCallback(() => api<Customer>(`/api/admin/customers/${id}`).then(x => {
setC(x);
setForm({
name: x.name, contactName: x.contactName || "", email: x.email || "", phone: x.phone || "", notes: x.notes || "",
aiRand: String(x.aiMonthlyCapCents / 100), aiMarkup: x.aiMarkupPercent == null ? "" : String(x.aiMarkupPercent),
});
}).catch(e => setMsg({ type: "err", text: errorText(e) })), [id]);
const load = useCallback(() => Promise.all([
api<Customer>(`/api/admin/customers/${id}`).then(setC),
api<CustomerBillingData>(`/api/admin/billing/customers/${id}`).then(setB),
api<Preview>(`/api/admin/billing/customers/${id}/preview`).then(p => { setPreview(p); setPreviewError(null); }).catch(e => setPreviewError(errorText(e))),
]).catch(e => setMsg({ type: "err", text: errorText(e) })), [id]);
useEffect(() => { load(); }, [load]);
useEffect(() => {
const t = tabFromUrl();
setTab(t);
if (window.location.hash === "#billing") window.history.replaceState(null, "", `?tab=${t}`);
}, []);
const openTab = (t: Tab) => {
setTab(t);
window.history.replaceState(null, "", t === "overview" ? window.location.pathname : `?tab=${t}`);
};
// An "ok" message fades after a while; an error stays until it's closed or replaced.
useEffect(() => {
if (msg?.type !== "ok") return;
const t = setTimeout(() => setMsg(m => (m === msg ? null : m)), 12000);
return () => clearTimeout(t);
}, [msg]);
/** Every card and popup reports here: close the popup, show the message, reload. */
const done: Done = m => { setPopup(null); setMsg(m); load(); };
const close = () => setPopup(null);
if (!c) return msg ? <Message msg={msg} /> : <Loading />;
// One open (not revoked) licence per product; Accounts comes with the first other product.
const taken = new Set(c.licences.filter(l => l.status !== "revoked").map(l => l.product));
const available = PRODUCTS.filter(p => !taken.has(p));
const product: Product | undefined = newLicence.product && available.includes(newLicence.product) ? newLicence.product : available.find(p => p !== "accounts") || available[0];
const licences = [...c.licences].sort((a, b) => byProduct(a, b) || (a.status === "revoked" ? 1 : 0) - (b.status === "revoked" ? 1 : 0));
const licences = [...c.licences].sort((x, y) => (x.status === "revoked" ? 1 : 0) - (y.status === "revoked" ? 1 : 0) || byProduct(x, y));
const saveDetails = async (e: React.FormEvent) => {
e.preventDefault();
try {
const { aiRand, aiMarkup, ...details } = form;
await api(`/api/admin/customers/${id}`, {
method: "PUT",
body: { ...details, aiMonthlyCapCents: Math.round((parseFloat(aiRand) || 0) * 100), aiMarkupPercent: aiMarkup.trim() === "" ? null : aiMarkup },
});
setMsg({ type: "ok", text: "Saved. The church's sites pick up an AI change with their next heartbeat (within 15 minutes)." });
load();
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
};
const generate = async (e: React.FormEvent) => {
e.preventDefault();
try {
const l = await api<Licence & { accountsLicence: Licence | null }>(`/api/admin/customers/${id}/licences`, {
method: "POST",
body: { product, expiresAt: newLicence.expiresAt ? `${newLicence.expiresAt}T23:59:59+02:00` : null, graceDays: newLicence.graceDays },
});
setMsg({
type: "ok",
text: `${PRODUCT_NAMES[l.product]} licence ${l.key} created. Send it to the church for their setup.`
+ (l.accountsLicence ? ` Their Accounts licence (free) was created too: ${l.accountsLicence.key}.` : ""),
});
load();
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
};
// Hub 2.12.0: archive (left out of the list and pickers) or restore.
const setArchivedState = async (archive: boolean) => {
if (archive && !confirm(`Archive ${c.name}? It's left out of the customer list until you restore it (Customers → Archived). Nothing else changes.`)) return;
try {
await api(`/api/admin/customers/${id}/${archive ? "archive" : "restore"}`, { method: "POST" });
setMsg({ type: "ok", text: archive ? "Archived. Find it under Customers → Archived." : "Restored: it's in the customer list again." });
load();
done({ type: "ok", text: archive ? "Archived. Find it under Customers → Archived." : "Restored: it's in the customer list again." });
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
};
const onAction = (a: HeaderAction) => { if (a === "history") openTab("invoices"); else setPopup(a); };
return (
<>
<Link href="/customers" className="mb-2 inline-flex items-center gap-1 text-sm text-slate-500 hover:underline"><ArrowLeft className="h-4 w-4" /> Customers</Link>
<PageTitle title={c.name}
subtitle={c.archivedAt ? `Archived ${fmtDate(c.archivedAt, false)} · customer since ${fmtDate(c.createdAt, false)}` : `Customer since ${fmtDate(c.createdAt, false)}`}
actions={c.archivedAt
? <button className="btn-secondary" onClick={() => setArchivedState(false)}><ArchiveRestore className="h-4 w-4" /> Restore</button>
: <button className="btn-secondary" onClick={() => setArchivedState(true)}><Archive className="h-4 w-4" /> Archive</button>} />
<div className="mb-4"><Message msg={msg} /></div>
<CustomerHeader c={c} b={b} preview={preview} canAdd={available.length > 0} onAction={onAction} onArchive={setArchivedState} />
<div className="grid gap-6 lg:grid-cols-[1fr_2fr]">
<form onSubmit={saveDetails} className="card space-y-3 self-start">
<h2 className="font-semibold">Details</h2>
<div><label className="label">Name</label><input className="input" value={form.name} onChange={e => setForm({ ...form, name: e.target.value })} required /></div>
<div><label className="label">Contact person</label><input className="input" value={form.contactName} onChange={e => setForm({ ...form, contactName: e.target.value })} /></div>
<EmailList id="c-email" label="Email" value={form.email} onChange={email => setForm({ ...form, email })} placeholder="office@church.org" />
<div><label className="label">Phone</label><input className="input" value={form.phone} onChange={e => setForm({ ...form, phone: e.target.value })} /></div>
<div><label className="label">Notes</label><textarea className="input" rows={4} value={form.notes} onChange={e => setForm({ ...form, notes: e.target.value })} placeholder="Plan, billing, anything worth remembering" /></div>
<div className="grid gap-3 sm:grid-cols-2">
<div>
<label className="label" htmlFor="ai-cap">AI cap (R / month)</label>
<input id="ai-cap" type="number" min={0} step="1" className="input" value={form.aiRand} onChange={e => setForm({ ...form, aiRand: e.target.value })} />
{msg && (
<div className="sticky top-2 z-30 mb-4 flex items-start gap-2 [&>div]:flex-1 [&>div]:shadow-sm" role="status">
<Message msg={msg} />
<button type="button" aria-label="Dismiss" onClick={() => setMsg(null)} className="mt-2.5 rounded p-1 text-slate-400 hover:bg-slate-100 hover:text-slate-700"><X className="h-4 w-4" /></button>
</div>
)}
<Tabs tabs={TABS} active={tab} onChange={openTab} />
<div role="tabpanel" id={`panel-${tab}`} aria-labelledby={`tab-${tab}`}>
{tab === "overview" && (
<div className="grid gap-4 lg:grid-cols-2">
<div className="space-y-4">
{b && <DetailsCard c={c} b={b} onDone={done} />}
<SitesCard c={c} />
</div>
<div>
<label className="label" htmlFor="ai-markup">AI markup (%)</label>
<input id="ai-markup" type="number" min={0} max={500} step="1" className="input" placeholder="Default" value={form.aiMarkup} onChange={e => setForm({ ...form, aiMarkup: e.target.value })} />
<div className="space-y-4">
{b && <ScheduleCard b={b} onEdit={() => setPopup("schedule")} />}
{b && <AddressCard b={b} onEdit={() => setPopup("address")} onDone={done} />}
<AiCard c={c} onEdit={() => setPopup("ai")} />
</div>
</div>
<p className="text-xs text-slate-500">The AI allowance is the church&apos;s, shared by all its sites: 0 = off (no AI buttons). Counted in charged rand. A blank markup uses the default (Settings → AI).</p>
<button className="btn-secondary">Save details</button>
</form>
)}
<div className="space-y-4">
<h2 className="font-semibold">Licences</h2>
{licences.map(l => <LicenceCard key={`${l.id}-${l.status}-${l.expiresAt}`} licence={l} onSaved={load} setMsg={setMsg} />)}
{product ? (
<form onSubmit={generate} className="card flex flex-wrap items-end gap-3">
<div>
<label className="label" htmlFor="new-product">Product</label>
<select id="new-product" className="input" value={product} onChange={e => setNewLicence({ ...newLicence, product: e.target.value as Product })}>
{available.map(p => <option key={p} value={p}>{PRODUCT_NAMES[p]}</option>)}
</select>
{tab === "products" && (
<div className="space-y-4">
<div className="flex flex-wrap items-center justify-between gap-2">
<p className="text-sm text-slate-500">One licence per product. Accounts is free and comes with the first other product.</p>
{available.length > 0
? <button type="button" className="btn-primary" onClick={() => setPopup("add")}><KeyRound className="h-4 w-4" /> Add product</button>
: <span className="text-sm text-slate-500">This customer has a licence for every product.</span>}
</div>
<div><label className="label">Expires (optional)</label><input type="date" className="input" value={newLicence.expiresAt} onChange={e => setNewLicence({ ...newLicence, expiresAt: e.target.value })} /></div>
<div><label className="label">Grace (days)</label><input type="number" min={0} max={90} className="input w-24" value={newLicence.graceDays} onChange={e => setNewLicence({ ...newLicence, graceDays: e.target.value })} /></div>
<button className="btn-primary"><KeyRound className="h-4 w-4" /> Generate licence</button>
<p className="w-full text-xs text-slate-500">One licence per product (revoke one to replace it). Accounts is free and is created with the first other product.</p>
</form>
) : <p className="text-sm text-slate-500">This customer has a licence for every product.</p>}
</div>
{licences.length === 0 && <div className="card text-sm text-slate-500">No products yet: add one to generate its licence key.</div>}
{licences.map(l => (
<ProductCard key={l.id} licence={l} billing={b?.licences.find(x => x.id === l.id)} plans={b?.plans[l.product] || []} nextInvoiceDate={b?.nextInvoiceDate || null} onDone={done} />
))}
</div>
)}
{tab === "invoices" && b && (
<div className="space-y-4">
<Statement b={b} onDone={done} />
<History b={b} onDone={done} />
<p className="text-xs text-slate-500">All churches&apos; invoices and payments are on <Link href="/billing" className="text-indigo-700 hover:underline">Billing</Link>.</p>
</div>
)}
</div>
<CustomerBilling key={c.licences.map(l => `${l.id}-${l.status}`).join()} customerId={id} />
{popup === "payment" && <RecordPayment customerId={id} onClose={close} onSaved={done} />}
{popup === "oneoff" && <OneOffInvoice customerId={id} onClose={close} onSaved={inv => done({ type: "ok", text: `Draft ${inv.number} made. Open it under Invoices and payments to check and approve it.` })} />}
{popup === "add" && available.length > 0 && <AddProductModal customerId={id} available={available} onClose={close} onDone={m => { done(m); openTab("products"); }} />}
{popup === "preview" && <NextInvoiceModal preview={preview} error={previewError} onClose={close} onSchedule={() => setPopup("schedule")} />}
{popup === "schedule" && b && <ScheduleModal b={b} onClose={close} onDone={done} />}
{popup === "address" && b && <AddressModal b={b} onClose={close} onDone={done} />}
{popup === "ai" && <AiModal c={c} onClose={close} onDone={done} />}
</>
);
}