@blocklet/payment-react 1.18.56 → 1.19.1
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/es/checkout/donate.d.ts +1 -15
- package/es/checkout/donate.js +301 -189
- package/es/checkout/form.d.ts +1 -15
- package/es/checkout/form.js +5 -13
- package/es/checkout/table.js +3 -3
- package/es/components/blockchain/gas.d.ts +1 -5
- package/es/components/blockchain/gas.js +10 -2
- package/es/components/blockchain/tx.d.ts +1 -8
- package/es/components/blockchain/tx.js +29 -10
- package/es/components/confirm.d.ts +1 -10
- package/es/components/confirm.js +4 -10
- package/es/components/country-select.d.ts +3 -2
- package/es/components/country-select.js +375 -352
- package/es/components/date-range-picker.d.ts +13 -0
- package/es/components/date-range-picker.js +279 -0
- package/es/components/input.d.ts +14 -20
- package/es/components/input.js +51 -44
- package/es/components/label.d.ts +7 -0
- package/es/components/label.js +49 -0
- package/es/components/lazy-loader.js +1 -2
- package/es/components/link.d.ts +2 -9
- package/es/components/link.js +9 -6
- package/es/components/livemode.d.ts +2 -8
- package/es/components/livemode.js +1 -5
- package/es/components/loading-button.d.ts +6 -1
- package/es/components/loading-button.js +56 -66
- package/es/components/over-due-invoice-payment.d.ts +0 -18
- package/es/components/over-due-invoice-payment.js +138 -95
- package/es/components/payment-beneficiaries.d.ts +2 -7
- package/es/components/payment-beneficiaries.js +86 -40
- package/es/components/pricing-item.d.ts +0 -5
- package/es/components/pricing-item.js +1 -4
- package/es/components/pricing-table.d.ts +2 -10
- package/es/components/pricing-table.js +8 -7
- package/es/components/resume-subscription.d.ts +0 -10
- package/es/components/resume-subscription.js +42 -21
- package/es/components/truncated-text.d.ts +2 -9
- package/es/components/truncated-text.js +0 -5
- package/es/contexts/donate.d.ts +0 -7
- package/es/contexts/donate.js +10 -8
- package/es/contexts/payment.d.ts +1 -4
- package/es/contexts/payment.js +7 -2
- package/es/history/credit/grants-list.d.ts +14 -0
- package/es/history/credit/grants-list.js +215 -0
- package/es/history/credit/transactions-list.d.ts +13 -0
- package/es/history/credit/transactions-list.js +255 -0
- package/es/history/invoice/list.d.ts +2 -18
- package/es/history/invoice/list.js +172 -74
- package/es/history/payment/list.js +115 -38
- package/es/hooks/keyboard.d.ts +1 -1
- package/es/hooks/keyboard.js +2 -4
- package/es/index.d.ts +5 -1
- package/es/index.js +10 -1
- package/es/libs/cached-request.js +2 -4
- package/es/libs/phone-validator.js +1 -2
- package/es/libs/util.d.ts +2 -0
- package/es/libs/util.js +14 -4
- package/es/libs/validator.js +2 -4
- package/es/locales/en.js +20 -2
- package/es/locales/zh.js +20 -2
- package/es/payment/amount.d.ts +2 -7
- package/es/payment/amount.js +1 -5
- package/es/payment/donation-form.d.ts +2 -10
- package/es/payment/donation-form.js +196 -160
- package/es/payment/error.d.ts +2 -8
- package/es/payment/error.js +40 -20
- package/es/payment/footer.d.ts +2 -3
- package/es/payment/footer.js +19 -6
- package/es/payment/form/addon.js +14 -4
- package/es/payment/form/address.d.ts +2 -9
- package/es/payment/form/address.js +3 -6
- package/es/payment/form/currency.js +45 -25
- package/es/payment/form/index.d.ts +2 -8
- package/es/payment/form/index.js +151 -71
- package/es/payment/form/phone.js +2 -4
- package/es/payment/form/stripe/form.d.ts +2 -8
- package/es/payment/form/stripe/form.js +1 -3
- package/es/payment/header.js +38 -16
- package/es/payment/index.d.ts +2 -9
- package/es/payment/index.js +23 -17
- package/es/payment/product-card.d.ts +2 -11
- package/es/payment/product-card.js +84 -50
- package/es/payment/product-donation.js +175 -114
- package/es/payment/product-item.d.ts +9 -9
- package/es/payment/product-item.js +320 -145
- package/es/payment/product-skeleton.js +2 -2
- package/es/payment/skeleton/donation.js +27 -7
- package/es/payment/skeleton/overview.js +22 -2
- package/es/payment/skeleton/payment.js +33 -5
- package/es/payment/success.d.ts +2 -9
- package/es/payment/success.js +41 -14
- package/es/payment/summary.d.ts +4 -17
- package/es/payment/summary.js +193 -111
- package/es/theme/index.d.ts +0 -5
- package/es/theme/index.js +2 -5
- package/es/theme/typography.d.ts +2 -2
- package/lib/checkout/donate.d.ts +1 -15
- package/lib/checkout/donate.js +75 -54
- package/lib/checkout/form.d.ts +1 -15
- package/lib/checkout/form.js +7 -15
- package/lib/checkout/table.js +4 -4
- package/lib/components/blockchain/gas.d.ts +1 -5
- package/lib/components/blockchain/gas.js +3 -2
- package/lib/components/blockchain/tx.d.ts +1 -8
- package/lib/components/blockchain/tx.js +15 -10
- package/lib/components/confirm.d.ts +1 -10
- package/lib/components/confirm.js +5 -11
- package/lib/components/country-select.d.ts +3 -2
- package/lib/components/country-select.js +23 -22
- package/lib/components/date-range-picker.d.ts +13 -0
- package/lib/components/date-range-picker.js +329 -0
- package/lib/components/input.d.ts +14 -20
- package/lib/components/input.js +28 -27
- package/lib/components/label.d.ts +7 -0
- package/lib/components/label.js +60 -0
- package/lib/components/lazy-loader.js +1 -1
- package/lib/components/link.d.ts +2 -9
- package/lib/components/link.js +3 -8
- package/lib/components/livemode.d.ts +2 -8
- package/lib/components/livemode.js +3 -7
- package/lib/components/loading-button.d.ts +6 -1
- package/lib/components/loading-button.js +9 -17
- package/lib/components/over-due-invoice-payment.d.ts +0 -18
- package/lib/components/over-due-invoice-payment.js +31 -33
- package/lib/components/payment-beneficiaries.d.ts +2 -7
- package/lib/components/payment-beneficiaries.js +12 -11
- package/lib/components/pricing-item.d.ts +0 -5
- package/lib/components/pricing-item.js +2 -5
- package/lib/components/pricing-table.d.ts +2 -10
- package/lib/components/pricing-table.js +5 -11
- package/lib/components/resume-subscription.d.ts +0 -10
- package/lib/components/resume-subscription.js +16 -16
- package/lib/components/table.js +1 -1
- package/lib/components/truncated-text.d.ts +2 -9
- package/lib/components/truncated-text.js +1 -6
- package/lib/contexts/donate.d.ts +0 -7
- package/lib/contexts/donate.js +4 -7
- package/lib/contexts/payment.d.ts +1 -4
- package/lib/contexts/payment.js +4 -7
- package/lib/history/credit/grants-list.d.ts +14 -0
- package/lib/history/credit/grants-list.js +277 -0
- package/lib/history/credit/transactions-list.d.ts +13 -0
- package/lib/history/credit/transactions-list.js +301 -0
- package/lib/history/invoice/list.d.ts +2 -18
- package/lib/history/invoice/list.js +73 -37
- package/lib/history/payment/list.js +30 -16
- package/lib/hooks/keyboard.d.ts +1 -1
- package/lib/hooks/mobile.js +1 -1
- package/lib/hooks/subscription.js +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +41 -2
- package/lib/libs/api.js +1 -1
- package/lib/libs/dayjs.js +1 -1
- package/lib/libs/phone-validator.js +0 -2
- package/lib/libs/theme.js +1 -1
- package/lib/libs/util.d.ts +2 -0
- package/lib/libs/util.js +15 -1
- package/lib/libs/validator.js +1 -1
- package/lib/locales/en.js +21 -3
- package/lib/locales/index.js +1 -1
- package/lib/locales/zh.js +21 -3
- package/lib/payment/amount.d.ts +2 -7
- package/lib/payment/amount.js +2 -6
- package/lib/payment/donation-form.d.ts +2 -10
- package/lib/payment/donation-form.js +33 -38
- package/lib/payment/error.d.ts +2 -8
- package/lib/payment/error.js +11 -13
- package/lib/payment/footer.d.ts +2 -3
- package/lib/payment/footer.js +5 -5
- package/lib/payment/form/addon.js +5 -3
- package/lib/payment/form/address.d.ts +2 -9
- package/lib/payment/form/address.js +5 -8
- package/lib/payment/form/currency.js +3 -3
- package/lib/payment/form/index.d.ts +2 -8
- package/lib/payment/form/index.js +64 -21
- package/lib/payment/form/phone.js +1 -1
- package/lib/payment/form/stripe/form.d.ts +2 -8
- package/lib/payment/form/stripe/form.js +3 -6
- package/lib/payment/header.js +8 -4
- package/lib/payment/index.d.ts +2 -9
- package/lib/payment/index.js +27 -18
- package/lib/payment/product-card.d.ts +2 -11
- package/lib/payment/product-card.js +13 -20
- package/lib/payment/product-donation.js +71 -66
- package/lib/payment/product-item.d.ts +9 -9
- package/lib/payment/product-item.js +168 -29
- package/lib/payment/product-skeleton.js +2 -2
- package/lib/payment/skeleton/donation.js +8 -4
- package/lib/payment/skeleton/overview.js +6 -2
- package/lib/payment/skeleton/payment.js +9 -3
- package/lib/payment/success.d.ts +2 -9
- package/lib/payment/success.js +12 -15
- package/lib/payment/summary.d.ts +4 -17
- package/lib/payment/summary.js +53 -45
- package/lib/theme/index.d.ts +0 -5
- package/lib/theme/index.js +2 -5
- package/lib/theme/typography.d.ts +2 -2
- package/package.json +40 -40
- package/src/checkout/donate.tsx +103 -35
- package/src/checkout/form.tsx +5 -14
- package/src/checkout/table.tsx +3 -3
- package/src/components/blockchain/gas.tsx +5 -3
- package/src/components/blockchain/tx.tsx +19 -11
- package/src/components/confirm.tsx +4 -11
- package/src/components/country-select.tsx +391 -378
- package/src/components/date-range-picker.tsx +310 -0
- package/src/components/input.tsx +61 -46
- package/src/components/label.tsx +58 -0
- package/src/components/link.tsx +9 -7
- package/src/components/livemode.tsx +2 -6
- package/src/components/loading-button.tsx +63 -76
- package/src/components/over-due-invoice-payment.tsx +43 -28
- package/src/components/payment-beneficiaries.tsx +33 -14
- package/src/components/pricing-item.tsx +1 -4
- package/src/components/pricing-table.tsx +8 -8
- package/src/components/resume-subscription.tsx +20 -14
- package/src/components/table.tsx +2 -2
- package/src/components/truncated-text.tsx +0 -6
- package/src/contexts/donate.tsx +6 -7
- package/src/contexts/payment.tsx +7 -3
- package/src/history/credit/grants-list.tsx +276 -0
- package/src/history/credit/transactions-list.tsx +317 -0
- package/src/history/invoice/list.tsx +92 -36
- package/src/history/payment/list.tsx +53 -16
- package/src/hooks/keyboard.ts +1 -1
- package/src/index.ts +9 -0
- package/src/libs/util.ts +14 -0
- package/src/locales/en.tsx +20 -0
- package/src/locales/zh.tsx +19 -0
- package/src/payment/amount.tsx +1 -6
- package/src/payment/donation-form.tsx +47 -29
- package/src/payment/error.tsx +16 -8
- package/src/payment/footer.tsx +11 -3
- package/src/payment/form/addon.tsx +6 -1
- package/src/payment/form/address.tsx +3 -7
- package/src/payment/form/currency.tsx +12 -2
- package/src/payment/form/index.tsx +121 -45
- package/src/payment/form/stripe/form.tsx +1 -5
- package/src/payment/header.tsx +14 -2
- package/src/payment/index.tsx +27 -22
- package/src/payment/product-card.tsx +41 -18
- package/src/payment/product-donation.tsx +85 -47
- package/src/payment/product-item.tsx +198 -28
- package/src/payment/product-skeleton.tsx +3 -2
- package/src/payment/skeleton/donation.tsx +12 -2
- package/src/payment/skeleton/overview.tsx +12 -2
- package/src/payment/skeleton/payment.tsx +16 -3
- package/src/payment/success.tsx +26 -15
- package/src/payment/summary.tsx +87 -44
- package/src/theme/index.tsx +5 -8
- package/src/theme/typography.ts +2 -2
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StatusChip = StatusChip;
|
|
7
|
+
module.exports = CreditGrantsList;
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
10
|
+
var _material = require("@mui/material");
|
|
11
|
+
var _ahooks = require("ahooks");
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _reactRouterDom = require("react-router-dom");
|
|
14
|
+
var _system = require("@mui/system");
|
|
15
|
+
var _util = require("../../libs/util");
|
|
16
|
+
var _payment = require("../../contexts/payment");
|
|
17
|
+
var _api = _interopRequireDefault(require("../../libs/api"));
|
|
18
|
+
var _table = _interopRequireDefault(require("../../components/table"));
|
|
19
|
+
var _navigation = require("../../libs/navigation");
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
22
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
23
|
+
const fetchData = (params = {}) => {
|
|
24
|
+
const search = new URLSearchParams();
|
|
25
|
+
Object.keys(params).forEach(key => {
|
|
26
|
+
if (params[key]) {
|
|
27
|
+
search.set(key, String(params[key]));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return _api.default.get(`/api/credit-grants?${search.toString()}`).then(res => res.data);
|
|
31
|
+
};
|
|
32
|
+
function StatusChip({
|
|
33
|
+
status,
|
|
34
|
+
label
|
|
35
|
+
}) {
|
|
36
|
+
const getStatusColor = statusValue => {
|
|
37
|
+
switch (statusValue) {
|
|
38
|
+
case "granted":
|
|
39
|
+
return "success";
|
|
40
|
+
case "pending":
|
|
41
|
+
return "warning";
|
|
42
|
+
case "expired":
|
|
43
|
+
return "default";
|
|
44
|
+
case "depleted":
|
|
45
|
+
return "default";
|
|
46
|
+
case "voided":
|
|
47
|
+
return "default";
|
|
48
|
+
default:
|
|
49
|
+
return "default";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Chip, {
|
|
53
|
+
label: label || status,
|
|
54
|
+
size: "small",
|
|
55
|
+
color: getStatusColor(status)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const getLink = (grant, inDashboard) => {
|
|
59
|
+
let path = `/customer/credit-grant/${grant.id}`;
|
|
60
|
+
if (inDashboard) {
|
|
61
|
+
path = `/admin/customers/${grant.id}`;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
link: (0, _navigation.createLink)(path),
|
|
65
|
+
connect: false
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const GrantsTable = _react.default.memo(props => {
|
|
69
|
+
const {
|
|
70
|
+
pageSize,
|
|
71
|
+
status = "",
|
|
72
|
+
customer_id,
|
|
73
|
+
subscription_id,
|
|
74
|
+
onTableDataChange
|
|
75
|
+
} = props;
|
|
76
|
+
const listKey = "credit-grants-table";
|
|
77
|
+
const {
|
|
78
|
+
t,
|
|
79
|
+
locale
|
|
80
|
+
} = (0, _context.useLocaleContext)();
|
|
81
|
+
const {
|
|
82
|
+
session
|
|
83
|
+
} = (0, _payment.usePaymentContext)();
|
|
84
|
+
const navigate = (0, _reactRouterDom.useNavigate)();
|
|
85
|
+
const isAdmin = ["owner", "admin"].includes(session?.user?.role || "");
|
|
86
|
+
const inDashboard = props.mode === "dashboard" && isAdmin;
|
|
87
|
+
const effectiveCustomerId = customer_id || session?.user?.did;
|
|
88
|
+
const [search, setSearch] = (0, _react.useState)({
|
|
89
|
+
pageSize: pageSize || 10,
|
|
90
|
+
page: 1
|
|
91
|
+
});
|
|
92
|
+
const {
|
|
93
|
+
loading,
|
|
94
|
+
data = {
|
|
95
|
+
list: [],
|
|
96
|
+
count: 0
|
|
97
|
+
}
|
|
98
|
+
} = (0, _ahooks.useRequest)(() => fetchData({
|
|
99
|
+
...search,
|
|
100
|
+
status,
|
|
101
|
+
customer_id: effectiveCustomerId,
|
|
102
|
+
subscription_id
|
|
103
|
+
}), {
|
|
104
|
+
refreshDeps: [search, status, effectiveCustomerId, subscription_id]
|
|
105
|
+
});
|
|
106
|
+
const prevData = (0, _react.useRef)(data);
|
|
107
|
+
const handleLinkClick = (e, grant) => {
|
|
108
|
+
const {
|
|
109
|
+
link
|
|
110
|
+
} = getLink(grant, inDashboard);
|
|
111
|
+
(0, _navigation.handleNavigation)(e, link, navigate, {
|
|
112
|
+
target: link.external ? "_blank" : "_self"
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
(0, _react.useEffect)(() => {
|
|
116
|
+
if (onTableDataChange) {
|
|
117
|
+
onTableDataChange(data, prevData.current);
|
|
118
|
+
prevData.current = data;
|
|
119
|
+
}
|
|
120
|
+
}, [data]);
|
|
121
|
+
const columns = [{
|
|
122
|
+
label: t("common.name"),
|
|
123
|
+
name: "name",
|
|
124
|
+
options: {
|
|
125
|
+
customBodyRenderLite: (_, index) => {
|
|
126
|
+
const grant = data?.list[index];
|
|
127
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
128
|
+
onClick: e => handleLinkClick(e, grant),
|
|
129
|
+
children: grant.name || grant.id
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, {
|
|
134
|
+
label: t("common.status"),
|
|
135
|
+
name: "status",
|
|
136
|
+
options: {
|
|
137
|
+
customBodyRenderLite: (_, index) => {
|
|
138
|
+
const grant = data?.list[index];
|
|
139
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
140
|
+
onClick: e => handleLinkClick(e, grant),
|
|
141
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(StatusChip, {
|
|
142
|
+
status: grant.status,
|
|
143
|
+
label: t(`admin.customer.creditGrants.status.${grant.status}`)
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}, {
|
|
149
|
+
label: t("common.remainingCredit"),
|
|
150
|
+
name: "remaining_amount",
|
|
151
|
+
align: "right",
|
|
152
|
+
options: {
|
|
153
|
+
customBodyRenderLite: (_, index) => {
|
|
154
|
+
const grant = data?.list[index];
|
|
155
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
156
|
+
onClick: e => handleLinkClick(e, grant),
|
|
157
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
158
|
+
variant: "body2",
|
|
159
|
+
children: [(0, _util.formatBNStr)(grant.remaining_amount, grant.paymentCurrency.decimal), " ", grant.paymentCurrency.symbol]
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
label: t("common.scope"),
|
|
166
|
+
name: "scope",
|
|
167
|
+
options: {
|
|
168
|
+
customBodyRenderLite: (_, index) => {
|
|
169
|
+
const grant = data?.list[index];
|
|
170
|
+
let scope = "general";
|
|
171
|
+
if (grant.applicability_config?.scope?.prices) {
|
|
172
|
+
scope = "specific";
|
|
173
|
+
}
|
|
174
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
175
|
+
onClick: e => handleLinkClick(e, grant),
|
|
176
|
+
children: scope === "specific" ? t("common.specific") : t("common.general")
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, {
|
|
181
|
+
label: t("common.effectiveDate"),
|
|
182
|
+
name: "effective_at",
|
|
183
|
+
options: {
|
|
184
|
+
customBodyRenderLite: (_, index) => {
|
|
185
|
+
const grant = data?.list[index];
|
|
186
|
+
const effectiveAt = grant.effective_at ? grant.effective_at * 1e3 : grant.created_at;
|
|
187
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
188
|
+
onClick: e => handleLinkClick(e, grant),
|
|
189
|
+
children: (0, _util.formatToDate)(effectiveAt, locale, "YYYY-MM-DD HH:mm")
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
label: t("common.expirationDate"),
|
|
195
|
+
name: "expires_at",
|
|
196
|
+
options: {
|
|
197
|
+
customBodyRenderLite: (_, index) => {
|
|
198
|
+
const grant = data?.list[index];
|
|
199
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
200
|
+
onClick: e => handleLinkClick(e, grant),
|
|
201
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
202
|
+
variant: "body2",
|
|
203
|
+
children: grant.expires_at ? (0, _util.formatToDate)(grant.expires_at * 1e3, locale, "YYYY-MM-DD HH:mm") : "-"
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}];
|
|
209
|
+
const onTableChange = ({
|
|
210
|
+
page,
|
|
211
|
+
rowsPerPage
|
|
212
|
+
}) => {
|
|
213
|
+
if (search.pageSize !== rowsPerPage) {
|
|
214
|
+
setSearch(x => ({
|
|
215
|
+
...x,
|
|
216
|
+
pageSize: rowsPerPage,
|
|
217
|
+
page: 1
|
|
218
|
+
}));
|
|
219
|
+
} else if (search.page !== page + 1) {
|
|
220
|
+
setSearch(x => ({
|
|
221
|
+
...x,
|
|
222
|
+
page: page + 1
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(TableRoot, {
|
|
227
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_table.default, {
|
|
228
|
+
hasRowLink: true,
|
|
229
|
+
durable: `__${listKey}__`,
|
|
230
|
+
durableKeys: ["page", "rowsPerPage", "searchText"],
|
|
231
|
+
data: data.list,
|
|
232
|
+
columns,
|
|
233
|
+
options: {
|
|
234
|
+
count: data.count,
|
|
235
|
+
page: search.page - 1,
|
|
236
|
+
rowsPerPage: search.pageSize
|
|
237
|
+
},
|
|
238
|
+
loading,
|
|
239
|
+
onChange: onTableChange,
|
|
240
|
+
toolbar: false,
|
|
241
|
+
sx: {
|
|
242
|
+
mt: 2
|
|
243
|
+
},
|
|
244
|
+
showMobile: false,
|
|
245
|
+
mobileTDFlexDirection: "row",
|
|
246
|
+
emptyNodeText: t("admin.creditGrants.noGrants")
|
|
247
|
+
})
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
const TableRoot = (0, _system.styled)(_material.Box)`
|
|
251
|
+
@media (max-width: ${({
|
|
252
|
+
theme
|
|
253
|
+
}) => theme.breakpoints.values.md}px) {
|
|
254
|
+
.MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > td.MuiTableCell-root {
|
|
255
|
+
> div {
|
|
256
|
+
width: fit-content;
|
|
257
|
+
flex: inherit;
|
|
258
|
+
font-size: 14px;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
.invoice-summary {
|
|
262
|
+
padding-right: 20px;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
`;
|
|
266
|
+
function CreditGrantsList(rawProps) {
|
|
267
|
+
const props = Object.assign({
|
|
268
|
+
customer_id: "",
|
|
269
|
+
subscription_id: "",
|
|
270
|
+
status: "granted,pending,depleted,expired",
|
|
271
|
+
pageSize: 10,
|
|
272
|
+
onTableDataChange: () => {}
|
|
273
|
+
}, rawProps);
|
|
274
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(GrantsTable, {
|
|
275
|
+
...props
|
|
276
|
+
});
|
|
277
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
customer_id?: string;
|
|
3
|
+
subscription_id?: string;
|
|
4
|
+
credit_grant_id?: string;
|
|
5
|
+
pageSize?: number;
|
|
6
|
+
onTableDataChange?: Function;
|
|
7
|
+
showAdminColumns?: boolean;
|
|
8
|
+
showTimeFilter?: boolean;
|
|
9
|
+
source?: string;
|
|
10
|
+
mode?: 'dashboard' | 'portal';
|
|
11
|
+
};
|
|
12
|
+
export default function CreditTransactionsList(rawProps: Props): JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = CreditTransactionsList;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
|
+
var _material = require("@mui/material");
|
|
10
|
+
var _ahooks = require("ahooks");
|
|
11
|
+
var _reactRouterDom = require("react-router-dom");
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _ufo = require("ufo");
|
|
14
|
+
var _system = require("@mui/system");
|
|
15
|
+
var _dateRangePicker = _interopRequireDefault(require("../../components/date-range-picker"));
|
|
16
|
+
var _util = require("../../libs/util");
|
|
17
|
+
var _payment = require("../../contexts/payment");
|
|
18
|
+
var _api = _interopRequireDefault(require("../../libs/api"));
|
|
19
|
+
var _table = _interopRequireDefault(require("../../components/table"));
|
|
20
|
+
var _navigation = require("../../libs/navigation");
|
|
21
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
23
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
24
|
+
const fetchData = (params = {}) => {
|
|
25
|
+
const search = new URLSearchParams();
|
|
26
|
+
Object.keys(params).forEach(key => {
|
|
27
|
+
if (params[key]) {
|
|
28
|
+
search.set(key, String(params[key]));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return _api.default.get(`/api/credit-transactions?${search.toString()}`).then(res => res.data);
|
|
32
|
+
};
|
|
33
|
+
const getGrantDetailLink = (grantId, inDashboard) => {
|
|
34
|
+
let path = `/customer/credit-grant/${grantId}`;
|
|
35
|
+
if (inDashboard) {
|
|
36
|
+
path = `/admin/customers/${grantId}`;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
link: (0, _navigation.createLink)(path),
|
|
40
|
+
connect: false
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const TransactionsTable = _react.default.memo(props => {
|
|
44
|
+
const {
|
|
45
|
+
pageSize,
|
|
46
|
+
customer_id,
|
|
47
|
+
subscription_id,
|
|
48
|
+
credit_grant_id,
|
|
49
|
+
onTableDataChange,
|
|
50
|
+
showAdminColumns = false,
|
|
51
|
+
showTimeFilter = false,
|
|
52
|
+
source,
|
|
53
|
+
mode = "portal"
|
|
54
|
+
} = props;
|
|
55
|
+
const listKey = "credit-transactions-table";
|
|
56
|
+
const {
|
|
57
|
+
t,
|
|
58
|
+
locale
|
|
59
|
+
} = (0, _context.useLocaleContext)();
|
|
60
|
+
const {
|
|
61
|
+
session
|
|
62
|
+
} = (0, _payment.usePaymentContext)();
|
|
63
|
+
const isAdmin = ["owner", "admin"].includes(session?.user?.role || "");
|
|
64
|
+
const navigate = (0, _reactRouterDom.useNavigate)();
|
|
65
|
+
const effectiveCustomerId = customer_id || session?.user?.did;
|
|
66
|
+
const [search, setSearch] = (0, _react.useState)({
|
|
67
|
+
pageSize: pageSize || 10,
|
|
68
|
+
page: 1
|
|
69
|
+
});
|
|
70
|
+
const [filters, setFilters] = (0, _react.useState)({
|
|
71
|
+
start: void 0,
|
|
72
|
+
end: void 0
|
|
73
|
+
});
|
|
74
|
+
const handleDateRangeChange = (0, _react.useCallback)(newValue => {
|
|
75
|
+
setFilters(newValue);
|
|
76
|
+
setSearch(prev => ({
|
|
77
|
+
...prev,
|
|
78
|
+
page: 1,
|
|
79
|
+
start: newValue.start || void 0,
|
|
80
|
+
end: newValue.end || void 0
|
|
81
|
+
}));
|
|
82
|
+
}, []);
|
|
83
|
+
const {
|
|
84
|
+
loading,
|
|
85
|
+
data = {
|
|
86
|
+
list: [],
|
|
87
|
+
count: 0
|
|
88
|
+
}
|
|
89
|
+
} = (0, _ahooks.useRequest)(() => fetchData({
|
|
90
|
+
...search,
|
|
91
|
+
customer_id: effectiveCustomerId,
|
|
92
|
+
subscription_id,
|
|
93
|
+
credit_grant_id,
|
|
94
|
+
source
|
|
95
|
+
}), {
|
|
96
|
+
refreshDeps: [search, effectiveCustomerId, subscription_id, credit_grant_id, source]
|
|
97
|
+
});
|
|
98
|
+
(0, _react.useEffect)(() => {
|
|
99
|
+
if (showTimeFilter && !search.start && !search.end) {
|
|
100
|
+
handleDateRangeChange(filters);
|
|
101
|
+
}
|
|
102
|
+
}, [showTimeFilter, handleDateRangeChange, search.start, search.end, filters]);
|
|
103
|
+
const prevData = (0, _react.useRef)(data);
|
|
104
|
+
(0, _react.useEffect)(() => {
|
|
105
|
+
if (onTableDataChange) {
|
|
106
|
+
onTableDataChange(data, prevData.current);
|
|
107
|
+
prevData.current = data;
|
|
108
|
+
}
|
|
109
|
+
}, [data]);
|
|
110
|
+
const columns = [{
|
|
111
|
+
label: t("common.creditAmount"),
|
|
112
|
+
name: "credit_amount",
|
|
113
|
+
align: "right",
|
|
114
|
+
width: 120,
|
|
115
|
+
options: {
|
|
116
|
+
customBodyRenderLite: (_, index) => {
|
|
117
|
+
const transaction = data?.list[index];
|
|
118
|
+
const unit = transaction.meter?.unit || transaction.paymentCurrency.symbol;
|
|
119
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
120
|
+
children: [(0, _util.formatBNStr)(transaction.credit_amount, transaction.paymentCurrency.decimal), " ", unit]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, !credit_grant_id && {
|
|
125
|
+
label: t("common.creditGrant"),
|
|
126
|
+
name: "credit_grant",
|
|
127
|
+
options: {
|
|
128
|
+
customBodyRenderLite: (_, index) => {
|
|
129
|
+
const transaction = data?.list[index];
|
|
130
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
131
|
+
direction: "row",
|
|
132
|
+
spacing: 1,
|
|
133
|
+
onClick: e => {
|
|
134
|
+
const link = getGrantDetailLink(transaction.credit_grant_id, isAdmin && mode === "dashboard");
|
|
135
|
+
(0, _navigation.handleNavigation)(e, link.link, navigate);
|
|
136
|
+
},
|
|
137
|
+
sx: {
|
|
138
|
+
alignItems: "center"
|
|
139
|
+
},
|
|
140
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
141
|
+
variant: "body2",
|
|
142
|
+
sx: {
|
|
143
|
+
color: "text.link",
|
|
144
|
+
cursor: "pointer"
|
|
145
|
+
},
|
|
146
|
+
children: transaction.creditGrant.name || `Grant ${transaction.credit_grant_id.slice(-6)}`
|
|
147
|
+
})
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}, {
|
|
152
|
+
label: t("common.description"),
|
|
153
|
+
name: "subscription",
|
|
154
|
+
options: {
|
|
155
|
+
customBodyRenderLite: (_, index) => {
|
|
156
|
+
const transaction = data?.list[index];
|
|
157
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
158
|
+
variant: "body2",
|
|
159
|
+
children: transaction.subscription?.description || transaction.description
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}, ...(showAdminColumns && isAdmin ? [{
|
|
164
|
+
label: t("common.meterEvent"),
|
|
165
|
+
name: "meter_event",
|
|
166
|
+
options: {
|
|
167
|
+
customBodyRenderLite: (_, index) => {
|
|
168
|
+
const transaction = data?.list[index];
|
|
169
|
+
if (!transaction.meter) {
|
|
170
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
171
|
+
variant: "body2",
|
|
172
|
+
children: "-"
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Link, {
|
|
176
|
+
href: (0, _ufo.joinURL)((0, _util.getPrefix)(), `/admin/billing/${transaction.meter.id}`),
|
|
177
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
178
|
+
variant: "body2",
|
|
179
|
+
sx: {
|
|
180
|
+
color: "text.link"
|
|
181
|
+
},
|
|
182
|
+
children: transaction.meter.event_name
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}] : []), {
|
|
188
|
+
label: t("admin.creditTransactions.transactionDate"),
|
|
189
|
+
name: "created_at",
|
|
190
|
+
options: {
|
|
191
|
+
customBodyRenderLite: (_, index) => {
|
|
192
|
+
const transaction = data?.list[index];
|
|
193
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
194
|
+
variant: "body2",
|
|
195
|
+
children: (0, _util.formatToDate)(transaction.created_at, locale, "YYYY-MM-DD HH:mm:ss")
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}].filter(Boolean);
|
|
200
|
+
const onTableChange = ({
|
|
201
|
+
page,
|
|
202
|
+
rowsPerPage
|
|
203
|
+
}) => {
|
|
204
|
+
if (search.pageSize !== rowsPerPage) {
|
|
205
|
+
setSearch(x => ({
|
|
206
|
+
...x,
|
|
207
|
+
pageSize: rowsPerPage,
|
|
208
|
+
page: 1
|
|
209
|
+
}));
|
|
210
|
+
} else if (search.page !== page + 1) {
|
|
211
|
+
setSearch(x => ({
|
|
212
|
+
...x,
|
|
213
|
+
page: page + 1
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(TableRoot, {
|
|
218
|
+
children: [showTimeFilter && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
219
|
+
sx: {
|
|
220
|
+
my: 2
|
|
221
|
+
},
|
|
222
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
223
|
+
sx: {
|
|
224
|
+
mt: 2
|
|
225
|
+
},
|
|
226
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Grid, {
|
|
227
|
+
container: true,
|
|
228
|
+
spacing: 2,
|
|
229
|
+
sx: {
|
|
230
|
+
alignItems: "center"
|
|
231
|
+
},
|
|
232
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Grid, {
|
|
233
|
+
size: {
|
|
234
|
+
xs: 12,
|
|
235
|
+
sm: 6,
|
|
236
|
+
md: 4
|
|
237
|
+
},
|
|
238
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_dateRangePicker.default, {
|
|
239
|
+
value: filters,
|
|
240
|
+
onChange: handleDateRangeChange,
|
|
241
|
+
size: "small",
|
|
242
|
+
fullWidth: true
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_table.default, {
|
|
248
|
+
hasRowLink: true,
|
|
249
|
+
durable: `__${listKey}__`,
|
|
250
|
+
durableKeys: ["page", "rowsPerPage"],
|
|
251
|
+
data: data.list,
|
|
252
|
+
columns,
|
|
253
|
+
options: {
|
|
254
|
+
count: data.count,
|
|
255
|
+
page: search.page - 1,
|
|
256
|
+
rowsPerPage: search.pageSize
|
|
257
|
+
},
|
|
258
|
+
loading,
|
|
259
|
+
onChange: onTableChange,
|
|
260
|
+
toolbar: false,
|
|
261
|
+
sx: {
|
|
262
|
+
mt: 2
|
|
263
|
+
},
|
|
264
|
+
showMobile: false,
|
|
265
|
+
mobileTDFlexDirection: "row",
|
|
266
|
+
emptyNodeText: t("admin.creditTransactions.noTransactions")
|
|
267
|
+
})]
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
const TableRoot = (0, _system.styled)(_material.Box)`
|
|
271
|
+
@media (max-width: ${({
|
|
272
|
+
theme
|
|
273
|
+
}) => theme.breakpoints.values.md}px) {
|
|
274
|
+
.MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > td.MuiTableCell-root {
|
|
275
|
+
> div {
|
|
276
|
+
width: fit-content;
|
|
277
|
+
flex: inherit;
|
|
278
|
+
font-size: 14px;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
.invoice-summary {
|
|
282
|
+
padding-right: 20px;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
`;
|
|
286
|
+
function CreditTransactionsList(rawProps) {
|
|
287
|
+
const props = Object.assign({
|
|
288
|
+
customer_id: "",
|
|
289
|
+
subscription_id: "",
|
|
290
|
+
credit_grant_id: "",
|
|
291
|
+
source: "",
|
|
292
|
+
pageSize: 10,
|
|
293
|
+
onTableDataChange: () => {},
|
|
294
|
+
showAdminColumns: false,
|
|
295
|
+
showTimeFilter: false,
|
|
296
|
+
mode: "portal"
|
|
297
|
+
}, rawProps);
|
|
298
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(TransactionsTable, {
|
|
299
|
+
...props
|
|
300
|
+
});
|
|
301
|
+
}
|
|
@@ -13,21 +13,5 @@ type Props = {
|
|
|
13
13
|
onTableDataChange?: Function;
|
|
14
14
|
relatedSubscription?: boolean;
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var defaultProps: {
|
|
19
|
-
customer_id: string;
|
|
20
|
-
subscription_id: string;
|
|
21
|
-
currency_id: string;
|
|
22
|
-
include_staking: boolean;
|
|
23
|
-
include_recovered_from: boolean;
|
|
24
|
-
status: string;
|
|
25
|
-
pageSize: number;
|
|
26
|
-
target: string;
|
|
27
|
-
action: string;
|
|
28
|
-
type: string;
|
|
29
|
-
onTableDataChange: () => void;
|
|
30
|
-
relatedSubscription: boolean;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export default CustomerInvoiceList;
|
|
16
|
+
export default function CustomerInvoiceList(rawProps: Props): JSX.Element;
|
|
17
|
+
export {};
|