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:
@@ -0,0 +1,42 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { todayYmd, type Invoice } from "@/lib/billing";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { LinesEditor, editTotal, fromEdit, type EditLine } from "./LinesEditor";
|
||||
|
||||
/**
|
||||
* Hub 2.14.0: a one-off invoice for one church (standby support, set-up…), made as a draft, in a
|
||||
* popup on the customer page. `/billing/invoices/new` is the same form for any church.
|
||||
*/
|
||||
export function OneOffInvoice({ customerId, onClose, onSaved }: { customerId: string; onClose: () => void; onSaved: (inv: Invoice) => void }) {
|
||||
const [form, setForm] = useState({ issueDate: todayYmd(), notes: "" });
|
||||
const [lines, setLines] = useState<EditLine[]>([{ description: "", quantity: "1", unit: "" }]);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const dirty = !!form.notes || fromEdit(lines).length > 0;
|
||||
const save = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
onSaved(await api<Invoice>("/api/admin/billing/invoices", { method: "POST", body: { customerId, ...form, lines: fromEdit(lines) } }));
|
||||
} catch (err) { setError(errorText(err)); } finally { setBusy(false); }
|
||||
};
|
||||
return (
|
||||
<Modal title="One-off invoice" onClose={onClose} dirty={dirty} wide>
|
||||
<form onSubmit={save} className="space-y-4">
|
||||
<p className="text-sm text-slate-600">For anything outside the licence, like standby support for a big event. It's made as a draft for you to approve.</p>
|
||||
<div className="max-w-xs"><label className="label" htmlFor="oo-date">Invoice date</label><input id="oo-date" type="date" className="input" value={form.issueDate} onChange={e => setForm({ ...form, issueDate: e.target.value })} required /><p className="mt-1 text-xs text-slate-500">It goes out on this day once approved.</p></div>
|
||||
<LinesEditor lines={lines} onChange={setLines} />
|
||||
<div><label className="label" htmlFor="oo-notes">Notes (printed on the invoice)</label><textarea id="oo-notes" className="input" rows={2} value={form.notes} onChange={e => setForm({ ...form, notes: e.target.value })} /></div>
|
||||
<FormError error={error} />
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<button className="btn-primary" disabled={busy || (editTotal(lines) === 0 && !fromEdit(lines).length)}>{busy ? "Saving…" : "Create draft"}</button>
|
||||
<button type="button" className="btn-secondary" onClick={onClose}>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user