@dainamite/billing 0.17.0 → 0.19.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 +99 -19
- package/dist/modules/billing/acl.js +9 -1
- package/dist/modules/billing/acl.js.map +2 -2
- package/dist/modules/billing/api/accounts/[id]/balance/route.js +62 -0
- package/dist/modules/billing/api/accounts/[id]/balance/route.js.map +7 -0
- package/dist/modules/billing/api/accounts/[id]/credit-status/route.js +56 -0
- package/dist/modules/billing/api/accounts/[id]/credit-status/route.js.map +7 -0
- package/dist/modules/billing/api/accounts/[id]/topups/route.js +36 -0
- package/dist/modules/billing/api/accounts/[id]/topups/route.js.map +7 -0
- package/dist/modules/billing/api/accounts/route.js +7 -0
- package/dist/modules/billing/api/accounts/route.js.map +2 -2
- package/dist/modules/billing/api/export/account/[id]/route.js +48 -3
- package/dist/modules/billing/api/export/account/[id]/route.js.map +2 -2
- package/dist/modules/billing/api/statements/generate/route.js +68 -0
- package/dist/modules/billing/api/statements/generate/route.js.map +7 -0
- package/dist/modules/billing/api/statements/route.js +110 -0
- package/dist/modules/billing/api/statements/route.js.map +7 -0
- package/dist/modules/billing/api/topups/route.js +139 -0
- package/dist/modules/billing/api/topups/route.js.map +7 -0
- package/dist/modules/billing/api/transactions/adjust/route.js +71 -0
- package/dist/modules/billing/api/transactions/adjust/route.js.map +7 -0
- package/dist/modules/billing/api/transactions/route.js +109 -0
- package/dist/modules/billing/api/transactions/route.js.map +7 -0
- package/dist/modules/billing/api/usage/route.js +30 -6
- package/dist/modules/billing/api/usage/route.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js +16 -1
- package/dist/modules/billing/backend/billing/accounts/[id]/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/create/page.js +8 -1
- package/dist/modules/billing/backend/billing/accounts/create/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/accounts/page.js +26 -1
- package/dist/modules/billing/backend/billing/accounts/page.js.map +2 -2
- package/dist/modules/billing/backend/billing/statements/[id]/page.js +129 -0
- package/dist/modules/billing/backend/billing/statements/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/statements/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/statements/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/statements/page.js +152 -0
- package/dist/modules/billing/backend/billing/statements/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/statements/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/statements/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/topups/[id]/page.js +90 -0
- package/dist/modules/billing/backend/billing/topups/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/topups/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/topups/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/topups/page.js +147 -0
- package/dist/modules/billing/backend/billing/topups/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/topups/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/topups/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/transactions/[id]/page.js +114 -0
- package/dist/modules/billing/backend/billing/transactions/[id]/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/transactions/[id]/page.meta.js +21 -0
- package/dist/modules/billing/backend/billing/transactions/[id]/page.meta.js.map +7 -0
- package/dist/modules/billing/backend/billing/transactions/page.js +149 -0
- package/dist/modules/billing/backend/billing/transactions/page.js.map +7 -0
- package/dist/modules/billing/backend/billing/transactions/page.meta.js +18 -0
- package/dist/modules/billing/backend/billing/transactions/page.meta.js.map +7 -0
- package/dist/modules/billing/commands/accounts.js +26 -1
- package/dist/modules/billing/commands/accounts.js.map +2 -2
- package/dist/modules/billing/commands/index.js +3 -0
- package/dist/modules/billing/commands/index.js.map +2 -2
- package/dist/modules/billing/commands/invoices.js +21 -1
- package/dist/modules/billing/commands/invoices.js.map +2 -2
- package/dist/modules/billing/commands/statements.js +74 -0
- package/dist/modules/billing/commands/statements.js.map +7 -0
- package/dist/modules/billing/commands/topups.js +139 -0
- package/dist/modules/billing/commands/topups.js.map +7 -0
- package/dist/modules/billing/commands/transactions.js +119 -0
- package/dist/modules/billing/commands/transactions.js.map +7 -0
- package/dist/modules/billing/commands/usage.js +72 -0
- package/dist/modules/billing/commands/usage.js.map +2 -2
- package/dist/modules/billing/components/AccountForm.js +53 -1
- package/dist/modules/billing/components/AccountForm.js.map +2 -2
- package/dist/modules/billing/components/PrepaidPanel.js +314 -0
- package/dist/modules/billing/components/PrepaidPanel.js.map +7 -0
- package/dist/modules/billing/components/accountNames.js +20 -0
- package/dist/modules/billing/components/accountNames.js.map +7 -0
- package/dist/modules/billing/data/entities.js +290 -0
- package/dist/modules/billing/data/entities.js.map +2 -2
- package/dist/modules/billing/data/entityIds.js +6 -1
- package/dist/modules/billing/data/entityIds.js.map +2 -2
- package/dist/modules/billing/data/validators.js +107 -2
- package/dist/modules/billing/data/validators.js.map +2 -2
- package/dist/modules/billing/events.js +52 -0
- package/dist/modules/billing/events.js.map +2 -2
- package/dist/modules/billing/i18n/en.json +112 -4
- package/dist/modules/billing/i18n/pl.json +112 -4
- package/dist/modules/billing/index.js +1 -1
- package/dist/modules/billing/index.js.map +2 -2
- package/dist/modules/billing/lib/accountStatus.js +106 -0
- package/dist/modules/billing/lib/accountStatus.js.map +7 -0
- package/dist/modules/billing/lib/balanceEvents.js +48 -0
- package/dist/modules/billing/lib/balanceEvents.js.map +7 -0
- package/dist/modules/billing/lib/balanceLedger.js +136 -0
- package/dist/modules/billing/lib/balanceLedger.js.map +7 -0
- package/dist/modules/billing/lib/balanceStatus.js +29 -0
- package/dist/modules/billing/lib/balanceStatus.js.map +7 -0
- package/dist/modules/billing/lib/billRunEngine.js +40 -2
- package/dist/modules/billing/lib/billRunEngine.js.map +2 -2
- package/dist/modules/billing/lib/creditStatus.js +65 -0
- package/dist/modules/billing/lib/creditStatus.js.map +7 -0
- package/dist/modules/billing/lib/money.js +47 -0
- package/dist/modules/billing/lib/money.js.map +7 -0
- package/dist/modules/billing/lib/prepaidConfig.js +45 -0
- package/dist/modules/billing/lib/prepaidConfig.js.map +7 -0
- package/dist/modules/billing/lib/prepaidConsume.js +214 -0
- package/dist/modules/billing/lib/prepaidConsume.js.map +7 -0
- package/dist/modules/billing/lib/prepaidPeriodClose.js +285 -0
- package/dist/modules/billing/lib/prepaidPeriodClose.js.map +7 -0
- package/dist/modules/billing/lib/topupCapture.js +62 -0
- package/dist/modules/billing/lib/topupCapture.js.map +7 -0
- package/dist/modules/billing/lib/topupReceipt.js +97 -0
- package/dist/modules/billing/lib/topupReceipt.js.map +7 -0
- package/dist/modules/billing/lib/topupTransition.js +19 -0
- package/dist/modules/billing/lib/topupTransition.js.map +7 -0
- package/dist/modules/billing/migrations/Migration20260619000000_billing_prepaid.js +110 -0
- package/dist/modules/billing/migrations/Migration20260619000000_billing_prepaid.js.map +7 -0
- package/dist/modules/billing/setup.js +32 -1
- package/dist/modules/billing/setup.js.map +2 -2
- package/dist/modules/billing/subscribers/prepaid-topup-cancelled.js +26 -0
- package/dist/modules/billing/subscribers/prepaid-topup-cancelled.js.map +7 -0
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js +87 -0
- package/dist/modules/billing/subscribers/prepaid-topup-captured.js.map +7 -0
- package/dist/modules/billing/subscribers/prepaid-topup-expired.js +26 -0
- package/dist/modules/billing/subscribers/prepaid-topup-expired.js.map +7 -0
- package/dist/modules/billing/subscribers/prepaid-topup-failed.js +26 -0
- package/dist/modules/billing/subscribers/prepaid-topup-failed.js.map +7 -0
- package/dist/modules/billing/workers/reconcile-prepaid-balances.js +50 -0
- package/dist/modules/billing/workers/reconcile-prepaid-balances.js.map +7 -0
- package/package.json +9 -9
- package/src/modules/billing/__tests__/commands/invoices.test.ts +3 -3
- package/src/modules/billing/__tests__/commands/topups.test.ts +104 -0
- package/src/modules/billing/__tests__/commands/transactions.test.ts +107 -0
- package/src/modules/billing/__tests__/helpers/prepaidMockEm.ts +235 -0
- package/src/modules/billing/__tests__/lib/accountStatus.test.ts +93 -0
- package/src/modules/billing/__tests__/lib/balanceLedger.test.ts +125 -0
- package/src/modules/billing/__tests__/lib/balanceStatus.test.ts +65 -0
- package/src/modules/billing/__tests__/lib/creditStatus.test.ts +111 -0
- package/src/modules/billing/__tests__/lib/money.test.ts +56 -0
- package/src/modules/billing/__tests__/lib/prepaidConsume.test.ts +179 -0
- package/src/modules/billing/__tests__/lib/prepaidPeriodClose.test.ts +232 -0
- package/src/modules/billing/__tests__/lib/topupCapture.test.ts +123 -0
- package/src/modules/billing/__tests__/lib/topupReceipt.test.ts +84 -0
- package/src/modules/billing/__tests__/setup.test.ts +28 -2
- package/src/modules/billing/acl.ts +8 -0
- package/src/modules/billing/api/accounts/[id]/balance/route.ts +74 -0
- package/src/modules/billing/api/accounts/[id]/credit-status/route.ts +71 -0
- package/src/modules/billing/api/accounts/[id]/topups/route.ts +49 -0
- package/src/modules/billing/api/accounts/route.ts +7 -0
- package/src/modules/billing/api/export/account/[id]/route.ts +47 -2
- package/src/modules/billing/api/statements/generate/route.ts +78 -0
- package/src/modules/billing/api/statements/route.ts +117 -0
- package/src/modules/billing/api/topups/route.ts +154 -0
- package/src/modules/billing/api/transactions/adjust/route.ts +80 -0
- package/src/modules/billing/api/transactions/route.ts +116 -0
- package/src/modules/billing/api/usage/route.ts +36 -5
- package/src/modules/billing/backend/billing/accounts/[id]/page.tsx +28 -0
- package/src/modules/billing/backend/billing/accounts/create/page.tsx +7 -0
- package/src/modules/billing/backend/billing/accounts/page.tsx +32 -1
- package/src/modules/billing/backend/billing/statements/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/statements/[id]/page.tsx +198 -0
- package/src/modules/billing/backend/billing/statements/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/statements/page.tsx +190 -0
- package/src/modules/billing/backend/billing/topups/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/topups/[id]/page.tsx +151 -0
- package/src/modules/billing/backend/billing/topups/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/topups/page.tsx +182 -0
- package/src/modules/billing/backend/billing/transactions/[id]/page.meta.ts +19 -0
- package/src/modules/billing/backend/billing/transactions/[id]/page.tsx +179 -0
- package/src/modules/billing/backend/billing/transactions/page.meta.ts +16 -0
- package/src/modules/billing/backend/billing/transactions/page.tsx +187 -0
- package/src/modules/billing/commands/accounts.ts +42 -1
- package/src/modules/billing/commands/index.ts +3 -0
- package/src/modules/billing/commands/invoices.ts +26 -2
- package/src/modules/billing/commands/statements.ts +101 -0
- package/src/modules/billing/commands/topups.ts +181 -0
- package/src/modules/billing/commands/transactions.ts +152 -0
- package/src/modules/billing/commands/usage.ts +114 -4
- package/src/modules/billing/components/AccountForm.tsx +66 -0
- package/src/modules/billing/components/PrepaidPanel.tsx +382 -0
- package/src/modules/billing/components/accountNames.ts +23 -0
- package/src/modules/billing/data/entities.ts +383 -0
- package/src/modules/billing/data/entityIds.ts +5 -0
- package/src/modules/billing/data/validators.ts +144 -0
- package/src/modules/billing/events.ts +52 -0
- package/src/modules/billing/i18n/en.json +112 -4
- package/src/modules/billing/i18n/pl.json +112 -4
- package/src/modules/billing/index.ts +1 -1
- package/src/modules/billing/lib/accountStatus.ts +155 -0
- package/src/modules/billing/lib/balanceEvents.ts +74 -0
- package/src/modules/billing/lib/balanceLedger.ts +258 -0
- package/src/modules/billing/lib/balanceStatus.ts +78 -0
- package/src/modules/billing/lib/billRunEngine.ts +66 -5
- package/src/modules/billing/lib/creditStatus.ts +153 -0
- package/src/modules/billing/lib/money.ts +73 -0
- package/src/modules/billing/lib/prepaidConfig.ts +58 -0
- package/src/modules/billing/lib/prepaidConsume.ts +299 -0
- package/src/modules/billing/lib/prepaidPeriodClose.ts +453 -0
- package/src/modules/billing/lib/topupCapture.ts +117 -0
- package/src/modules/billing/lib/topupReceipt.ts +153 -0
- package/src/modules/billing/lib/topupTransition.ts +31 -0
- package/src/modules/billing/migrations/Migration20260619000000_billing_prepaid.ts +131 -0
- package/src/modules/billing/setup.ts +45 -0
- package/src/modules/billing/subscribers/prepaid-topup-cancelled.ts +31 -0
- package/src/modules/billing/subscribers/prepaid-topup-captured.ts +120 -0
- package/src/modules/billing/subscribers/prepaid-topup-expired.ts +31 -0
- package/src/modules/billing/subscribers/prepaid-topup-failed.ts +32 -0
- package/src/modules/billing/workers/reconcile-prepaid-balances.ts +68 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/billing/backend/billing/topups/%5Bid%5D/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { Wallet } from 'lucide-react'\n\nconst topupIcon = React.createElement(Wallet, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.topup.view'],\n pageTitle: 'Top-up',\n pageTitleKey: 'billing.topups.detail.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n navHidden: true,\n icon: topupIcon,\n breadcrumb: [\n { label: 'Top-ups', labelKey: 'billing.topups.title', href: '/backend/billing/topups' },\n { label: 'Top-up', labelKey: 'billing.topups.detail.title' },\n ],\n} as const\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,cAAc;AAEvB,MAAM,YAAY,MAAM,cAAc,QAAQ,EAAE,MAAM,GAAG,CAAC;AAEnD,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,oBAAoB;AAAA,EACtC,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY;AAAA,IACV,EAAE,OAAO,WAAW,UAAU,wBAAwB,MAAM,0BAA0B;AAAA,IACtF,EAAE,OAAO,UAAU,UAAU,8BAA8B;AAAA,EAC7D;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
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 } from "@open-mercato/ui/backend/Page";
|
|
7
|
+
import { DataTable } from "@open-mercato/ui/backend/DataTable";
|
|
8
|
+
import { Tag } from "@open-mercato/ui/primitives/tag";
|
|
9
|
+
import { readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
10
|
+
import { fetchAccountNames } from "../../../components/accountNames.js";
|
|
11
|
+
function formatDate(value) {
|
|
12
|
+
if (!value) return "\u2014";
|
|
13
|
+
const d = new Date(value);
|
|
14
|
+
return Number.isNaN(d.getTime()) ? value : d.toLocaleString();
|
|
15
|
+
}
|
|
16
|
+
function statusVariant(status) {
|
|
17
|
+
if (status === "captured") return "success";
|
|
18
|
+
if (status === "pending") return "info";
|
|
19
|
+
if (status === "failed") return "error";
|
|
20
|
+
return "default";
|
|
21
|
+
}
|
|
22
|
+
function BillingTopupsListPage() {
|
|
23
|
+
const t = useT();
|
|
24
|
+
const router = useRouter();
|
|
25
|
+
const [rows, setRows] = React.useState([]);
|
|
26
|
+
const [page, setPage] = React.useState(1);
|
|
27
|
+
const [pageSize] = React.useState(25);
|
|
28
|
+
const [filters, setFilters] = React.useState({});
|
|
29
|
+
const [search, setSearch] = React.useState("");
|
|
30
|
+
const [total, setTotal] = React.useState(0);
|
|
31
|
+
const [totalPages, setTotalPages] = React.useState(1);
|
|
32
|
+
const [loading, setLoading] = React.useState(true);
|
|
33
|
+
const [accountNames, setAccountNames] = React.useState({});
|
|
34
|
+
const filterDefs = React.useMemo(
|
|
35
|
+
() => [
|
|
36
|
+
{
|
|
37
|
+
id: "status",
|
|
38
|
+
label: t("billing.topups.filters.status", "Status"),
|
|
39
|
+
type: "select",
|
|
40
|
+
options: [
|
|
41
|
+
{ value: "pending", label: t("billing.topups.status.pending", "Pending") },
|
|
42
|
+
{ value: "captured", label: t("billing.topups.status.captured", "Captured") },
|
|
43
|
+
{ value: "failed", label: t("billing.topups.status.failed", "Failed") },
|
|
44
|
+
{ value: "cancelled", label: t("billing.topups.status.cancelled", "Cancelled") },
|
|
45
|
+
{ value: "expired", label: t("billing.topups.status.expired", "Expired") }
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
[t]
|
|
50
|
+
);
|
|
51
|
+
const loadRows = React.useCallback(async () => {
|
|
52
|
+
setLoading(true);
|
|
53
|
+
try {
|
|
54
|
+
const params = new URLSearchParams({
|
|
55
|
+
page: String(page),
|
|
56
|
+
pageSize: String(pageSize),
|
|
57
|
+
sortField: "createdAt",
|
|
58
|
+
sortDir: "desc"
|
|
59
|
+
});
|
|
60
|
+
if (search.trim()) params.set("search", search.trim());
|
|
61
|
+
if (typeof filters.status === "string" && filters.status) params.set("status", filters.status);
|
|
62
|
+
const result = await readApiResultOrThrow(
|
|
63
|
+
`/api/billing/topups?${params.toString()}`
|
|
64
|
+
);
|
|
65
|
+
const items = result.items ?? [];
|
|
66
|
+
setRows(items);
|
|
67
|
+
setTotal(result.total ?? 0);
|
|
68
|
+
setTotalPages(result.totalPages ?? 1);
|
|
69
|
+
try {
|
|
70
|
+
const names = await fetchAccountNames(items.map((r) => r.bill_account_id));
|
|
71
|
+
setAccountNames((prev) => ({ ...prev, ...names }));
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
} finally {
|
|
75
|
+
setLoading(false);
|
|
76
|
+
}
|
|
77
|
+
}, [filters.status, page, pageSize, search]);
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
void loadRows();
|
|
80
|
+
}, [loadRows]);
|
|
81
|
+
const columns = React.useMemo(
|
|
82
|
+
() => [
|
|
83
|
+
{
|
|
84
|
+
accessorKey: "created_at",
|
|
85
|
+
header: t("billing.topups.columns.created", "Created"),
|
|
86
|
+
cell: ({ row }) => formatDate(row.original.created_at)
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
accessorKey: "amount",
|
|
90
|
+
header: t("billing.topups.columns.amount", "Amount"),
|
|
91
|
+
cell: ({ row }) => /* @__PURE__ */ jsxs("span", { className: "font-mono tabular-nums", children: [
|
|
92
|
+
row.original.amount,
|
|
93
|
+
" ",
|
|
94
|
+
row.original.currency_code
|
|
95
|
+
] })
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
accessorKey: "provider_key",
|
|
99
|
+
header: t("billing.topups.columns.provider", "Provider"),
|
|
100
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.original.provider_key })
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
accessorKey: "status",
|
|
104
|
+
header: t("billing.topups.columns.status", "Status"),
|
|
105
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Tag, { variant: statusVariant(row.original.status), children: t(`billing.topups.status.${row.original.status}`, row.original.status) })
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
accessorKey: "bill_account_id",
|
|
109
|
+
header: t("billing.topups.columns.account", "Account"),
|
|
110
|
+
cell: ({ row }) => {
|
|
111
|
+
const name = accountNames[row.original.bill_account_id];
|
|
112
|
+
return name ? /* @__PURE__ */ jsx("span", { className: "text-sm", children: name }) : /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.original.bill_account_id });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
[t, accountNames]
|
|
117
|
+
);
|
|
118
|
+
return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
|
|
119
|
+
DataTable,
|
|
120
|
+
{
|
|
121
|
+
title: t("billing.topups.title", "Top-ups"),
|
|
122
|
+
refreshButton: {
|
|
123
|
+
label: t("billing.common.refresh", "Refresh"),
|
|
124
|
+
onRefresh: loadRows,
|
|
125
|
+
isRefreshing: loading
|
|
126
|
+
},
|
|
127
|
+
columnChooser: { auto: true },
|
|
128
|
+
perspective: { tableId: "billing-topups" },
|
|
129
|
+
columns,
|
|
130
|
+
data: rows,
|
|
131
|
+
onRowClick: (row) => router.push(`/backend/billing/topups/${row.id}`),
|
|
132
|
+
isLoading: loading,
|
|
133
|
+
pagination: { page, pageSize, total, totalPages, onPageChange: setPage },
|
|
134
|
+
filters: filterDefs,
|
|
135
|
+
filterValues: filters,
|
|
136
|
+
onFiltersApply: setFilters,
|
|
137
|
+
onFiltersClear: () => setFilters({}),
|
|
138
|
+
searchValue: search,
|
|
139
|
+
onSearchChange: setSearch
|
|
140
|
+
}
|
|
141
|
+
) }) });
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
BillingTopupsListPage as default,
|
|
145
|
+
statusVariant
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/billing/backend/billing/topups/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport type { ColumnDef } from '@tanstack/react-table'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { fetchAccountNames } from '../../../components/accountNames'\n\n/**\n * Registered top-ups admin list (SPEC-002 P2). Read-only \u2014 top-ups are\n * initiated from a prepaid account's detail page and progress through the\n * gateway capture lifecycle.\n */\n\ntype TopupRow = {\n id: string\n bill_account_id: string\n status: string\n amount: string\n currency_code: string\n provider_key: string\n receipt_invoice_id: string | null\n created_at: string\n}\n\ntype ListResponse = { items: TopupRow[]; total: number; totalPages: number }\n\nfunction formatDate(value: string | null | undefined): string {\n if (!value) return '\u2014'\n const d = new Date(value)\n return Number.isNaN(d.getTime()) ? value : d.toLocaleString()\n}\n\nexport function statusVariant(status: string): 'success' | 'info' | 'error' | 'default' {\n if (status === 'captured') return 'success'\n if (status === 'pending') return 'info'\n if (status === 'failed') return 'error'\n return 'default' // cancelled / expired\n}\n\nexport default function BillingTopupsListPage() {\n const t = useT()\n const router = useRouter()\n const [rows, setRows] = React.useState<TopupRow[]>([])\n const [page, setPage] = React.useState(1)\n const [pageSize] = React.useState(25)\n const [filters, setFilters] = React.useState<FilterValues>({})\n const [search, setSearch] = React.useState('')\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [loading, setLoading] = React.useState(true)\n const [accountNames, setAccountNames] = React.useState<Record<string, string>>({})\n\n const filterDefs = React.useMemo<FilterDef[]>(\n () => [\n {\n id: 'status',\n label: t('billing.topups.filters.status', 'Status'),\n type: 'select',\n options: [\n { value: 'pending', label: t('billing.topups.status.pending', 'Pending') },\n { value: 'captured', label: t('billing.topups.status.captured', 'Captured') },\n { value: 'failed', label: t('billing.topups.status.failed', 'Failed') },\n { value: 'cancelled', label: t('billing.topups.status.cancelled', 'Cancelled') },\n { value: 'expired', label: t('billing.topups.status.expired', 'Expired') },\n ],\n },\n ],\n [t],\n )\n\n const loadRows = React.useCallback(async () => {\n setLoading(true)\n try {\n const params = new URLSearchParams({\n page: String(page),\n pageSize: String(pageSize),\n sortField: 'createdAt',\n sortDir: 'desc',\n })\n if (search.trim()) params.set('search', search.trim())\n if (typeof filters.status === 'string' && filters.status) params.set('status', filters.status)\n const result = await readApiResultOrThrow<ListResponse>(\n `/api/billing/topups?${params.toString()}`,\n )\n const items = result.items ?? []\n setRows(items)\n setTotal(result.total ?? 0)\n setTotalPages(result.totalPages ?? 1)\n try {\n const names = await fetchAccountNames(items.map((r) => r.bill_account_id))\n setAccountNames((prev) => ({ ...prev, ...names }))\n } catch {\n // Name resolution is best-effort \u2014 fall back to the id in the cell.\n }\n } finally {\n setLoading(false)\n }\n }, [filters.status, page, pageSize, search])\n\n React.useEffect(() => {\n void loadRows()\n }, [loadRows])\n\n const columns = React.useMemo<ColumnDef<TopupRow>[]>(\n () => [\n {\n accessorKey: 'created_at',\n header: t('billing.topups.columns.created', 'Created'),\n cell: ({ row }) => formatDate(row.original.created_at),\n },\n {\n accessorKey: 'amount',\n header: t('billing.topups.columns.amount', 'Amount'),\n cell: ({ row }) => (\n <span className=\"font-mono tabular-nums\">\n {row.original.amount} {row.original.currency_code}\n </span>\n ),\n },\n {\n accessorKey: 'provider_key',\n header: t('billing.topups.columns.provider', 'Provider'),\n cell: ({ row }) => <span className=\"font-mono text-xs\">{row.original.provider_key}</span>,\n },\n {\n accessorKey: 'status',\n header: t('billing.topups.columns.status', 'Status'),\n cell: ({ row }) => (\n <Tag variant={statusVariant(row.original.status)}>\n {t(`billing.topups.status.${row.original.status}`, row.original.status)}\n </Tag>\n ),\n },\n {\n accessorKey: 'bill_account_id',\n header: t('billing.topups.columns.account', 'Account'),\n cell: ({ row }) => {\n const name = accountNames[row.original.bill_account_id]\n return name ? (\n <span className=\"text-sm\">{name}</span>\n ) : (\n <span className=\"font-mono text-xs\">{row.original.bill_account_id}</span>\n )\n },\n },\n ],\n [t, accountNames],\n )\n\n return (\n <Page>\n <PageBody>\n <DataTable\n title={t('billing.topups.title', 'Top-ups')}\n refreshButton={{\n label: t('billing.common.refresh', 'Refresh'),\n onRefresh: loadRows,\n isRefreshing: loading,\n }}\n columnChooser={{ auto: true }}\n perspective={{ tableId: 'billing-topups' }}\n columns={columns}\n data={rows}\n onRowClick={(row) => router.push(`/backend/billing/topups/${row.id}`)}\n isLoading={loading}\n pagination={{ page, pageSize, total, totalPages, onPageChange: setPage }}\n filters={filterDefs}\n filterValues={filters}\n onFiltersApply={setFilters}\n onFiltersClear={() =>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AAAA,IACF;AAAA,IACA,CAAC,GAAG,YAAY;AAAA,EAClB;AAEA,SACE,oBAAC,QACC,8BAAC,YACC;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,EAAE,wBAAwB,SAAS;AAAA,MAC1C,eAAe;AAAA,QACb,OAAO,EAAE,0BAA0B,SAAS;AAAA,QAC5C,WAAW;AAAA,QACX,cAAc;AAAA,MAChB;AAAA,MACA,eAAe,EAAE,MAAM,KAAK;AAAA,MAC5B,aAAa,EAAE,SAAS,iBAAiB;AAAA,MACzC;AAAA,MACA,MAAM;AAAA,MACN,YAAY,CAAC,QAAQ,OAAO,KAAK,2BAA2B,IAAI,EAAE,EAAE;AAAA,MACpE,WAAW;AAAA,MACX,YAAY,EAAE,MAAM,UAAU,OAAO,YAAY,cAAc,QAAQ;AAAA,MACvE,SAAS;AAAA,MACT,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,gBAAgB,MAAM,WAAW,CAAC,CAAC;AAAA,MACnC,aAAa;AAAA,MACb,gBAAgB;AAAA;AAAA,EAClB,GACF,GACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Wallet } from "lucide-react";
|
|
3
|
+
const topupsIcon = React.createElement(Wallet, { size: 16 });
|
|
4
|
+
const metadata = {
|
|
5
|
+
requireAuth: true,
|
|
6
|
+
requireFeatures: ["billing.topup.view"],
|
|
7
|
+
pageTitle: "Top-ups",
|
|
8
|
+
pageTitleKey: "billing.topups.title",
|
|
9
|
+
pageGroup: "Billing",
|
|
10
|
+
pageGroupKey: "billing.nav.group",
|
|
11
|
+
pageOrder: 50,
|
|
12
|
+
icon: topupsIcon,
|
|
13
|
+
breadcrumb: [{ label: "Top-ups", labelKey: "billing.topups.title" }]
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
metadata
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=page.meta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/billing/backend/billing/topups/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { Wallet } from 'lucide-react'\n\nconst topupsIcon = React.createElement(Wallet, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.topup.view'],\n pageTitle: 'Top-ups',\n pageTitleKey: 'billing.topups.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n pageOrder: 50,\n icon: topupsIcon,\n breadcrumb: [{ label: 'Top-ups', labelKey: 'billing.topups.title' }],\n} as const\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,cAAc;AAEvB,MAAM,aAAa,MAAM,cAAc,QAAQ,EAAE,MAAM,GAAG,CAAC;AAEpD,MAAM,WAAW;AAAA,EACtB,aAAa;AAAA,EACb,iBAAiB,CAAC,oBAAoB;AAAA,EACtC,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,cAAc;AAAA,EACd,WAAW;AAAA,EACX,MAAM;AAAA,EACN,YAAY,CAAC,EAAE,OAAO,WAAW,UAAU,uBAAuB,CAAC;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
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 { useParams } from "next/navigation";
|
|
6
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
7
|
+
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
|
|
8
|
+
import { FormHeader } from "@open-mercato/ui/backend/forms";
|
|
9
|
+
import { Tag } from "@open-mercato/ui/primitives/tag";
|
|
10
|
+
import { Button } from "@open-mercato/ui/primitives/button";
|
|
11
|
+
import { LoadingMessage, ErrorMessage } from "@open-mercato/ui/backend/detail";
|
|
12
|
+
import { readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
13
|
+
import { DetailCard, DetailField } from "../../../../components/DetailFields.js";
|
|
14
|
+
import { txnVariant } from "../page.js";
|
|
15
|
+
function formatDate(value) {
|
|
16
|
+
if (!value) return "\u2014";
|
|
17
|
+
const d = new Date(value);
|
|
18
|
+
return Number.isNaN(d.getTime()) ? value : d.toLocaleString();
|
|
19
|
+
}
|
|
20
|
+
function RefField({ id, href }) {
|
|
21
|
+
if (!id) return /* @__PURE__ */ jsx(Fragment, { children: "\u2014" });
|
|
22
|
+
if (href) {
|
|
23
|
+
return /* @__PURE__ */ jsx(Link, { href, className: "font-mono text-xs hover:underline", children: id });
|
|
24
|
+
}
|
|
25
|
+
return /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: id });
|
|
26
|
+
}
|
|
27
|
+
function BillingTransactionDetailPage(props) {
|
|
28
|
+
const t = useT();
|
|
29
|
+
const urlParams = useParams();
|
|
30
|
+
const transactionId = props.params?.id ?? urlParams?.id ?? "";
|
|
31
|
+
const [row, setRow] = React.useState(null);
|
|
32
|
+
const [loading, setLoading] = React.useState(true);
|
|
33
|
+
const [error, setError] = React.useState(null);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
let cancelled = false;
|
|
36
|
+
if (!transactionId) return;
|
|
37
|
+
setLoading(true);
|
|
38
|
+
readApiResultOrThrow(
|
|
39
|
+
`/api/billing/transactions?id=${transactionId}&pageSize=1`
|
|
40
|
+
).then((res) => {
|
|
41
|
+
if (cancelled) return;
|
|
42
|
+
const found = res.items?.[0];
|
|
43
|
+
if (!found) setError(t("billing.transactions.detail.not_found", "Transaction not found"));
|
|
44
|
+
else setRow(found);
|
|
45
|
+
}).catch(() => {
|
|
46
|
+
if (!cancelled)
|
|
47
|
+
setError(t("billing.transactions.detail.load_error", "Failed to load transaction"));
|
|
48
|
+
}).finally(() => {
|
|
49
|
+
if (!cancelled) setLoading(false);
|
|
50
|
+
});
|
|
51
|
+
return () => {
|
|
52
|
+
cancelled = true;
|
|
53
|
+
};
|
|
54
|
+
}, [transactionId, t]);
|
|
55
|
+
if (error) {
|
|
56
|
+
return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(ErrorMessage, { label: error }) }) });
|
|
57
|
+
}
|
|
58
|
+
if (loading || !row) {
|
|
59
|
+
return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(LoadingMessage, { label: t("billing.transactions.detail.loading", "Loading transaction\u2026") }) }) });
|
|
60
|
+
}
|
|
61
|
+
return /* @__PURE__ */ jsxs(Page, { children: [
|
|
62
|
+
/* @__PURE__ */ jsx(
|
|
63
|
+
FormHeader,
|
|
64
|
+
{
|
|
65
|
+
mode: "detail",
|
|
66
|
+
backHref: "/backend/billing/transactions",
|
|
67
|
+
entityTypeLabel: t("billing.transactions.detail.title", "Transaction"),
|
|
68
|
+
title: `${row.amount} ${row.currency_code}`,
|
|
69
|
+
statusBadge: /* @__PURE__ */ jsx(Tag, { variant: txnVariant(row.type), children: t(`billing.transactions.type.${row.type}`, row.type) }),
|
|
70
|
+
actionsContent: /* @__PURE__ */ jsx(Button, { asChild: true, variant: "outline", children: /* @__PURE__ */ jsx(Link, { href: `/backend/billing/accounts/${row.bill_account_id}`, children: t("billing.transactions.detail.view_account", "View account") }) })
|
|
71
|
+
}
|
|
72
|
+
),
|
|
73
|
+
/* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsxs(DetailCard, { children: [
|
|
74
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.columns.amount", "Amount"), children: /* @__PURE__ */ jsxs("span", { className: "font-mono tabular-nums", children: [
|
|
75
|
+
row.amount,
|
|
76
|
+
" ",
|
|
77
|
+
row.currency_code
|
|
78
|
+
] }) }),
|
|
79
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.columns.balance_after", "Balance"), children: /* @__PURE__ */ jsx("span", { className: "font-mono tabular-nums", children: row.balance_after }) }),
|
|
80
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.columns.type", "Type"), children: /* @__PURE__ */ jsx(Tag, { variant: txnVariant(row.type), children: t(`billing.transactions.type.${row.type}`, row.type) }) }),
|
|
81
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.columns.when", "When"), children: formatDate(row.created_at) }),
|
|
82
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.columns.description", "Description"), fullWidth: true, children: row.description || "\u2014" }),
|
|
83
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.detail.source_ref", "Source ref"), children: /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.source_ref || "\u2014" }) }),
|
|
84
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.detail.topup", "Top-up"), children: /* @__PURE__ */ jsx(
|
|
85
|
+
RefField,
|
|
86
|
+
{
|
|
87
|
+
id: row.topup_id,
|
|
88
|
+
href: row.topup_id ? `/backend/billing/topups/${row.topup_id}` : void 0
|
|
89
|
+
}
|
|
90
|
+
) }),
|
|
91
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.detail.statement", "Statement"), children: /* @__PURE__ */ jsx(
|
|
92
|
+
RefField,
|
|
93
|
+
{
|
|
94
|
+
id: row.statement_id,
|
|
95
|
+
href: row.statement_id ? `/backend/billing/statements/${row.statement_id}` : void 0
|
|
96
|
+
}
|
|
97
|
+
) }),
|
|
98
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.detail.usage", "Usage record"), children: /* @__PURE__ */ jsx(RefField, { id: row.usage_id }) }),
|
|
99
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.detail.item", "Billing item"), children: /* @__PURE__ */ jsx(
|
|
100
|
+
RefField,
|
|
101
|
+
{
|
|
102
|
+
id: row.billing_item_id,
|
|
103
|
+
href: row.billing_item_id ? `/backend/billing/items/${row.billing_item_id}` : void 0
|
|
104
|
+
}
|
|
105
|
+
) }),
|
|
106
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.transactions.detail.user", "User"), children: /* @__PURE__ */ jsx(RefField, { id: row.user_id }) }),
|
|
107
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("billing.common.id", "ID"), children: /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.id }) })
|
|
108
|
+
] }) })
|
|
109
|
+
] });
|
|
110
|
+
}
|
|
111
|
+
export {
|
|
112
|
+
BillingTransactionDetailPage as default
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/billing/backend/billing/transactions/%5Bid%5D/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useParams } from 'next/navigation'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { FormHeader } from '@open-mercato/ui/backend/forms'\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 { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { DetailCard, DetailField } from '../../../../components/DetailFields'\nimport { txnVariant } from '../page'\n\ntype TransactionRow = {\n id: string\n bill_account_id: string\n type: string\n amount: string\n currency_code: string\n balance_after: string\n usage_id: string | null\n billing_item_id: string | null\n topup_id: string | null\n statement_id: string | null\n description: string\n source_ref: string | null\n user_id: string | null\n created_at: string\n}\n\nfunction formatDate(value: string | null | undefined): string {\n if (!value) return '\u2014'\n const d = new Date(value)\n return Number.isNaN(d.getTime()) ? value : d.toLocaleString()\n}\n\n// A monospace value that links somewhere when present, else an em dash.\nfunction RefField({ id, href }: { id: string | null; href?: string }) {\n if (!id) return <>\u2014</>\n if (href) {\n return (\n <Link href={href} className=\"font-mono text-xs hover:underline\">\n {id}\n </Link>\n )\n }\n return <span className=\"font-mono text-xs\">{id}</span>\n}\n\nexport default function BillingTransactionDetailPage(props: { params?: { id?: string } }) {\n const t = useT()\n const urlParams = useParams<{ id: string }>()\n const transactionId = (props.params?.id ?? urlParams?.id ?? '') as string\n\n const [row, setRow] = React.useState<TransactionRow | null>(null)\n const [loading, setLoading] = React.useState(true)\n const [error, setError] = React.useState<string | null>(null)\n\n React.useEffect(() => {\n let cancelled = false\n if (!transactionId) return\n setLoading(true)\n readApiResultOrThrow<{ items: TransactionRow[] }>(\n `/api/billing/transactions?id=${transactionId}&pageSize=1`,\n )\n .then((res) => {\n if (cancelled) return\n const found = res.items?.[0]\n if (!found) setError(t('billing.transactions.detail.not_found', 'Transaction not found'))\n else setRow(found)\n })\n .catch(() => {\n if (!cancelled)\n setError(t('billing.transactions.detail.load_error', 'Failed to load transaction'))\n })\n .finally(() => {\n if (!cancelled) setLoading(false)\n })\n return () => {\n cancelled = true\n }\n }, [transactionId, t])\n\n if (error) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage label={error} />\n </PageBody>\n </Page>\n )\n }\n if (loading || !row) {\n return (\n <Page>\n <PageBody>\n <LoadingMessage label={t('billing.transactions.detail.loading', 'Loading transaction\u2026')} />\n </PageBody>\n </Page>\n )\n }\n\n return (\n <Page>\n <FormHeader\n mode=\"detail\"\n backHref=\"/backend/billing/transactions\"\n entityTypeLabel={t('billing.transactions.detail.title', 'Transaction')}\n title={`${row.amount} ${row.currency_code}`}\n statusBadge={\n <Tag variant={txnVariant(row.type)}>\n {t(`billing.transactions.type.${row.type}`, row.type)}\n </Tag>\n }\n actionsContent={\n <Button asChild variant=\"outline\">\n <Link href={`/backend/billing/accounts/${row.bill_account_id}`}>\n {t('billing.transactions.detail.view_account', 'View account')}\n </Link>\n </Button>\n }\n />\n <PageBody>\n <DetailCard>\n <DetailField label={t('billing.transactions.columns.amount', 'Amount')}>\n <span className=\"font-mono tabular-nums\">\n {row.amount} {row.currency_code}\n </span>\n </DetailField>\n <DetailField label={t('billing.transactions.columns.balance_after', 'Balance')}>\n <span className=\"font-mono tabular-nums\">{row.balance_after}</span>\n </DetailField>\n <DetailField label={t('billing.transactions.columns.type', 'Type')}>\n <Tag variant={txnVariant(row.type)}>\n {t(`billing.transactions.type.${row.type}`, row.type)}\n </Tag>\n </DetailField>\n <DetailField label={t('billing.transactions.columns.when', 'When')}>\n {formatDate(row.created_at)}\n </DetailField>\n <DetailField label={t('billing.transactions.columns.description', 'Description')} fullWidth>\n {row.description || '\u2014'}\n </DetailField>\n <DetailField label={t('billing.transactions.detail.source_ref', 'Source ref')}>\n <span className=\"font-mono text-xs\">{row.source_ref || '\u2014'}</span>\n </DetailField>\n <DetailField label={t('billing.transactions.detail.topup', 'Top-up')}>\n <RefField\n id={row.topup_id}\n href={row.topup_id ? `/backend/billing/topups/${row.topup_id}` : undefined}\n />\n </DetailField>\n <DetailField label={t('billing.transactions.detail.statement', 'Statement')}>\n <RefField\n id={row.statement_id}\n href={row.statement_id ? `/backend/billing/statements/${row.statement_id}` : undefined}\n />\n </DetailField>\n <DetailField label={t('billing.transactions.detail.usage', 'Usage record')}>\n <RefField id={row.usage_id} />\n </DetailField>\n <DetailField label={t('billing.transactions.detail.item', 'Billing item')}>\n <RefField\n id={row.billing_item_id}\n href={row.billing_item_id ? `/backend/billing/items/${row.billing_item_id}` : undefined}\n />\n </DetailField>\n <DetailField label={t('billing.transactions.detail.user', 'User')}>\n <RefField id={row.user_id} />\n </DetailField>\n <DetailField label={t('billing.common.id', 'ID')}>\n <span className=\"font-mono text-xs\">{row.id}</span>\n </DetailField>\n </DetailCard>\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAuCkB,wBAuFN,YAvFM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,qBAAqB,cAAI,IAAG,GAC9C;AAAA,OACF,GACF;AAAA,KACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ArrowLeftRight } from "lucide-react";
|
|
3
|
+
const transactionIcon = React.createElement(ArrowLeftRight, { size: 16 });
|
|
4
|
+
const metadata = {
|
|
5
|
+
requireAuth: true,
|
|
6
|
+
requireFeatures: ["billing.balance.view"],
|
|
7
|
+
pageTitle: "Transaction",
|
|
8
|
+
pageTitleKey: "billing.transactions.detail.title",
|
|
9
|
+
pageGroup: "Billing",
|
|
10
|
+
pageGroupKey: "billing.nav.group",
|
|
11
|
+
navHidden: true,
|
|
12
|
+
icon: transactionIcon,
|
|
13
|
+
breadcrumb: [
|
|
14
|
+
{ label: "Transactions", labelKey: "billing.transactions.title", href: "/backend/billing/transactions" },
|
|
15
|
+
{ label: "Transaction", labelKey: "billing.transactions.detail.title" }
|
|
16
|
+
]
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
metadata
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=page.meta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../src/modules/billing/backend/billing/transactions/%5Bid%5D/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { ArrowLeftRight } from 'lucide-react'\n\nconst transactionIcon = React.createElement(ArrowLeftRight, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.balance.view'],\n pageTitle: 'Transaction',\n pageTitleKey: 'billing.transactions.detail.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n navHidden: true,\n icon: transactionIcon,\n breadcrumb: [\n { label: 'Transactions', labelKey: 'billing.transactions.title', href: '/backend/billing/transactions' },\n { label: 'Transaction', labelKey: 'billing.transactions.detail.title' },\n ],\n} as const\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,sBAAsB;AAE/B,MAAM,kBAAkB,MAAM,cAAc,gBAAgB,EAAE,MAAM,GAAG,CAAC;AAEjE,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,EAAE,OAAO,gBAAgB,UAAU,8BAA8B,MAAM,gCAAgC;AAAA,IACvG,EAAE,OAAO,eAAe,UAAU,oCAAoC;AAAA,EACxE;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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 } from "@open-mercato/ui/backend/Page";
|
|
7
|
+
import { DataTable } from "@open-mercato/ui/backend/DataTable";
|
|
8
|
+
import { Tag } from "@open-mercato/ui/primitives/tag";
|
|
9
|
+
import { readApiResultOrThrow } from "@open-mercato/ui/backend/utils/apiCall";
|
|
10
|
+
import { fetchAccountNames } from "../../../components/accountNames.js";
|
|
11
|
+
function formatDate(value) {
|
|
12
|
+
if (!value) return "\u2014";
|
|
13
|
+
const d = new Date(value);
|
|
14
|
+
return Number.isNaN(d.getTime()) ? value : d.toLocaleString();
|
|
15
|
+
}
|
|
16
|
+
function txnVariant(type) {
|
|
17
|
+
if (type === "topup" || type === "adjustment") return "success";
|
|
18
|
+
if (type === "usage") return "info";
|
|
19
|
+
if (type === "reversal") return "error";
|
|
20
|
+
return "neutral";
|
|
21
|
+
}
|
|
22
|
+
function BillingTransactionsListPage() {
|
|
23
|
+
const t = useT();
|
|
24
|
+
const router = useRouter();
|
|
25
|
+
const [rows, setRows] = React.useState([]);
|
|
26
|
+
const [page, setPage] = React.useState(1);
|
|
27
|
+
const [pageSize] = React.useState(25);
|
|
28
|
+
const [filters, setFilters] = React.useState({});
|
|
29
|
+
const [total, setTotal] = React.useState(0);
|
|
30
|
+
const [totalPages, setTotalPages] = React.useState(1);
|
|
31
|
+
const [loading, setLoading] = React.useState(true);
|
|
32
|
+
const [accountNames, setAccountNames] = React.useState({});
|
|
33
|
+
const filterDefs = React.useMemo(
|
|
34
|
+
() => [
|
|
35
|
+
{
|
|
36
|
+
id: "type",
|
|
37
|
+
label: t("billing.transactions.filters.type", "Type"),
|
|
38
|
+
type: "select",
|
|
39
|
+
options: [
|
|
40
|
+
{ value: "topup", label: t("billing.transactions.type.topup", "Top-up") },
|
|
41
|
+
{ value: "usage", label: t("billing.transactions.type.usage", "Usage") },
|
|
42
|
+
{ value: "recurring", label: t("billing.transactions.type.recurring", "Recurring") },
|
|
43
|
+
{ value: "one_time", label: t("billing.transactions.type.one_time", "One-time") },
|
|
44
|
+
{ value: "adjustment", label: t("billing.transactions.type.adjustment", "Adjustment") },
|
|
45
|
+
{ value: "reversal", label: t("billing.transactions.type.reversal", "Reversal") }
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
[t]
|
|
50
|
+
);
|
|
51
|
+
const loadRows = React.useCallback(async () => {
|
|
52
|
+
setLoading(true);
|
|
53
|
+
try {
|
|
54
|
+
const params = new URLSearchParams({
|
|
55
|
+
page: String(page),
|
|
56
|
+
pageSize: String(pageSize),
|
|
57
|
+
sortField: "createdAt",
|
|
58
|
+
sortDir: "desc"
|
|
59
|
+
});
|
|
60
|
+
if (typeof filters.type === "string" && filters.type) params.set("type", filters.type);
|
|
61
|
+
const result = await readApiResultOrThrow(
|
|
62
|
+
`/api/billing/transactions?${params.toString()}`
|
|
63
|
+
);
|
|
64
|
+
const items = result.items ?? [];
|
|
65
|
+
setRows(items);
|
|
66
|
+
setTotal(result.total ?? 0);
|
|
67
|
+
setTotalPages(result.totalPages ?? 1);
|
|
68
|
+
try {
|
|
69
|
+
const names = await fetchAccountNames(items.map((r) => r.bill_account_id));
|
|
70
|
+
setAccountNames((prev) => ({ ...prev, ...names }));
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
setLoading(false);
|
|
75
|
+
}
|
|
76
|
+
}, [filters.type, page, pageSize]);
|
|
77
|
+
React.useEffect(() => {
|
|
78
|
+
void loadRows();
|
|
79
|
+
}, [loadRows]);
|
|
80
|
+
const columns = React.useMemo(
|
|
81
|
+
() => [
|
|
82
|
+
{
|
|
83
|
+
accessorKey: "created_at",
|
|
84
|
+
header: t("billing.transactions.columns.when", "When"),
|
|
85
|
+
cell: ({ row }) => formatDate(row.original.created_at)
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
accessorKey: "type",
|
|
89
|
+
header: t("billing.transactions.columns.type", "Type"),
|
|
90
|
+
cell: ({ row }) => /* @__PURE__ */ jsx(Tag, { variant: txnVariant(row.original.type), children: t(`billing.transactions.type.${row.original.type}`, row.original.type) })
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
accessorKey: "description",
|
|
94
|
+
header: t("billing.transactions.columns.description", "Description"),
|
|
95
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "text-sm", children: row.original.description })
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
accessorKey: "amount",
|
|
99
|
+
header: t("billing.transactions.columns.amount", "Amount"),
|
|
100
|
+
cell: ({ row }) => /* @__PURE__ */ jsxs("span", { className: "font-mono tabular-nums", children: [
|
|
101
|
+
row.original.amount,
|
|
102
|
+
" ",
|
|
103
|
+
row.original.currency_code
|
|
104
|
+
] })
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
accessorKey: "balance_after",
|
|
108
|
+
header: t("billing.transactions.columns.balance_after", "Balance"),
|
|
109
|
+
cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "font-mono tabular-nums", children: row.original.balance_after })
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
accessorKey: "bill_account_id",
|
|
113
|
+
header: t("billing.transactions.columns.account", "Account"),
|
|
114
|
+
cell: ({ row }) => {
|
|
115
|
+
const name = accountNames[row.original.bill_account_id];
|
|
116
|
+
return name ? /* @__PURE__ */ jsx("span", { className: "text-sm", children: name }) : /* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: row.original.bill_account_id });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
[t, accountNames]
|
|
121
|
+
);
|
|
122
|
+
return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
|
|
123
|
+
DataTable,
|
|
124
|
+
{
|
|
125
|
+
title: t("billing.transactions.title", "Transactions"),
|
|
126
|
+
refreshButton: {
|
|
127
|
+
label: t("billing.common.refresh", "Refresh"),
|
|
128
|
+
onRefresh: loadRows,
|
|
129
|
+
isRefreshing: loading
|
|
130
|
+
},
|
|
131
|
+
columnChooser: { auto: true },
|
|
132
|
+
perspective: { tableId: "billing-transactions" },
|
|
133
|
+
columns,
|
|
134
|
+
data: rows,
|
|
135
|
+
onRowClick: (row) => router.push(`/backend/billing/transactions/${row.id}`),
|
|
136
|
+
isLoading: loading,
|
|
137
|
+
pagination: { page, pageSize, total, totalPages, onPageChange: setPage },
|
|
138
|
+
filters: filterDefs,
|
|
139
|
+
filterValues: filters,
|
|
140
|
+
onFiltersApply: setFilters,
|
|
141
|
+
onFiltersClear: () => setFilters({})
|
|
142
|
+
}
|
|
143
|
+
) }) });
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
BillingTransactionsListPage as default,
|
|
147
|
+
txnVariant
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/billing/backend/billing/transactions/page.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport type { ColumnDef } from '@tanstack/react-table'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { Tag } from '@open-mercato/ui/primitives/tag'\nimport { readApiResultOrThrow } from '@open-mercato/ui/backend/utils/apiCall'\nimport { fetchAccountNames } from '../../../components/accountNames'\n\n/**\n * Balance transactions admin list (SPEC-002). Read-only \u2014 the append-only\n * ledger is written by the command bus (real-time consume, top-up capture,\n * period close, manual adjustment). Each row links to its detail page so an\n * operator can trace a movement back to its source document.\n */\n\ntype TransactionRow = {\n id: string\n bill_account_id: string\n type: string\n amount: string\n currency_code: string\n balance_after: string\n description: string\n created_at: string\n}\n\ntype ListResponse = { items: TransactionRow[]; total: number; totalPages: number }\n\nfunction formatDate(value: string | null | undefined): string {\n if (!value) return '\u2014'\n const d = new Date(value)\n return Number.isNaN(d.getTime()) ? value : d.toLocaleString()\n}\n\nexport function txnVariant(type: string): 'success' | 'info' | 'error' | 'neutral' | 'default' {\n if (type === 'topup' || type === 'adjustment') return 'success'\n if (type === 'usage') return 'info'\n if (type === 'reversal') return 'error'\n return 'neutral' // recurring / one_time\n}\n\nexport default function BillingTransactionsListPage() {\n const t = useT()\n const router = useRouter()\n const [rows, setRows] = React.useState<TransactionRow[]>([])\n const [page, setPage] = React.useState(1)\n const [pageSize] = React.useState(25)\n const [filters, setFilters] = React.useState<FilterValues>({})\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [loading, setLoading] = React.useState(true)\n const [accountNames, setAccountNames] = React.useState<Record<string, string>>({})\n\n const filterDefs = React.useMemo<FilterDef[]>(\n () => [\n {\n id: 'type',\n label: t('billing.transactions.filters.type', 'Type'),\n type: 'select',\n options: [\n { value: 'topup', label: t('billing.transactions.type.topup', 'Top-up') },\n { value: 'usage', label: t('billing.transactions.type.usage', 'Usage') },\n { value: 'recurring', label: t('billing.transactions.type.recurring', 'Recurring') },\n { value: 'one_time', label: t('billing.transactions.type.one_time', 'One-time') },\n { value: 'adjustment', label: t('billing.transactions.type.adjustment', 'Adjustment') },\n { value: 'reversal', label: t('billing.transactions.type.reversal', 'Reversal') },\n ],\n },\n ],\n [t],\n )\n\n const loadRows = React.useCallback(async () => {\n setLoading(true)\n try {\n const params = new URLSearchParams({\n page: String(page),\n pageSize: String(pageSize),\n sortField: 'createdAt',\n sortDir: 'desc',\n })\n if (typeof filters.type === 'string' && filters.type) params.set('type', filters.type)\n const result = await readApiResultOrThrow<ListResponse>(\n `/api/billing/transactions?${params.toString()}`,\n )\n const items = result.items ?? []\n setRows(items)\n setTotal(result.total ?? 0)\n setTotalPages(result.totalPages ?? 1)\n try {\n const names = await fetchAccountNames(items.map((r) => r.bill_account_id))\n setAccountNames((prev) => ({ ...prev, ...names }))\n } catch {\n // Name resolution is best-effort \u2014 fall back to the id in the cell.\n }\n } finally {\n setLoading(false)\n }\n }, [filters.type, page, pageSize])\n\n React.useEffect(() => {\n void loadRows()\n }, [loadRows])\n\n const columns = React.useMemo<ColumnDef<TransactionRow>[]>(\n () => [\n {\n accessorKey: 'created_at',\n header: t('billing.transactions.columns.when', 'When'),\n cell: ({ row }) => formatDate(row.original.created_at),\n },\n {\n accessorKey: 'type',\n header: t('billing.transactions.columns.type', 'Type'),\n cell: ({ row }) => (\n <Tag variant={txnVariant(row.original.type)}>\n {t(`billing.transactions.type.${row.original.type}`, row.original.type)}\n </Tag>\n ),\n },\n {\n accessorKey: 'description',\n header: t('billing.transactions.columns.description', 'Description'),\n cell: ({ row }) => <span className=\"text-sm\">{row.original.description}</span>,\n },\n {\n accessorKey: 'amount',\n header: t('billing.transactions.columns.amount', 'Amount'),\n cell: ({ row }) => (\n <span className=\"font-mono tabular-nums\">\n {row.original.amount} {row.original.currency_code}\n </span>\n ),\n },\n {\n accessorKey: 'balance_after',\n header: t('billing.transactions.columns.balance_after', 'Balance'),\n cell: ({ row }) => (\n <span className=\"font-mono tabular-nums\">{row.original.balance_after}</span>\n ),\n },\n {\n accessorKey: 'bill_account_id',\n header: t('billing.transactions.columns.account', 'Account'),\n cell: ({ row }) => {\n const name = accountNames[row.original.bill_account_id]\n return name ? (\n <span className=\"text-sm\">{name}</span>\n ) : (\n <span className=\"font-mono text-xs\">{row.original.bill_account_id}</span>\n )\n },\n },\n ],\n [t, accountNames],\n )\n\n return (\n <Page>\n <PageBody>\n <DataTable\n title={t('billing.transactions.title', 'Transactions')}\n refreshButton={{\n label: t('billing.common.refresh', 'Refresh'),\n onRefresh: loadRows,\n isRefreshing: loading,\n }}\n columnChooser={{ auto: true }}\n perspective={{ tableId: 'billing-transactions' }}\n columns={columns}\n data={rows}\n onRowClick={(row) => router.push(`/backend/billing/transactions/${row.id}`)}\n isLoading={loading}\n pagination={{ page, pageSize, total, totalPages, onPageChange: setPage }}\n filters={filterDefs}\n filterValues={filters}\n onFiltersApply={setFilters}\n onFiltersClear={() => setFilters({})}\n />\n </PageBody>\n </Page>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAuHU,cAcA,YAdA;AAtHV,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAE1B,SAAS,YAAY;AAErB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,WAAW;AACpB,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAsBlC,SAAS,WAAW,OAA0C;AAC5D,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,IAAI,IAAI,KAAK,KAAK;AACxB,SAAO,OAAO,MAAM,EAAE,QAAQ,CAAC,IAAI,QAAQ,EAAE,eAAe;AAC9D;AAEO,SAAS,WAAW,M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Y,CAAC,QAAQ,OAAO,KAAK,iCAAiC,IAAI,EAAE,EAAE;AAAA,MAC1E,WAAW;AAAA,MACX,YAAY,EAAE,MAAM,UAAU,OAAO,YAAY,cAAc,QAAQ;AAAA,MACvE,SAAS;AAAA,MACT,cAAc;AAAA,MACd,gBAAgB;AAAA,MAChB,gBAAgB,MAAM,WAAW,CAAC,CAAC;AAAA;AAAA,EACrC,GACF,GACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ArrowLeftRight } from "lucide-react";
|
|
3
|
+
const transactionsIcon = React.createElement(ArrowLeftRight, { size: 16 });
|
|
4
|
+
const metadata = {
|
|
5
|
+
requireAuth: true,
|
|
6
|
+
requireFeatures: ["billing.balance.view"],
|
|
7
|
+
pageTitle: "Transactions",
|
|
8
|
+
pageTitleKey: "billing.transactions.title",
|
|
9
|
+
pageGroup: "Billing",
|
|
10
|
+
pageGroupKey: "billing.nav.group",
|
|
11
|
+
pageOrder: 70,
|
|
12
|
+
icon: transactionsIcon,
|
|
13
|
+
breadcrumb: [{ label: "Transactions", labelKey: "billing.transactions.title" }]
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
metadata
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=page.meta.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/modules/billing/backend/billing/transactions/page.meta.ts"],
|
|
4
|
+
"sourcesContent": ["import React from 'react'\nimport { ArrowLeftRight } from 'lucide-react'\n\nconst transactionsIcon = React.createElement(ArrowLeftRight, { size: 16 })\n\nexport const metadata = {\n requireAuth: true,\n requireFeatures: ['billing.balance.view'],\n pageTitle: 'Transactions',\n pageTitleKey: 'billing.transactions.title',\n pageGroup: 'Billing',\n pageGroupKey: 'billing.nav.group',\n pageOrder: 70,\n icon: transactionsIcon,\n breadcrumb: [{ label: 'Transactions', labelKey: 'billing.transactions.title' }],\n} as const\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,sBAAsB;AAE/B,MAAM,mBAAmB,MAAM,cAAc,gBAAgB,EAAE,MAAM,GAAG,CAAC;AAElE,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,CAAC,EAAE,OAAO,gBAAgB,UAAU,6BAA6B,CAAC;AAChF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|