@dainamite/billing 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +658 -0
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/modules/billing/acl.js +20 -0
- package/dist/modules/billing/acl.js.map +7 -0
- package/dist/modules/billing/api/accounts/route.js +182 -0
- package/dist/modules/billing/api/accounts/route.js.map +7 -0
- package/dist/modules/billing/api/export/account/[id]/route.js +170 -0
- package/dist/modules/billing/api/export/account/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/[id]/route.js +85 -0
- package/dist/modules/billing/api/invoices/[id]/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/add-line/route.js +69 -0
- package/dist/modules/billing/api/invoices/add-line/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/edit-line/route.js +78 -0
- package/dist/modules/billing/api/invoices/edit-line/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/post/route.js +74 -0
- package/dist/modules/billing/api/invoices/post/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/remove-line/route.js +69 -0
- package/dist/modules/billing/api/invoices/remove-line/route.js.map +7 -0
- package/dist/modules/billing/api/invoices/route.js +109 -0
- package/dist/modules/billing/api/invoices/route.js.map +7 -0
- package/dist/modules/billing/api/items/bulk/route.js +74 -0
- package/dist/modules/billing/api/items/bulk/route.js.map +7 -0
- package/dist/modules/billing/api/items/route.js +224 -0
- package/dist/modules/billing/api/items/route.js.map +7 -0
- package/dist/modules/billing/api/openapi.js +25 -0
- package/dist/modules/billing/api/openapi.js.map +7 -0
- package/dist/modules/billing/api/run-outcomes/route.js +122 -0
- package/dist/modules/billing/api/run-outcomes/route.js.map +7 -0
- package/dist/modules/billing/api/runs/retry-failed/route.js +70 -0
- package/dist/modules/billing/api/runs/retry-failed/route.js.map +7 -0
- package/dist/modules/billing/api/runs/route.js +143 -0
- package/dist/modules/billing/api/runs/route.js.map +7 -0
- package/dist/modules/billing/api/test-invoices/wipe/route.js +65 -0
- package/dist/modules/billing/api/test-invoices/wipe/route.js.map +7 -0
- package/dist/modules/billing/api/usage/route.js +138 -0
- package/dist/modules/billing/api/usage/route.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js +402 -0
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/[id]/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/accounts/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.js +82 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/accounts/create/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/page.js +173 -0
- package/dist/modules/billing/backend/billing/accounts/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/accounts/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/accounts/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js +500 -0
- package/dist/modules/billing/backend/billing/invoices/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/invoices/[id]/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/invoices/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/invoices/page.js +187 -0
- package/dist/modules/billing/backend/billing/invoices/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/invoices/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/invoices/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/[id]/page.js +265 -0
- package/dist/modules/billing/backend/billing/items/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/[id]/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/items/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/create/page.js +90 -0
- package/dist/modules/billing/backend/billing/items/create/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/create/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/items/create/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/page.js +208 -0
- package/dist/modules/billing/backend/billing/items/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/items/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/items/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.js +293 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/runs/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/page.js +341 -0
- package/dist/modules/billing/backend/billing/runs/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/runs/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/runs/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/usage/create/page.js +100 -0
- package/dist/modules/billing/backend/billing/usage/create/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/usage/create/page.meta.js +25 -0
- package/dist/modules/billing/backend/billing/usage/create/page.meta.js.map +7 -0
- package/dist/modules/billing/ce.js +56 -0
- package/dist/modules/billing/ce.js.map +7 -0
- package/dist/modules/billing/cli.js +67 -0
- package/dist/modules/billing/cli.js.map +7 -0
- package/dist/modules/billing/commands/accounts.js +157 -0
- package/dist/modules/billing/commands/accounts.js.map +7 -0
- package/dist/modules/billing/commands/index.js +6 -0
- package/dist/modules/billing/commands/index.js.map +7 -0
- package/dist/modules/billing/commands/invoices.js +401 -0
- package/dist/modules/billing/commands/invoices.js.map +7 -0
- package/dist/modules/billing/commands/items.js +317 -0
- package/dist/modules/billing/commands/items.js.map +7 -0
- package/dist/modules/billing/commands/runs.js +123 -0
- package/dist/modules/billing/commands/runs.js.map +7 -0
- package/dist/modules/billing/commands/usage.js +88 -0
- package/dist/modules/billing/commands/usage.js.map +7 -0
- package/dist/modules/billing/components/AccountForm.js +420 -0
- package/dist/modules/billing/components/AccountForm.js.map +7 -0
- package/dist/modules/billing/components/DetailFields.js +37 -0
- package/dist/modules/billing/components/DetailFields.js.map +7 -0
- package/dist/modules/billing/components/ItemForm.js +440 -0
- package/dist/modules/billing/components/ItemForm.js.map +7 -0
- package/dist/modules/billing/components/LineFormDialog.js +195 -0
- package/dist/modules/billing/components/LineFormDialog.js.map +7 -0
- package/dist/modules/billing/components/UsageForm.js +262 -0
- package/dist/modules/billing/components/UsageForm.js.map +7 -0
- package/dist/modules/billing/data/entities.js +433 -0
- package/dist/modules/billing/data/entities.js.map +7 -0
- package/dist/modules/billing/data/entityIds.js +12 -0
- package/dist/modules/billing/data/entityIds.js.map +7 -0
- package/dist/modules/billing/data/validators.js +396 -0
- package/dist/modules/billing/data/validators.js.map +7 -0
- package/dist/modules/billing/di.js +6 -0
- package/dist/modules/billing/di.js.map +7 -0
- package/dist/modules/billing/events.js +35 -0
- package/dist/modules/billing/events.js.map +7 -0
- package/dist/modules/billing/i18n/en.json +336 -0
- package/dist/modules/billing/i18n/pl.json +336 -0
- package/dist/modules/billing/index.js +17 -0
- package/dist/modules/billing/index.js.map +7 -0
- package/dist/modules/billing/lib/billPeriod.js +101 -0
- package/dist/modules/billing/lib/billPeriod.js.map +7 -0
- package/dist/modules/billing/lib/billRunEngine.js +256 -0
- package/dist/modules/billing/lib/billRunEngine.js.map +7 -0
- package/dist/modules/billing/lib/billRunLabel.js +8 -0
- package/dist/modules/billing/lib/billRunLabel.js.map +7 -0
- package/dist/modules/billing/lib/idempotency.js +13 -0
- package/dist/modules/billing/lib/idempotency.js.map +7 -0
- package/dist/modules/billing/lib/invoiceStatus.js +38 -0
- package/dist/modules/billing/lib/invoiceStatus.js.map +7 -0
- package/dist/modules/billing/lib/invoiceWriter.js +153 -0
- package/dist/modules/billing/lib/invoiceWriter.js.map +7 -0
- package/dist/modules/billing/lib/itemSelector.js +77 -0
- package/dist/modules/billing/lib/itemSelector.js.map +7 -0
- package/dist/modules/billing/lib/seeds/demo.js +130 -0
- package/dist/modules/billing/lib/seeds/demo.js.map +7 -0
- package/dist/modules/billing/lib/tenantLock.js +32 -0
- package/dist/modules/billing/lib/tenantLock.js.map +7 -0
- package/dist/modules/billing/lib/usageRater.js +150 -0
- package/dist/modules/billing/lib/usageRater.js.map +7 -0
- package/dist/modules/billing/lib/usageRunner.js +82 -0
- package/dist/modules/billing/lib/usageRunner.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20260519000000_billing.js +144 -0
- package/dist/modules/billing/migrations/Migration20260519000000_billing.js.map +7 -0
- package/dist/modules/billing/setup.js +190 -0
- package/dist/modules/billing/setup.js.map +7 -0
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js +47 -0
- package/dist/modules/billing/subscribers/payment-captured-to-paid.js.map +7 -0
- package/dist/modules/billing/translations.js +5 -0
- package/dist/modules/billing/translations.js.map +7 -0
- package/dist/modules/billing/workers/reap-stale-bill-runs.js +31 -0
- package/dist/modules/billing/workers/reap-stale-bill-runs.js.map +7 -0
- package/package.json +148 -0
- package/src/modules/billing/__integration__/TC-BILL-001.spec.ts +116 -0
- package/src/modules/billing/__integration__/TC-BILL-002.spec.ts +169 -0
- package/src/modules/billing/__integration__/TC-BILL-003.spec.ts +28 -0
- package/src/modules/billing/__integration__/meta.ts +4 -0
- package/src/modules/billing/__tests__/commands/invoices.test.ts +464 -0
- package/src/modules/billing/__tests__/commands/itemsBulk.test.ts +284 -0
- package/src/modules/billing/__tests__/lib/billPeriod.test.ts +131 -0
- package/src/modules/billing/__tests__/lib/billRunEngine.test.ts +561 -0
- package/src/modules/billing/__tests__/lib/idempotency.test.ts +81 -0
- package/src/modules/billing/__tests__/lib/invoiceStatus.test.ts +97 -0
- package/src/modules/billing/__tests__/lib/invoiceWriter.test.ts +119 -0
- package/src/modules/billing/__tests__/lib/itemSelector.test.ts +192 -0
- package/src/modules/billing/__tests__/lib/seedsDemo.test.ts +86 -0
- package/src/modules/billing/__tests__/lib/tenantLock.test.ts +126 -0
- package/src/modules/billing/__tests__/lib/usageRater.test.ts +190 -0
- package/src/modules/billing/__tests__/package-isolation.test.ts +223 -0
- package/src/modules/billing/__tests__/setup.test.ts +107 -0
- package/src/modules/billing/__tests__/validators.test.ts +594 -0
- package/src/modules/billing/acl.ts +16 -0
- package/src/modules/billing/api/accounts/route.ts +198 -0
- package/src/modules/billing/api/export/account/[id]/route.ts +233 -0
- package/src/modules/billing/api/invoices/[id]/route.ts +143 -0
- package/src/modules/billing/api/invoices/add-line/route.ts +74 -0
- package/src/modules/billing/api/invoices/edit-line/route.ts +97 -0
- package/src/modules/billing/api/invoices/post/route.ts +97 -0
- package/src/modules/billing/api/invoices/remove-line/route.ts +75 -0
- package/src/modules/billing/api/invoices/route.ts +167 -0
- package/src/modules/billing/api/items/bulk/route.ts +92 -0
- package/src/modules/billing/api/items/route.ts +255 -0
- package/src/modules/billing/api/openapi.ts +33 -0
- package/src/modules/billing/api/run-outcomes/route.ts +149 -0
- package/src/modules/billing/api/runs/retry-failed/route.ts +88 -0
- package/src/modules/billing/api/runs/route.ts +170 -0
- package/src/modules/billing/api/test-invoices/wipe/route.ts +87 -0
- package/src/modules/billing/api/usage/route.ts +148 -0
- package/src/modules/billing/backend/billing/accounts/[id]/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +574 -0
- package/src/modules/billing/backend/billing/accounts/create/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/accounts/create/page.tsx +101 -0
- package/src/modules/billing/backend/billing/accounts/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/accounts/page.tsx +222 -0
- package/src/modules/billing/backend/billing/invoices/[id]/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/invoices/[id]/page.tsx +613 -0
- package/src/modules/billing/backend/billing/invoices/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/invoices/page.tsx +245 -0
- package/src/modules/billing/backend/billing/items/[id]/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/items/[id]/page.tsx +366 -0
- package/src/modules/billing/backend/billing/items/create/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/items/create/page.tsx +110 -0
- package/src/modules/billing/backend/billing/items/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/items/page.tsx +272 -0
- package/src/modules/billing/backend/billing/runs/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/runs/[id]/page.tsx +404 -0
- package/src/modules/billing/backend/billing/runs/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/runs/page.tsx +426 -0
- package/src/modules/billing/backend/billing/usage/create/page.meta.ts +23 -0
- package/src/modules/billing/backend/billing/usage/create/page.tsx +120 -0
- package/src/modules/billing/ce.ts +74 -0
- package/src/modules/billing/cli.ts +89 -0
- package/src/modules/billing/commands/accounts.ts +205 -0
- package/src/modules/billing/commands/index.ts +13 -0
- package/src/modules/billing/commands/invoices.ts +542 -0
- package/src/modules/billing/commands/items.ts +438 -0
- package/src/modules/billing/commands/runs.ts +166 -0
- package/src/modules/billing/commands/usage.ts +118 -0
- package/src/modules/billing/components/AccountForm.tsx +517 -0
- package/src/modules/billing/components/DetailFields.tsx +60 -0
- package/src/modules/billing/components/ItemForm.tsx +558 -0
- package/src/modules/billing/components/LineFormDialog.tsx +253 -0
- package/src/modules/billing/components/UsageForm.tsx +326 -0
- package/src/modules/billing/data/entities.ts +533 -0
- package/src/modules/billing/data/entityIds.ts +25 -0
- package/src/modules/billing/data/validators.ts +562 -0
- package/src/modules/billing/di.ts +14 -0
- package/src/modules/billing/events.ts +47 -0
- package/src/modules/billing/i18n/en.json +336 -0
- package/src/modules/billing/i18n/pl.json +336 -0
- package/src/modules/billing/index.ts +22 -0
- package/src/modules/billing/lib/billPeriod.ts +181 -0
- package/src/modules/billing/lib/billRunEngine.ts +416 -0
- package/src/modules/billing/lib/billRunLabel.ts +14 -0
- package/src/modules/billing/lib/idempotency.ts +46 -0
- package/src/modules/billing/lib/invoiceStatus.ts +61 -0
- package/src/modules/billing/lib/invoiceWriter.ts +260 -0
- package/src/modules/billing/lib/itemSelector.ts +154 -0
- package/src/modules/billing/lib/seeds/demo.ts +199 -0
- package/src/modules/billing/lib/tenantLock.ts +87 -0
- package/src/modules/billing/lib/usageRater.ts +250 -0
- package/src/modules/billing/lib/usageRunner.ts +189 -0
- package/src/modules/billing/migrations/Migration20260519000000_billing.ts +175 -0
- package/src/modules/billing/setup.ts +252 -0
- package/src/modules/billing/subscribers/payment-captured-to-paid.ts +89 -0
- package/src/modules/billing/translations.ts +9 -0
- package/src/modules/billing/workers/reap-stale-bill-runs.ts +57 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { Pencil, Plus } from "lucide-react";
|
|
6
|
+
import { useParams, useRouter } from "next/navigation";
|
|
7
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
8
|
+
import { Page, PageBody, PageHeader } from "@open-mercato/ui/backend/Page";
|
|
9
|
+
import { FormHeader } from "@open-mercato/ui/backend/forms";
|
|
10
|
+
import { DataTable } from "@open-mercato/ui/backend/DataTable";
|
|
11
|
+
import { Tag } from "@open-mercato/ui/primitives/tag";
|
|
12
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
13
|
+
import { LoadingMessage, ErrorMessage } from "@open-mercato/ui/backend/detail";
|
|
14
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
15
|
+
import { useConfirmDialog } from "@open-mercato/ui/backend/confirm-dialog";
|
|
16
|
+
import {
|
|
17
|
+
apiCallOrThrow,
|
|
18
|
+
readApiResultOrThrow
|
|
19
|
+
} from "@open-mercato/ui/backend/utils/apiCall";
|
|
20
|
+
import { normalizeCrudServerError } from "@open-mercato/ui/backend/utils/serverErrors";
|
|
21
|
+
import { AccountForm } from "../../../../components/AccountForm.js";
|
|
22
|
+
import { DetailCard, DetailField } from "../../../../components/DetailFields.js";
|
|
23
|
+
function formatDate(value) {
|
|
24
|
+
if (!value) return "\u2014";
|
|
25
|
+
const parsed = new Date(value);
|
|
26
|
+
return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleDateString();
|
|
27
|
+
}
|
|
28
|
+
function toFormValues(row) {
|
|
29
|
+
return {
|
|
30
|
+
customerId: row.customer_id,
|
|
31
|
+
name: row.name,
|
|
32
|
+
currencyCode: row.currency_code,
|
|
33
|
+
billCycle: row.bill_cycle,
|
|
34
|
+
billCycleAnchor: row.bill_cycle_anchor,
|
|
35
|
+
invoiceEmail: row.invoice_email,
|
|
36
|
+
invoiceLanguage: row.invoice_language,
|
|
37
|
+
taxId: row.tax_id ?? "",
|
|
38
|
+
invoiceAddress: {
|
|
39
|
+
line1: row.invoice_address?.line1 ?? "",
|
|
40
|
+
line2: row.invoice_address?.line2 ?? "",
|
|
41
|
+
city: row.invoice_address?.city ?? "",
|
|
42
|
+
postal_code: row.invoice_address?.postal_code ?? "",
|
|
43
|
+
country: row.invoice_address?.country ?? ""
|
|
44
|
+
},
|
|
45
|
+
nextBillDate: row.next_bill_date?.slice(0, 10) ?? "",
|
|
46
|
+
isActive: row.is_active
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function AccountView({ row }) {
|
|
50
|
+
const t = useT();
|
|
51
|
+
const addr = row.invoice_address;
|
|
52
|
+
const addressText = addr ? [
|
|
53
|
+
addr.line1,
|
|
54
|
+
addr.line2,
|
|
55
|
+
[addr.postal_code, addr.city].filter(Boolean).join(" "),
|
|
56
|
+
addr.country
|
|
57
|
+
].map((part) => (part ?? "").trim()).filter(Boolean).join(", ") : "";
|
|
58
|
+
return /* @__PURE__ */ jsxs(DetailCard, { children: [
|
|
59
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.accounts.form.customer_id", "Customer ID"), children: /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.customer_id }) }),
|
|
60
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.accounts.columns.currency", "Currency"), children: row.currency_code }),
|
|
61
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.common.id", "ID"), children: /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.id }) }),
|
|
62
|
+
/* @__PURE__ */ jsxs(DetailField, { label: t("billing.accounts.columns.cycle", "Cycle"), children: [
|
|
63
|
+
row.bill_cycle,
|
|
64
|
+
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
|
|
65
|
+
" \xB7 ",
|
|
66
|
+
row.bill_cycle_anchor
|
|
67
|
+
] })
|
|
68
|
+
] }),
|
|
69
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.accounts.columns.next_bill", "Next bill"), children: formatDate(row.next_bill_date) }),
|
|
70
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.accounts.columns.last_bill", "Last bill"), children: formatDate(row.last_bill_date) }),
|
|
71
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.accounts.form.invoice_email", "Invoice email"), children: row.invoice_email }),
|
|
72
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.accounts.form.invoice_language", "Invoice language"), children: row.invoice_language }),
|
|
73
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.accounts.form.tax_id", "Tax ID"), children: row.tax_id || "\u2014" }),
|
|
74
|
+
/* @__PURE__ */ jsx(
|
|
75
|
+
DetailField,
|
|
76
|
+
{
|
|
77
|
+
label: t("billing.accounts.form.address.title", "Invoice address"),
|
|
78
|
+
fullWidth: true,
|
|
79
|
+
children: addressText || "\u2014"
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
] });
|
|
83
|
+
}
|
|
84
|
+
function AccountItemsSection({ accountId }) {
|
|
85
|
+
const t = useT();
|
|
86
|
+
const router = useRouter();
|
|
87
|
+
const [rows, setRows] = React.useState([]);
|
|
88
|
+
const [page, setPage] = React.useState(1);
|
|
89
|
+
const [total, setTotal] = React.useState(0);
|
|
90
|
+
const [totalPages, setTotalPages] = React.useState(1);
|
|
91
|
+
const [loading, setLoading] = React.useState(true);
|
|
92
|
+
const pageSize = 25;
|
|
93
|
+
const load = React.useCallback(async () => {
|
|
94
|
+
setLoading(true);
|
|
95
|
+
try {
|
|
96
|
+
const result = await readApiResultOrThrow(
|
|
97
|
+
`/api/billing/items?billAccountId=${accountId}&page=${page}&pageSize=${pageSize}&sortField=createdAt&sortDir=desc`
|
|
98
|
+
);
|
|
99
|
+
setRows(result.items ?? []);
|
|
100
|
+
setTotal(result.total ?? 0);
|
|
101
|
+
setTotalPages(result.totalPages ?? 1);
|
|
102
|
+
} finally {
|
|
103
|
+
setLoading(false);
|
|
104
|
+
}
|
|
105
|
+
}, [accountId, page]);
|
|
106
|
+
React.useEffect(() => {
|
|
107
|
+
void load();
|
|
108
|
+
}, [load]);
|
|
109
|
+
const columns = React.useMemo(
|
|
110
|
+
() => [
|
|
111
|
+
{
|
|
112
|
+
accessorKey: "description",
|
|
113
|
+
header: t("billing.items.columns.description", "Description"),
|
|
114
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-primary", children: row.original.description })
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
accessorKey: "type",
|
|
118
|
+
header: t("billing.items.columns.type", "Type"),
|
|
119
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Tag, { variant: "info", children: row.original.type })
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
accessorKey: "bill_start_date",
|
|
123
|
+
header: t("billing.items.columns.start", "Start"),
|
|
124
|
+
cell: ({ row }) => formatDate(row.original.bill_start_date)
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
accessorKey: "is_active",
|
|
128
|
+
header: t("billing.items.columns.status", "Status"),
|
|
129
|
+
cell: ({ row }) => row.original.is_active ? /* @__PURE__ */ jsx(Tag, { variant: "success", children: t("billing.common.active", "Active") }) : /* @__PURE__ */ jsx(Tag, { variant: "default", children: t("billing.common.inactive", "Inactive") })
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
[t]
|
|
133
|
+
);
|
|
134
|
+
return /* @__PURE__ */ jsx("div", { className: "mt-6", children: /* @__PURE__ */ jsx(
|
|
135
|
+
DataTable,
|
|
136
|
+
{
|
|
137
|
+
title: t("billing.accounts.detail.items.title", "Items"),
|
|
138
|
+
columns,
|
|
139
|
+
data: rows,
|
|
140
|
+
isLoading: loading,
|
|
141
|
+
onRowClick: (row) => router.push(`/backend/billing/items/${row.id}`),
|
|
142
|
+
pagination: { page, pageSize, total, totalPages, onPageChange: setPage },
|
|
143
|
+
emptyState: /* @__PURE__ */ jsx("div", { className: "rounded-lg border bg-card p-6 text-center text-sm text-muted-foreground", children: t("billing.accounts.detail.items.empty", "No items for this account yet.") })
|
|
144
|
+
}
|
|
145
|
+
) });
|
|
146
|
+
}
|
|
147
|
+
function AccountUsageSection({ accountId }) {
|
|
148
|
+
const t = useT();
|
|
149
|
+
const [rows, setRows] = React.useState([]);
|
|
150
|
+
const [page, setPage] = React.useState(1);
|
|
151
|
+
const [total, setTotal] = React.useState(0);
|
|
152
|
+
const [totalPages, setTotalPages] = React.useState(1);
|
|
153
|
+
const [loading, setLoading] = React.useState(true);
|
|
154
|
+
const pageSize = 25;
|
|
155
|
+
const load = React.useCallback(async () => {
|
|
156
|
+
setLoading(true);
|
|
157
|
+
try {
|
|
158
|
+
const result = await readApiResultOrThrow(
|
|
159
|
+
`/api/billing/usage?billAccountId=${accountId}&page=${page}&pageSize=${pageSize}&sortField=periodStart&sortDir=desc`
|
|
160
|
+
);
|
|
161
|
+
setRows(result.items ?? []);
|
|
162
|
+
setTotal(result.total ?? 0);
|
|
163
|
+
setTotalPages(result.totalPages ?? 1);
|
|
164
|
+
} finally {
|
|
165
|
+
setLoading(false);
|
|
166
|
+
}
|
|
167
|
+
}, [accountId, page]);
|
|
168
|
+
React.useEffect(() => {
|
|
169
|
+
void load();
|
|
170
|
+
}, [load]);
|
|
171
|
+
const columns = React.useMemo(
|
|
172
|
+
() => [
|
|
173
|
+
{
|
|
174
|
+
accessorKey: "uom_code",
|
|
175
|
+
header: t("billing.usage.columns.uom", "Unit"),
|
|
176
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.original.uom_code })
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
accessorKey: "quantity",
|
|
180
|
+
header: t("billing.usage.columns.quantity", "Quantity"),
|
|
181
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "font-mono tabular-nums", children: row.original.quantity })
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
accessorKey: "period_start",
|
|
185
|
+
header: t("billing.usage.columns.period", "Period"),
|
|
186
|
+
cell: ({ row }) => `${formatDate(row.original.period_start)} \u2013 ${formatDate(row.original.period_end)}`
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
accessorKey: "line_description",
|
|
190
|
+
header: t("billing.usage.columns.description", "Description"),
|
|
191
|
+
cell: ({ row }) => row.original.line_description || "\u2014"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
accessorKey: "rated_in_bill_run_id",
|
|
195
|
+
header: t("billing.usage.columns.rated", "Rated"),
|
|
196
|
+
cell: ({ row }) => row.original.rated_in_bill_run_id ? (
|
|
197
|
+
// Rated records carry the Bill Run that priced them — link to it.
|
|
198
|
+
// Unrated records have no destination, so they stay non-interactive
|
|
199
|
+
// (no misleading row-level click affordance).
|
|
200
|
+
/* @__PURE__ */ jsx(
|
|
201
|
+
Link,
|
|
202
|
+
{
|
|
203
|
+
href: `/backend/billing/runs/${row.original.rated_in_bill_run_id}`,
|
|
204
|
+
className: "rounded-sm hover:underline",
|
|
205
|
+
children: /* @__PURE__ */ jsx(Tag, { variant: "success", children: t("billing.usage.rated.yes", "Rated") })
|
|
206
|
+
}
|
|
207
|
+
)
|
|
208
|
+
) : /* @__PURE__ */ jsx(Tag, { variant: "default", children: t("billing.usage.rated.no", "Unrated") })
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
[t]
|
|
212
|
+
);
|
|
213
|
+
return /* @__PURE__ */ jsx("div", { className: "mt-6", children: /* @__PURE__ */ jsx(
|
|
214
|
+
DataTable,
|
|
215
|
+
{
|
|
216
|
+
title: t("billing.accounts.detail.usage.title", "Usage"),
|
|
217
|
+
columns,
|
|
218
|
+
data: rows,
|
|
219
|
+
isLoading: loading,
|
|
220
|
+
pagination: { page, pageSize, total, totalPages, onPageChange: setPage },
|
|
221
|
+
emptyState: /* @__PURE__ */ jsx("div", { className: "rounded-lg border bg-card p-6 text-center text-sm text-muted-foreground", children: t("billing.accounts.detail.usage.empty", "No usage records for this account yet.") })
|
|
222
|
+
}
|
|
223
|
+
) });
|
|
224
|
+
}
|
|
225
|
+
function BillingAccountDetailPage(props) {
|
|
226
|
+
const t = useT();
|
|
227
|
+
const router = useRouter();
|
|
228
|
+
const urlParams = useParams();
|
|
229
|
+
const accountId = props.params?.id ?? urlParams?.id ?? "";
|
|
230
|
+
const [row, setRow] = React.useState(null);
|
|
231
|
+
const [loading, setLoading] = React.useState(true);
|
|
232
|
+
const [error, setError] = React.useState(null);
|
|
233
|
+
const [editing, setEditing] = React.useState(false);
|
|
234
|
+
const [saving, setSaving] = React.useState(false);
|
|
235
|
+
const [deleting, setDeleting] = React.useState(false);
|
|
236
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog();
|
|
237
|
+
const load = React.useCallback(async () => {
|
|
238
|
+
if (!accountId) return;
|
|
239
|
+
setLoading(true);
|
|
240
|
+
setError(null);
|
|
241
|
+
try {
|
|
242
|
+
const result = await readApiResultOrThrow(
|
|
243
|
+
`/api/billing/accounts?id=${accountId}&pageSize=1`
|
|
244
|
+
);
|
|
245
|
+
const found = result.items?.[0];
|
|
246
|
+
if (!found) {
|
|
247
|
+
setError(t("billing.accounts.detail.error.not_found", "Account not found"));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
setRow(found);
|
|
251
|
+
} catch (err) {
|
|
252
|
+
const { message } = normalizeCrudServerError(err);
|
|
253
|
+
setError(message || t("billing.accounts.detail.error.load", "Failed to load account"));
|
|
254
|
+
} finally {
|
|
255
|
+
setLoading(false);
|
|
256
|
+
}
|
|
257
|
+
}, [accountId, t]);
|
|
258
|
+
React.useEffect(() => {
|
|
259
|
+
void load();
|
|
260
|
+
}, [load]);
|
|
261
|
+
const handleSubmit = React.useCallback(
|
|
262
|
+
async (values) => {
|
|
263
|
+
if (!row) return;
|
|
264
|
+
setSaving(true);
|
|
265
|
+
try {
|
|
266
|
+
const payload = {
|
|
267
|
+
id: row.id,
|
|
268
|
+
name: values.name.trim(),
|
|
269
|
+
billCycle: values.billCycle,
|
|
270
|
+
billCycleAnchor: values.billCycleAnchor.trim(),
|
|
271
|
+
invoiceEmail: values.invoiceEmail.trim(),
|
|
272
|
+
invoiceLanguage: values.invoiceLanguage.trim().toLowerCase(),
|
|
273
|
+
invoiceAddress: {
|
|
274
|
+
line1: values.invoiceAddress.line1.trim(),
|
|
275
|
+
...values.invoiceAddress.line2.trim() ? { line2: values.invoiceAddress.line2.trim() } : {},
|
|
276
|
+
city: values.invoiceAddress.city.trim(),
|
|
277
|
+
postal_code: values.invoiceAddress.postal_code.trim(),
|
|
278
|
+
country: values.invoiceAddress.country.trim().toUpperCase()
|
|
279
|
+
},
|
|
280
|
+
nextBillDate: values.nextBillDate,
|
|
281
|
+
isActive: values.isActive
|
|
282
|
+
};
|
|
283
|
+
payload.taxId = values.taxId.trim() === "" ? null : values.taxId.trim();
|
|
284
|
+
await apiCallOrThrow("/api/billing/accounts", {
|
|
285
|
+
method: "PUT",
|
|
286
|
+
headers: { "Content-Type": "application/json" },
|
|
287
|
+
body: JSON.stringify(payload)
|
|
288
|
+
});
|
|
289
|
+
flash(t("billing.accounts.detail.save.success", "Account updated"), "success");
|
|
290
|
+
setEditing(false);
|
|
291
|
+
void load();
|
|
292
|
+
} catch (err) {
|
|
293
|
+
const { message, fieldErrors } = normalizeCrudServerError(err);
|
|
294
|
+
const fieldDetail = fieldErrors && Object.keys(fieldErrors).length ? Object.entries(fieldErrors).map(([field, msg]) => `${field}: ${msg}`).join("; ") : null;
|
|
295
|
+
const detailed = fieldDetail && message ? `${message} \u2014 ${fieldDetail}` : fieldDetail || message;
|
|
296
|
+
flash(detailed || t("billing.accounts.detail.save.error", "Save failed"), "error");
|
|
297
|
+
} finally {
|
|
298
|
+
setSaving(false);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
[load, row, t]
|
|
302
|
+
);
|
|
303
|
+
const handleDelete = React.useCallback(async () => {
|
|
304
|
+
if (!row) return;
|
|
305
|
+
const ok = await confirm({
|
|
306
|
+
title: t("billing.accounts.detail.delete.confirm.title", "Delete account?"),
|
|
307
|
+
text: t(
|
|
308
|
+
"billing.accounts.detail.delete.confirm.text",
|
|
309
|
+
"Soft-deletes the account. Its items + usage records stay in the database for audit; the Bill Run engine will stop picking it up immediately."
|
|
310
|
+
),
|
|
311
|
+
confirmText: t("billing.accounts.detail.delete.confirm.button", "Soft delete"),
|
|
312
|
+
variant: "destructive"
|
|
313
|
+
});
|
|
314
|
+
if (!ok) return;
|
|
315
|
+
setDeleting(true);
|
|
316
|
+
try {
|
|
317
|
+
await apiCallOrThrow("/api/billing/accounts", {
|
|
318
|
+
method: "DELETE",
|
|
319
|
+
headers: { "Content-Type": "application/json" },
|
|
320
|
+
body: JSON.stringify({ id: row.id })
|
|
321
|
+
});
|
|
322
|
+
flash(t("billing.accounts.detail.delete.success", "Account deleted"), "success");
|
|
323
|
+
router.push("/backend/billing/accounts");
|
|
324
|
+
} catch (err) {
|
|
325
|
+
const { message } = normalizeCrudServerError(err);
|
|
326
|
+
flash(message || t("billing.accounts.detail.delete.error", "Delete failed"), "error");
|
|
327
|
+
setDeleting(false);
|
|
328
|
+
}
|
|
329
|
+
}, [confirm, router, row, t]);
|
|
330
|
+
if (error) {
|
|
331
|
+
return /* @__PURE__ */ jsxs(Page, { children: [
|
|
332
|
+
/* @__PURE__ */ jsx(PageHeader, { title: t("billing.accounts.detail.title", "Billing Account") }),
|
|
333
|
+
/* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(ErrorMessage, { label: error }) })
|
|
334
|
+
] });
|
|
335
|
+
}
|
|
336
|
+
if (loading || !row) {
|
|
337
|
+
return /* @__PURE__ */ jsxs(Page, { children: [
|
|
338
|
+
/* @__PURE__ */ jsx(PageHeader, { title: t("billing.accounts.detail.title", "Billing Account") }),
|
|
339
|
+
/* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
|
|
340
|
+
LoadingMessage,
|
|
341
|
+
{
|
|
342
|
+
label: t("billing.accounts.detail.loading", "Loading account\u2026")
|
|
343
|
+
}
|
|
344
|
+
) })
|
|
345
|
+
] });
|
|
346
|
+
}
|
|
347
|
+
return /* @__PURE__ */ jsxs(Page, { children: [
|
|
348
|
+
/* @__PURE__ */ jsx(
|
|
349
|
+
FormHeader,
|
|
350
|
+
{
|
|
351
|
+
mode: "detail",
|
|
352
|
+
backHref: "/backend/billing/accounts",
|
|
353
|
+
entityTypeLabel: t("billing.accounts.detail.title", "Billing Account"),
|
|
354
|
+
title: row.name,
|
|
355
|
+
statusBadge: row.is_active ? /* @__PURE__ */ jsx(Tag, { variant: "success", children: t("billing.common.active", "Active") }) : /* @__PURE__ */ jsx(Tag, { variant: "default", children: t("billing.common.inactive", "Inactive") }),
|
|
356
|
+
actionsContent: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
357
|
+
/* @__PURE__ */ jsx(Button, { asChild: true, variant: "outline", children: /* @__PURE__ */ jsxs(Link, { href: `/backend/billing/items/create?billAccountId=${row.id}`, children: [
|
|
358
|
+
/* @__PURE__ */ jsx(Plus, { size: 16 }),
|
|
359
|
+
t("billing.accounts.detail.add_item", "Add item")
|
|
360
|
+
] }) }),
|
|
361
|
+
/* @__PURE__ */ jsx(Button, { asChild: true, variant: "outline", children: /* @__PURE__ */ jsxs(Link, { href: `/backend/billing/usage/create?billAccountId=${row.id}`, children: [
|
|
362
|
+
/* @__PURE__ */ jsx(Plus, { size: 16 }),
|
|
363
|
+
t("billing.accounts.detail.add_usage", "Add usage")
|
|
364
|
+
] }) }),
|
|
365
|
+
!editing ? /* @__PURE__ */ jsxs(Button, { type: "button", onClick: () => setEditing(true), children: [
|
|
366
|
+
/* @__PURE__ */ jsx(Pencil, { size: 16 }),
|
|
367
|
+
t("billing.common.edit", "Edit")
|
|
368
|
+
] }) : null,
|
|
369
|
+
/* @__PURE__ */ jsx(
|
|
370
|
+
Button,
|
|
371
|
+
{
|
|
372
|
+
type: "button",
|
|
373
|
+
variant: "outline",
|
|
374
|
+
onClick: handleDelete,
|
|
375
|
+
disabled: deleting,
|
|
376
|
+
children: deleting ? t("billing.accounts.detail.delete.in_progress", "Deleting\u2026") : t("billing.accounts.detail.delete.action", "Soft delete")
|
|
377
|
+
}
|
|
378
|
+
)
|
|
379
|
+
] })
|
|
380
|
+
}
|
|
381
|
+
),
|
|
382
|
+
/* @__PURE__ */ jsxs(PageBody, { children: [
|
|
383
|
+
editing ? /* @__PURE__ */ jsx(
|
|
384
|
+
AccountForm,
|
|
385
|
+
{
|
|
386
|
+
mode: "edit",
|
|
387
|
+
initial: toFormValues(row),
|
|
388
|
+
submitting: saving,
|
|
389
|
+
onSubmit: handleSubmit,
|
|
390
|
+
onCancel: () => setEditing(false)
|
|
391
|
+
}
|
|
392
|
+
) : /* @__PURE__ */ jsx(AccountView, { row }),
|
|
393
|
+
/* @__PURE__ */ jsx(AccountItemsSection, { accountId: row.id }),
|
|
394
|
+
/* @__PURE__ */ jsx(AccountUsageSection, { accountId: row.id }),
|
|
395
|
+
ConfirmDialogElement
|
|
396
|
+
] })
|
|
397
|
+
] });
|
|
398
|
+
}
|
|
399
|
+
export {
|
|
400
|
+
BillingAccountDetailPage as default
|
|
401
|
+
};
|
|
402
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/billing/backend/billing/accounts/%5Bid%5D/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { Pencil, Plus } from 'lucide-react'\nimport { useParams, useRouter } from 'next/navigation'\nimport type { ColumnDef } from '@tanstack/react-table'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody, PageHeader } from '@open-mercato/ui/backend/Page'\nimport { FormHeader } from '@open-mercato/ui/backend/forms'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport {\n apiCallOrThrow,\n readApiResultOrThrow,\n} from '@open-mercato/ui/backend/utils/apiCall'\nimport { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { AccountForm, type AccountFormValues } from '../../../../components/AccountForm'\nimport { DetailCard, DetailField } from '../../../../components/DetailFields'\n\n/**\n * `/backend/billing/accounts/[id]` \u2014 Billing Account detail.\n *\n * Opens read-only (field grid + the account's items). The `Edit`\n * button swaps the grid for the `AccountForm`; Save / Cancel return\n * to the read-only view. Loads via `GET /api/billing/accounts?id=<id>`,\n * edits through `PUT`, soft-delete through `DELETE`.\n *\n * `customerId` + `currencyCode` are immutable on update \u2014 the form\n * disables both in `mode='edit'` and the schema rejects them per\n * `billingAccountUpdateSchema`.\n */\n\n// API list rows are snake_case (see `api/accounts/route.ts` `fields`).\ntype AccountRow = {\n id: string\n customer_id: string\n name: string\n currency_code: string\n bill_cycle: 'weekly' | 'monthly' | 'quarterly' | 'annually'\n bill_cycle_anchor: string\n invoice_email: string\n invoice_language: string\n tax_id: string | null\n invoice_address: {\n line1?: string\n line2?: string\n city?: string\n postal_code?: string\n country?: string\n } | null\n next_bill_date: string\n last_bill_date: string | null\n is_active: boolean\n created_at: string\n updated_at: string\n}\n\ntype ListResponse = { items: AccountRow[] }\n\n// Minimal item shape for the embedded \"Items\" table.\ntype AccountItemRow = {\n id: string\n description: string\n type: 'one_time' | 'recurring' | 'usage'\n bill_start_date: string\n is_active: boolean\n}\n\n// Minimal usage shape for the embedded \"Usage\" table. Mirrors the\n// snake_case `fields` projection in `api/usage/route.ts`. Usage is\n// append-only \u2014 `rated_in_bill_run_id` is null until a Bill Run rates it.\ntype AccountUsageRow = {\n id: string\n uom_code: string\n quantity: string\n period_start: string\n period_end: string\n line_description: string | null\n rated_in_bill_run_id: string | null\n}\n\nfunction formatDate(value: string | null | undefined): string {\n if (!value) return '\u2014'\n const parsed = new Date(value)\n return Number.isNaN(parsed.getTime()) ? value : parsed.toLocaleDateString()\n}\n\nfunction toFormValues(row: AccountRow): AccountFormValues {\n return {\n customerId: row.customer_id,\n name: row.name,\n currencyCode: row.currency_code,\n billCycle: row.bill_cycle,\n billCycleAnchor: row.bill_cycle_anchor,\n invoiceEmail: row.invoice_email,\n invoiceLanguage: row.invoice_language,\n taxId: row.tax_id ?? '',\n invoiceAddress: {\n line1: row.invoice_address?.line1 ?? '',\n line2: row.invoice_address?.line2 ?? '',\n city: row.invoice_address?.city ?? '',\n postal_code: row.invoice_address?.postal_code ?? '',\n country: row.invoice_address?.country ?? '',\n },\n nextBillDate: row.next_bill_date?.slice(0, 10) ?? '',\n isActive: row.is_active,\n }\n}\n\n// \u2500\u2500\u2500 Read-only view \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction AccountView({ row }: { row: AccountRow }) {\n const t = useT()\n const addr = row.invoice_address\n const addressText = addr\n ? [\n addr.line1,\n addr.line2,\n [addr.postal_code, addr.city].filter(Boolean).join(' '),\n addr.country,\n ]\n .map((part) => (part ?? '').trim())\n .filter(Boolean)\n .join(', ')\n : ''\n return (\n <DetailCard>\n <DetailField label={t('billing.accounts.form.customer_id', 'Customer ID')}>\n <span className=\"font-mono text-xs\">{row.customer_id}</span>\n </DetailField>\n <DetailField label={t('billing.accounts.columns.currency', 'Currency')}>\n {row.currency_code}\n </DetailField>\n <DetailField label={t('billing.common.id', 'ID')}>\n <span className=\"font-mono text-xs\">{row.id}</span>\n </DetailField>\n <DetailField label={t('billing.accounts.columns.cycle', 'Cycle')}>\n {row.bill_cycle}\n <span className=\"text-muted-foreground\"> \u00B7 {row.bill_cycle_anchor}</span>\n </DetailField>\n <DetailField label={t('billing.accounts.columns.next_bill', 'Next bill')}>\n {formatDate(row.next_bill_date)}\n </DetailField>\n <DetailField label={t('billing.accounts.columns.last_bill', 'Last bill')}>\n {formatDate(row.last_bill_date)}\n </DetailField>\n <DetailField label={t('billing.accounts.form.invoice_email', 'Invoice email')}>\n {row.invoice_email}\n </DetailField>\n <DetailField label={t('billing.accounts.form.invoice_language', 'Invoice language')}>\n {row.invoice_language}\n </DetailField>\n <DetailField label={t('billing.accounts.form.tax_id', 'Tax ID')}>\n {row.tax_id || '\u2014'}\n </DetailField>\n <DetailField\n label={t('billing.accounts.form.address.title', 'Invoice address')}\n fullWidth\n >\n {addressText || '\u2014'}\n </DetailField>\n </DetailCard>\n )\n}\n\n// \u2500\u2500\u2500 Embedded items table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction AccountItemsSection({ accountId }: { accountId: string }) {\n const t = useT()\n const router = useRouter()\n const [rows, setRows] = React.useState<AccountItemRow[]>([])\n const [page, setPage] = React.useState(1)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [loading, setLoading] = React.useState(true)\n const pageSize = 25\n\n const load = React.useCallback(async () => {\n setLoading(true)\n try {\n const result = await readApiResultOrThrow<{\n items: AccountItemRow[]\n total: number\n totalPages: number\n }>(\n `/api/billing/items?billAccountId=${accountId}&page=${page}` +\n `&pageSize=${pageSize}&sortField=createdAt&sortDir=desc`,\n )\n setRows(result.items ?? [])\n setTotal(result.total ?? 0)\n setTotalPages(result.totalPages ?? 1)\n } finally {\n setLoading(false)\n }\n }, [accountId, page])\n\n React.useEffect(() => {\n void load()\n }, [load])\n\n const columns = React.useMemo<ColumnDef<AccountItemRow>[]>(\n () => [\n {\n accessorKey: 'description',\n header: t('billing.items.columns.description', 'Description'),\n cell: ({ row }) => (\n <span className=\"text-sm font-medium text-primary\">\n {row.original.description}\n </span>\n ),\n },\n {\n accessorKey: 'type',\n header: t('billing.items.columns.type', 'Type'),\n cell: ({ row }) => <Tag variant=\"info\">{row.original.type}</Tag>,\n },\n {\n accessorKey: 'bill_start_date',\n header: t('billing.items.columns.start', 'Start'),\n cell: ({ row }) => formatDate(row.original.bill_start_date),\n },\n {\n accessorKey: 'is_active',\n header: t('billing.items.columns.status', 'Status'),\n cell: ({ row }) =>\n row.original.is_active ? (\n <Tag variant=\"success\">{t('billing.common.active', 'Active')}</Tag>\n ) : (\n <Tag variant=\"default\">{t('billing.common.inactive', 'Inactive')}</Tag>\n ),\n },\n ],\n [t],\n )\n\n return (\n <div className=\"mt-6\">\n <DataTable\n title={t('billing.accounts.detail.items.title', 'Items')}\n columns={columns}\n data={rows}\n isLoading={loading}\n onRowClick={(row) => router.push(`/backend/billing/items/${row.id}`)}\n pagination={{ page, pageSize, total, totalPages, onPageChange: setPage }}\n emptyState={\n <div className=\"rounded-lg border bg-card p-6 text-center text-sm text-muted-foreground\">\n {t('billing.accounts.detail.items.empty', 'No items for this account yet.')}\n </div>\n }\n />\n </div>\n )\n}\n\n// \u2500\u2500\u2500 Embedded usage table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction AccountUsageSection({ accountId }: { accountId: string }) {\n const t = useT()\n const [rows, setRows] = React.useState<AccountUsageRow[]>([])\n const [page, setPage] = React.useState(1)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [loading, setLoading] = React.useState(true)\n const pageSize = 25\n\n const load = React.useCallback(async () => {\n setLoading(true)\n try {\n const result = await readApiResultOrThrow<{\n items: AccountUsageRow[]\n total: number\n totalPages: number\n }>(\n `/api/billing/usage?billAccountId=${accountId}&page=${page}` +\n `&pageSize=${pageSize}&sortField=periodStart&sortDir=desc`,\n )\n setRows(result.items ?? [])\n setTotal(result.total ?? 0)\n setTotalPages(result.totalPages ?? 1)\n } finally {\n setLoading(false)\n }\n }, [accountId, page])\n\n React.useEffect(() => {\n void load()\n }, [load])\n\n const columns = React.useMemo<ColumnDef<AccountUsageRow>[]>(\n () => [\n {\n accessorKey: 'uom_code',\n header: t('billing.usage.columns.uom', 'Unit'),\n cell: ({ row }) => (\n <span className=\"font-mono text-xs\">{row.original.uom_code}</span>\n ),\n },\n {\n accessorKey: 'quantity',\n header: t('billing.usage.columns.quantity', 'Quantity'),\n cell: ({ row }) => (\n <span className=\"font-mono tabular-nums\">{row.original.quantity}</span>\n ),\n },\n {\n accessorKey: 'period_start',\n header: t('billing.usage.columns.period', 'Period'),\n cell: ({ row }) =>\n `${formatDate(row.original.period_start)} \u2013 ${formatDate(row.original.period_end)}`,\n },\n {\n accessorKey: 'line_description',\n header: t('billing.usage.columns.description', 'Description'),\n cell: ({ row }) => row.original.line_description || '\u2014',\n },\n {\n accessorKey: 'rated_in_bill_run_id',\n header: t('billing.usage.columns.rated', 'Rated'),\n cell: ({ row }) =>\n row.original.rated_in_bill_run_id ? (\n // Rated records carry the Bill Run that priced them \u2014 link to it.\n // Unrated records have no destination, so they stay non-interactive\n // (no misleading row-level click affordance).\n <Link\n href={`/backend/billing/runs/${row.original.rated_in_bill_run_id}`}\n className=\"rounded-sm hover:underline\"\n >\n <Tag variant=\"success\">{t('billing.usage.rated.yes', 'Rated')}</Tag>\n </Link>\n ) : (\n <Tag variant=\"default\">{t('billing.usage.rated.no', 'Unrated')}</Tag>\n ),\n },\n ],\n [t],\n )\n\n return (\n <div className=\"mt-6\">\n <DataTable\n title={t('billing.accounts.detail.usage.title', 'Usage')}\n columns={columns}\n data={rows}\n isLoading={loading}\n pagination={{ page, pageSize, total, totalPages, onPageChange: setPage }}\n emptyState={\n <div className=\"rounded-lg border bg-card p-6 text-center text-sm text-muted-foreground\">\n {t('billing.accounts.detail.usage.empty', 'No usage records for this account yet.')}\n </div>\n }\n />\n </div>\n )\n}\n\nexport default function BillingAccountDetailPage(props: { params?: { id?: string } }) {\n const t = useT()\n const router = useRouter()\n // OM serves backend pages through a catch-all route \u2014 the dynamic\n // `[id]` segment arrives as a page prop; `useParams()` is the fallback.\n const urlParams = useParams<{ id: string }>()\n const accountId = (props.params?.id ?? urlParams?.id ?? '') as string\n\n const [row, setRow] = React.useState<AccountRow | null>(null)\n const [loading, setLoading] = React.useState(true)\n const [error, setError] = React.useState<string | null>(null)\n const [editing, setEditing] = React.useState(false)\n const [saving, setSaving] = React.useState(false)\n const [deleting, setDeleting] = React.useState(false)\n\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n\n const load = React.useCallback(async () => {\n if (!accountId) return\n setLoading(true)\n setError(null)\n try {\n const result = await readApiResultOrThrow<ListResponse>(\n `/api/billing/accounts?id=${accountId}&pageSize=1`,\n )\n const found = result.items?.[0]\n if (!found) {\n setError(t('billing.accounts.detail.error.not_found', 'Account not found'))\n return\n }\n setRow(found)\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n setError(message || t('billing.accounts.detail.error.load', 'Failed to load account'))\n } finally {\n setLoading(false)\n }\n }, [accountId, t])\n\n React.useEffect(() => {\n void load()\n }, [load])\n\n const handleSubmit = React.useCallback(\n async (values: AccountFormValues) => {\n if (!row) return\n setSaving(true)\n try {\n const payload: Record<string, unknown> = {\n id: row.id,\n name: values.name.trim(),\n billCycle: values.billCycle,\n billCycleAnchor: values.billCycleAnchor.trim(),\n invoiceEmail: values.invoiceEmail.trim(),\n invoiceLanguage: values.invoiceLanguage.trim().toLowerCase(),\n invoiceAddress: {\n line1: values.invoiceAddress.line1.trim(),\n ...(values.invoiceAddress.line2.trim()\n ? { line2: values.invoiceAddress.line2.trim() }\n : {}),\n city: values.invoiceAddress.city.trim(),\n postal_code: values.invoiceAddress.postal_code.trim(),\n country: values.invoiceAddress.country.trim().toUpperCase(),\n },\n nextBillDate: values.nextBillDate,\n isActive: values.isActive,\n }\n payload.taxId = values.taxId.trim() === '' ? null : values.taxId.trim()\n\n await apiCallOrThrow('/api/billing/accounts', {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(payload),\n })\n flash(t('billing.accounts.detail.save.success', 'Account updated'), 'success')\n setEditing(false)\n void load()\n } catch (err) {\n const { message, fieldErrors } = normalizeCrudServerError(err)\n const fieldDetail =\n fieldErrors && Object.keys(fieldErrors).length\n ? Object.entries(fieldErrors)\n .map(([field, msg]) => `${field}: ${msg}`)\n .join('; ')\n : null\n const detailed =\n fieldDetail && message\n ? `${message} \u2014 ${fieldDetail}`\n : fieldDetail || message\n flash(detailed || t('billing.accounts.detail.save.error', 'Save failed'), 'error')\n } finally {\n setSaving(false)\n }\n },\n [load, row, t],\n )\n\n const handleDelete = React.useCallback(async () => {\n if (!row) return\n const ok = await confirm({\n title: t('billing.accounts.detail.delete.confirm.title', 'Delete account?'),\n text: t(\n 'billing.accounts.detail.delete.confirm.text',\n \"Soft-deletes the account. Its items + usage records stay in the database for audit; the Bill Run engine will stop picking it up immediately.\",\n ),\n confirmText: t('billing.accounts.detail.delete.confirm.button', 'Soft delete'),\n variant: 'destructive',\n })\n if (!ok) return\n setDeleting(true)\n try {\n await apiCallOrThrow('/api/billing/accounts', {\n method: 'DELETE',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ id: row.id }),\n })\n flash(t('billing.accounts.detail.delete.success', 'Account deleted'), 'success')\n router.push('/backend/billing/accounts')\n } catch (err) {\n const { message } = normalizeCrudServerError(err)\n flash(message || t('billing.accounts.detail.delete.error', 'Delete failed'), 'error')\n setDeleting(false)\n }\n }, [confirm, router, row, t])\n\n if (error) {\n return (\n <Page>\n <PageHeader title={t('billing.accounts.detail.title', 'Billing Account')} />\n <PageBody>\n <ErrorMessage label={error} />\n </PageBody>\n </Page>\n )\n }\n\n if (loading || !row) {\n return (\n <Page>\n <PageHeader title={t('billing.accounts.detail.title', 'Billing Account')} />\n <PageBody>\n <LoadingMessage\n label={t('billing.accounts.detail.loading', 'Loading account\u2026')}\n />\n </PageBody>\n </Page>\n )\n }\n\n return (\n <Page>\n <FormHeader\n mode=\"detail\"\n backHref=\"/backend/billing/accounts\"\n entityTypeLabel={t('billing.accounts.detail.title', 'Billing Account')}\n title={row.name}\n statusBadge={\n row.is_active ? (\n <Tag variant=\"success\">{t('billing.common.active', 'Active')}</Tag>\n ) : (\n <Tag variant=\"default\">{t('billing.common.inactive', 'Inactive')}</Tag>\n )\n }\n actionsContent={\n <>\n <Button asChild variant=\"outline\">\n <Link href={`/backend/billing/items/create?billAccountId=${row.id}`}>\n <Plus size={16} />\n {t('billing.accounts.detail.add_item', 'Add item')}\n </Link>\n </Button>\n <Button asChild variant=\"outline\">\n <Link href={`/backend/billing/usage/create?billAccountId=${row.id}`}>\n <Plus size={16} />\n {t('billing.accounts.detail.add_usage', 'Add usage')}\n </Link>\n </Button>\n {!editing ? (\n <Button type=\"button\" onClick={() => setEditing(true)}>\n <Pencil size={16} />\n {t('billing.common.edit', 'Edit')}\n </Button>\n ) : null}\n <Button\n type=\"button\"\n variant=\"outline\"\n onClick={handleDelete}\n disabled={deleting}\n >\n {deleting\n ? t('billing.accounts.detail.delete.in_progress', 'Deleting\u2026')\n : t('billing.accounts.detail.delete.action', 'Soft delete')}\n </Button>\n </>\n }\n />\n <PageBody>\n {editing ? (\n <AccountForm\n mode=\"edit\"\n initial={toFormValues(row)}\n submitting={saving}\n onSubmit={handleSubmit}\n onCancel={() => setEditing(false)}\n />\n ) : (\n <AccountView row={row} />\n )}\n <AccountItemsSection accountId={row.id} />\n <AccountUsageSection accountId={row.id} />\n {ConfirmDialogElement}\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAoIQ,SAuYE,UAvYF,KAUA,YAVA;AAnIR,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,QAAQ,YAAY;AAC7B,SAAS,WAAW,iBAAiB;AAErC,SAAS,YAAY;AACrB,SAAS,MAAM,UAAU,kBAAkB;AAC3C,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,mBAA2C;AACpD,SAAS,YAAY,mBAAmB;AAgExC,SAAS,WAAW,OAA0C;AAC5D,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,SAAS,IAAI,KAAK,KAAK;AAC7B,SAAO,OAAO,MAAM,OAAO,QAAQ,CAAC,IAAI,QAAQ,OAAO,mBAAmB;AAC5E;AAEA,SAAS,aAAa,KAAoC;AACxD,SAAO;AAAA,IACL,YAAY,IAAI;AAAA,IAChB,MAAM,IAA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C,oBAAC,uBAAoB,WAAW,IAAI,IAAI;AAAA,MACvC;AAAA,OACH;AAAA,KACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Building2 } from "lucide-react";
|
|
3
|
+
const accountIcon = React.createElement(Building2, { size: 16 });
|
|
4
|
+
const metadata = {
|
|
5
|
+
requireAuth: true,
|
|
6
|
+
requireFeatures: ["billing.account.view"],
|
|
7
|
+
pageTitle: "Billing Account",
|
|
8
|
+
pageTitleKey: "billing.accounts.detail.title",
|
|
9
|
+
pageGroup: "Billing",
|
|
10
|
+
pageGroupKey: "billing.nav.group",
|
|
11
|
+
navHidden: true,
|
|
12
|
+
icon: accountIcon,
|
|
13
|
+
breadcrumb: [
|
|
14
|
+
{
|
|
15
|
+
label: "Billing Accounts",
|
|
16
|
+
labelKey: "billing.accounts.title",
|
|
17
|
+
href: "/backend/billing/accounts"
|
|
18
|
+
},
|
|
19
|
+
{ label: "Account", labelKey: "billing.accounts.detail.title" }
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
metadata
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=page.meta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/billing/backend/billing/accounts/%5Bid%5D/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { Building2 } from 'lucide-react'\n\nconst accountIcon = React.createElement(Building2, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.account.view'],\n pageTitle: 'Billing Account',\n pageTitleKey: 'billing.accounts.detail.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n navHidden: true,\n icon: accountIcon,\n breadcrumb: [\n {\n label: 'Billing Accounts',\n labelKey: 'billing.accounts.title',\n href: '/backend/billing/accounts',\n },\n { label: 'Account', labelKey: 'billing.accounts.detail.title' },\n ],\n} as const\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,iBAAiB;AAE1B,MAAM,cAAc,MAAM,cAAc,WAAW,EAAE,MAAM,GAAG,CAAC;AAExD,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,sBAAsB;AAAA,EACxC,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY;AAAA,IACV;AAAA,MACE,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,IACR;AAAA,IACA,EAAE,OAAO,WAAW,UAAU,gCAAgC;AAAA,EAChE;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useRouter } from "next/navigation";
|
|
5
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
|
+
import { Page, PageBody, PageHeader } from "@open-mercato/ui/backend/Page";
|
|
7
|
+
import { flash } from "@open-mercato/ui/backend/FlashMessages";
|
|
8
|
+
import { apiCallOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
9
|
+
import { normalizeCrudServerError } from "@open-mercato/ui/backend/utils/serverErrors";
|
|
10
|
+
import { AccountForm } from "../../../../components/AccountForm.js";
|
|
11
|
+
function CreateBillingAccountPage() {
|
|
12
|
+
const t = useT();
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
15
|
+
const handleSubmit = React.useCallback(
|
|
16
|
+
async (values) => {
|
|
17
|
+
setSubmitting(true);
|
|
18
|
+
try {
|
|
19
|
+
const payload = {
|
|
20
|
+
customerId: values.customerId.trim(),
|
|
21
|
+
name: values.name.trim(),
|
|
22
|
+
currencyCode: values.currencyCode.trim().toUpperCase(),
|
|
23
|
+
billCycle: values.billCycle,
|
|
24
|
+
billCycleAnchor: values.billCycleAnchor.trim(),
|
|
25
|
+
invoiceEmail: values.invoiceEmail.trim(),
|
|
26
|
+
invoiceLanguage: values.invoiceLanguage.trim().toLowerCase(),
|
|
27
|
+
invoiceAddress: {
|
|
28
|
+
line1: values.invoiceAddress.line1.trim(),
|
|
29
|
+
...values.invoiceAddress.line2.trim() ? { line2: values.invoiceAddress.line2.trim() } : {},
|
|
30
|
+
city: values.invoiceAddress.city.trim(),
|
|
31
|
+
postal_code: values.invoiceAddress.postal_code.trim(),
|
|
32
|
+
country: values.invoiceAddress.country.trim().toUpperCase()
|
|
33
|
+
},
|
|
34
|
+
nextBillDate: values.nextBillDate
|
|
35
|
+
};
|
|
36
|
+
if (values.taxId.trim()) payload.taxId = values.taxId.trim();
|
|
37
|
+
const call = await apiCallOrThrow("/api/billing/accounts", {
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: { "Content-Type": "application/json" },
|
|
40
|
+
body: JSON.stringify(payload)
|
|
41
|
+
});
|
|
42
|
+
const id = call.result?.id;
|
|
43
|
+
flash(t("billing.accounts.create.success", "Billing account created"), "success");
|
|
44
|
+
if (id) {
|
|
45
|
+
router.push(`/backend/billing/accounts/${id}`);
|
|
46
|
+
} else {
|
|
47
|
+
router.push("/backend/billing/accounts");
|
|
48
|
+
}
|
|
49
|
+
} catch (err) {
|
|
50
|
+
const { message, fieldErrors } = normalizeCrudServerError(err);
|
|
51
|
+
const fieldDetail = fieldErrors && Object.keys(fieldErrors).length ? Object.entries(fieldErrors).map(([field, msg]) => `${field}: ${msg}`).join("; ") : null;
|
|
52
|
+
const detailed = fieldDetail && message ? `${message} \u2014 ${fieldDetail}` : fieldDetail || message;
|
|
53
|
+
flash(
|
|
54
|
+
detailed || t("billing.accounts.create.error", "Failed to create account"),
|
|
55
|
+
"error"
|
|
56
|
+
);
|
|
57
|
+
} finally {
|
|
58
|
+
setSubmitting(false);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[router, t]
|
|
62
|
+
);
|
|
63
|
+
const handleCancel = React.useCallback(() => {
|
|
64
|
+
router.push("/backend/billing/accounts");
|
|
65
|
+
}, [router]);
|
|
66
|
+
return /* @__PURE__ */ jsxs(Page, { children: [
|
|
67
|
+
/* @__PURE__ */ jsx(PageHeader, { title: t("billing.accounts.create.title", "Create Billing Account") }),
|
|
68
|
+
/* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
|
|
69
|
+
AccountForm,
|
|
70
|
+
{
|
|
71
|
+
mode: "create",
|
|
72
|
+
submitting,
|
|
73
|
+
onSubmit: handleSubmit,
|
|
74
|
+
onCancel: handleCancel
|
|
75
|
+
}
|
|
76
|
+
) })
|
|
77
|
+
] });
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
CreateBillingAccountPage as default
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/billing/backend/billing/accounts/create/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody, PageHeader } from '@open-mercato/ui/backend/Page'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCallOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { normalizeCrudServerError } from '@open-mercato/ui/backend/utils/serverErrors'\nimport { AccountForm, type AccountFormValues } from '../../../../components/AccountForm'\n\n/**\n * `/backend/billing/accounts/create` \u2014 create a Billing Account.\n *\n * POSTs `/api/billing/accounts`. On success, flash + navigate to the\n * new account's detail page (`/backend/billing/accounts/<id>`) so the\n * operator can continue editing if they need to tweak after-creation\n * details.\n */\nexport default function CreateBillingAccountPage() {\n const t = useT()\n const router = useRouter()\n const [submitting, setSubmitting] = React.useState(false)\n\n const handleSubmit = React.useCallback(\n async (values: AccountFormValues) => {\n setSubmitting(true)\n try {\n const payload: Record<string, unknown> = {\n customerId: values.customerId.trim(),\n name: values.name.trim(),\n currencyCode: values.currencyCode.trim().toUpperCase(),\n billCycle: values.billCycle,\n billCycleAnchor: values.billCycleAnchor.trim(),\n invoiceEmail: values.invoiceEmail.trim(),\n invoiceLanguage: values.invoiceLanguage.trim().toLowerCase(),\n invoiceAddress: {\n line1: values.invoiceAddress.line1.trim(),\n ...(values.invoiceAddress.line2.trim()\n ? { line2: values.invoiceAddress.line2.trim() }\n : {}),\n city: values.invoiceAddress.city.trim(),\n postal_code: values.invoiceAddress.postal_code.trim(),\n country: values.invoiceAddress.country.trim().toUpperCase(),\n },\n nextBillDate: values.nextBillDate,\n }\n if (values.taxId.trim()) payload.taxId = values.taxId.trim()\n\n const call = await apiCallOrThrow<{ id: string }>('/api/billing/accounts', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(payload),\n })\n const id = call.result?.id\n flash(t('billing.accounts.create.success', 'Billing account created'), 'success')\n if (id) {\n router.push(`/backend/billing/accounts/${id}`)\n } else {\n router.push('/backend/billing/accounts')\n }\n } catch (err) {\n const { message, fieldErrors } = normalizeCrudServerError(err)\n const fieldDetail =\n fieldErrors && Object.keys(fieldErrors).length\n ? Object.entries(fieldErrors)\n .map(([field, msg]) => `${field}: ${msg}`)\n .join('; ')\n : null\n const detailed =\n fieldDetail && message\n ? `${message} \u2014 ${fieldDetail}`\n : fieldDetail || message\n flash(\n detailed || t('billing.accounts.create.error', 'Failed to create account'),\n 'error',\n )\n } finally {\n setSubmitting(false)\n }\n },\n [router, t],\n )\n\n const handleCancel = React.useCallback(() => {\n router.push('/backend/billing/accounts')\n }, [router])\n\n return (\n <Page>\n <PageHeader title={t('billing.accounts.create.title', 'Create Billing Account')} />\n <PageBody>\n <AccountForm\n mode=\"create\"\n submitting={submitting}\n onSubmit={handleSubmit}\n onCancel={handleCancel}\n />\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAwFI,SACE,KADF;AAvFJ,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAC1B,SAAS,YAAY;AACrB,SAAS,MAAM,UAAU,kBAAkB;AAC3C,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,mBAA2C;AAUrC,SAAR,2BAA4C;AACjD,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,UAAU;AACzB,QAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,KAAK;AAExD,QAAM,eAAe,MAAM;AAAA,IACzB,OAAO,WAA8B;AACnC,oBAAc,IAAI;AAClB,UAAI;AACF,cAAM,UAAmC;AAAA,UACvC,YAAY,OAAO,WAAW,KAAK;AAAA,UACnC,MAAM,OAAO,KAAK,KAAK;AAAA,UACvB,cAAc,OAAO,aAAa,KAAK,EAAE,YAAY;AAAA,UACrD,WAAW,OAAO;AAAA,UAClB,iBAAiB,OAAO,gBAAgB,KAAK;AAAA,UAC7C,cAAc,OAAO,aAAa,KAAK;AAAA,UACvC,iBAAiB,OAAO,gBAAgB,KAAK,EAAE,YAAY;AAAA,UAC3D,gBAAgB;AAAA,YACd,OAAO,OAAO,eAAe,MAAM,KAAK;AAAA,YACxC,GAAI,OAAO,eAAe,MAAM,KAAK,IACjC,EAAE,OAAO,OAAO,eAAe,MAAM,KAAK,EAAE,IAC5C,CAAC;AAAA,YACL,MAAM,OAAO,eAAe,KAAK,KAAK;AAAA,YACtC,aAAa,OAAO,eAAe,YAAY,KAAK;AAAA,YACpD,SAAS,OAAO,eAAe,QAAQ,KAAK,EAAE,YAAY;AAAA,UAC5D;AAAA,UACA,cAAc,OAAO;AAAA,QACvB;AACA,YAAI,OAAO,MAAM,KAAK,EAAG,SAAQ,QAAQ,OAAO,MAAM,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";
|
|
2
|
+
import { Building2 } from "lucide-react";
|
|
3
|
+
const accountIcon = React.createElement(Building2, { size: 16 });
|
|
4
|
+
const metadata = {
|
|
5
|
+
requireAuth: true,
|
|
6
|
+
requireFeatures: ["billing.account.manage"],
|
|
7
|
+
pageTitle: "Create Billing Account",
|
|
8
|
+
pageTitleKey: "billing.accounts.create.title",
|
|
9
|
+
pageGroup: "Billing",
|
|
10
|
+
pageGroupKey: "billing.nav.group",
|
|
11
|
+
navHidden: true,
|
|
12
|
+
icon: accountIcon,
|
|
13
|
+
breadcrumb: [
|
|
14
|
+
{
|
|
15
|
+
label: "Billing Accounts",
|
|
16
|
+
labelKey: "billing.accounts.title",
|
|
17
|
+
href: "/backend/billing/accounts"
|
|
18
|
+
},
|
|
19
|
+
{ label: "Create", labelKey: "billing.accounts.create.title" }
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
metadata
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=page.meta.js.map
|