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
+145
View File
@@ -0,0 +1,145 @@
# Customer page clean-up plan (`/customers/[id]`)
Status: done in Hub 2.14.0 (all five steps in one release) · 2026-11-23
The customer page has grown one card at a time and is now one long scroll of open forms. This plan
reorganises it into a summary header and tabs, merges the duplicated product settings, and does it in
small steps that can each be released on their own. No backend changes are needed.
## What's wrong today
Files: `frontend/src/app/(hub)/customers/[id]/page.tsx` (239 lines) and
`frontend/src/components/billing/CustomerBilling.tsx` (436 lines).
1. **Everything is an open form, all on one page.** About 13 cards: Details, one per licence, new
licence, billing details, billing schedule, address, products, next invoice, statement, invoices,
payments, notices of licence change, billing emails.
2. **Each product appears twice.** The licence card at the top (plan, status, expiry, grace days,
notes) and the billing card further down (charged from, custom price, notice of change). Both show a
plan/tier and each has its own Save button.
3. **Two "details" forms and two message banners.** Customer details and billing details are separate
forms; the page and the Billing section each have a message area, so feedback often appears far from
the button that was clicked.
4. **No summary.** To see what the church has, what it owes and when it's next invoiced you have to
scroll and add it up.
5. **Risky actions next to everyday ones.** Suspend, revoke and release sit beside notes and grace days.
6. **AI settings are buried** at the bottom of the contact details form.
## Target layout
### Header (always visible)
- Name, founding star, archived badge, "customer since".
- A row of `Stat` tiles (existing component in `components/ui.tsx`):
- **Products**: e.g. "Events · Website · Accounts", red/amber if any is suspended or expiring.
- **Owing**: balance, red when overdue.
- **Next invoice**: date and estimated amount.
- **Address**: own domain / Cross Code address / included domain, with the domain.
- **AI**: monthly cap, or "Off".
- Actions: **Record payment**, **One-off invoice**, **Add product**, each opening a popup. **Archive /
Restore** moves into a "⋯" menu.
- Clicking the **Next invoice** tile opens the next-invoice preview in a popup.
### Why there is no Billing tab
The Billing page (`/billing`) is the ledger across all churches: every invoice, every payment, the
founding list. It has nothing that belongs to one church (billing email, postal address, schedule,
next-invoice preview, statement), and its links send you to the customer page for those. So the
customer page still needs them, but they don't need a tab of their own:
- Billing email, postal address and founding are **details**: they join the contact details in one
Details view and one Edit popup (this also fixes "two details forms").
- Custom price and charged-from belong to a **product**: they go on the product card.
- Schedule, next invoice and owing are **summary**: they live in the header tiles.
- Statement, invoices, payments, notices and billing emails are this church's **slice of the Billing
page**: one "Invoices and payments" tab.
Three tabs instead of four.
### Tabs
Using the existing `Tabs` component, with the active tab in the URL (`?tab=products`) so links and
reloads keep it.
| Tab | Contents |
|---|---|
| **Overview** | Details (contact, notes, billing email, postal address, founding), billing schedule, address (own domain / Cross Code / included), AI allowance: each as text with **Edit**. Sites, with their address and last heartbeat (links to `/installs/[id]`). |
| **Products** | **One card per product**, combining the licence and the billing settings (see below). **Add product** button at the top. |
| **Invoices and payments** | Statement (PDF, email) at the top, then invoices, payments, notices of licence change and billing emails. Later, optionally one combined timeline. |
### Popups, not inline forms
Every add or edit opens a popup; the page itself only shows read views. That covers: Edit details,
Edit schedule, Edit address, Edit AI allowance, Add product, Edit product, Notice of licence change,
Record payment, One-off invoice, Next-invoice preview.
- New `Modal` component in `components/ui.tsx` (there is none yet): overlay, title, close button,
closes on Esc or a click outside (asking first if the form has unsaved changes), focus kept inside,
page scroll locked, full-screen sheet at phone width.
- A form's error shows inside the popup next to its Save button; on success the popup closes and the
page message shows the confirmation.
- Confirmations for risky actions (Suspend, Revoke, Release, Archive) stay as they are.
- `RecordPayment` is already a self-contained card with a close button, so it just goes inside a
`Modal`. Using the same popup on `/billing` and the invoice page is a free follow-up.
### One product card
Read view:
```
Cross Events CE-XXXX-XXXX [copy] ● Active
events.hopefamily.co.za · heartbeat 4 min ago
Tier Medium · R350/month · charged from 1 Dec 2026 · expires never
[Notice of change…] [Edit] [⋯]
```
**Edit** opens one popup with one **Save**:
- Licence: tier, expiry, grace days, notes.
- Billing: charged from, custom price.
The "⋯" menu holds Suspend, Revoke and Release from site, each with its existing confirmation, so they
are no longer next to the everyday fields.
The Save still calls the two existing endpoints (`PUT /api/admin/licences/:id` and
`PUT /api/admin/billing/licences/:id`), only those whose fields changed. Accounts keeps its "Free: comes
with the church's other products" line and has no billing fields.
### Messages
One page-level message (a toast or a sticky banner under the header) shared by every tab, replacing the
two banners. Keep the existing wording ("The site picks it up with its next heartbeat…").
### Existing links
`/customers/[id]#billing` is used by `billing/page.tsx` (twice) and `billing/invoices/[id]/page.tsx`.
Treat `#billing` as `?tab=invoices` on load, then change those three links to `?tab=invoices`.
## Steps
Each step is its own branch and Hub release.
1. **Split the files, no visual change.** Move the pieces into `frontend/src/components/customer/`:
`CustomerHeader`, `DetailsCard`, `AiCard`, `LicenceCard`, `NewLicenceForm`, and from
`CustomerBilling.tsx`: `BillingDetails`, `Schedule`, `Address`, `LicenceBilling`, `NextInvoice`,
`Statement`, `InvoiceList`, `PaymentList`, `NoticeList`, `EmailLog`. Load the customer and billing
data once in the page and pass them down. This keeps the later diffs small.
2. **Header summary, tabs and one message.** The biggest improvement for the effort. Includes the
`#billing` → `?tab=invoices` handling and updating the three links.
3. **`Modal` and read views.** Add `Modal`; details (merged with billing details), schedule, address
and AI become read views with Edit popups; Record payment and One-off invoice move into popups.
4. **One card per product.** Merge `LicenceCard` and `LicenceBilling` into a read card with an Edit
popup; suspend/revoke/release go in its "⋯" menu; Add product and Notice of change become popups.
5. *(Optional)* **Invoices and payments as one timeline**: invoices, payments, notices and emails in date order with
a filter.
## Checks for each step
- `frontend` builds and type-checks; backend tests still pass (no backend changes expected).
- Every existing action still works: save details, AI cap/markup, generate licence (and the free
Accounts licence), save/suspend/revoke/release licence, archive/restore, billing details, schedule,
address, product billing, notice of licence change (send, PDF, send again), statement (PDF, email),
one-off invoice, record payment, receipts.
- Popups: Esc and the close button work, unsaved changes ask before closing, errors show in the popup.
- Phone width: tabs scroll sideways, stat tiles wrap, popups go full-screen, no horizontal page scroll.
- CHANGELOG entry and version bump as usual.