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,51 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { PRODUCT_NAMES, type Product } from "@/lib/products";
|
||||
import type { Licence } from "@/lib/types";
|
||||
import { FormError, Modal } from "@/components/ui";
|
||||
import { ModalButtons } from "./ReadCard";
|
||||
import { endOfDay, type Done } from "./shared";
|
||||
|
||||
/** A new licence for a product the church doesn't have yet. Accounts comes free with the first other one. */
|
||||
export function AddProductModal({ customerId, available, onClose, onDone }: { customerId: string; available: Product[]; onClose: () => void; onDone: Done }) {
|
||||
const form0 = { product: available.find(p => p !== "accounts") || available[0], expiresAt: "", graceDays: "14" };
|
||||
const [form, setForm] = useState(form0);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const save = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const l = await api<Licence & { accountsLicence: Licence | null }>(`/api/admin/customers/${customerId}/licences`, {
|
||||
method: "POST", body: { product: form.product, expiresAt: endOfDay(form.expiresAt), graceDays: form.graceDays },
|
||||
});
|
||||
onDone({
|
||||
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}.` : ""),
|
||||
});
|
||||
} catch (err) { setError(errorText(err)); } finally { setBusy(false); }
|
||||
};
|
||||
return (
|
||||
<Modal title="Add a product" onClose={onClose} dirty={form.expiresAt !== "" || form.graceDays !== "14"}>
|
||||
<form onSubmit={save} className="space-y-3">
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
<div>
|
||||
<label className="label" htmlFor="new-product">Product</label>
|
||||
<select id="new-product" className="input" value={form.product} onChange={e => setForm({ ...form, product: e.target.value as Product })}>
|
||||
{available.map(p => <option key={p} value={p}>{PRODUCT_NAMES[p]}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div><label className="label" htmlFor="new-exp">Expires (optional)</label><input id="new-exp" type="date" className="input" value={form.expiresAt} onChange={e => setForm({ ...form, expiresAt: e.target.value })} /></div>
|
||||
<div><label className="label" htmlFor="new-grace">Grace (days)</label><input id="new-grace" type="number" min={0} max={90} className="input" value={form.graceDays} onChange={e => setForm({ ...form, graceDays: e.target.value })} /></div>
|
||||
</div>
|
||||
<p className="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>
|
||||
<FormError error={error} />
|
||||
<ModalButtons busy={busy} onCancel={onClose} label="Generate licence" />
|
||||
</form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user