@blocklet/payment-react 1.13.211 → 1.13.213
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/components/safe-guard.d.ts +3 -0
- package/es/components/safe-guard.js +8 -0
- package/es/history/invoice/list.js +20 -12
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -1
- package/es/util.d.ts +2 -1
- package/es/util.js +5 -2
- package/lib/components/safe-guard.d.ts +3 -0
- package/lib/components/safe-guard.js +16 -0
- package/lib/history/invoice/list.js +39 -21
- package/lib/index.d.ts +2 -1
- package/lib/index.js +8 -0
- package/lib/util.d.ts +2 -1
- package/lib/util.js +7 -2
- package/package.json +3 -3
- package/src/components/safe-guard.tsx +9 -0
- package/src/history/invoice/list.tsx +32 -17
- package/src/index.ts +2 -0
- package/src/util.ts +6 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PAYMENT_KIT_DID, isPaymentKitMounted } from "../util.js";
|
|
2
|
+
export default function SafeGuard({ children }) {
|
|
3
|
+
const mounted = isPaymentKitMounted();
|
|
4
|
+
if (mounted === false) {
|
|
5
|
+
console.warn(`PaymentKit is required to use this feature: https://store.blocklet.dev/blocklets/${PAYMENT_KIT_DID}`);
|
|
6
|
+
}
|
|
7
|
+
return mounted ? children : null;
|
|
8
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
3
|
import { OpenInNewOutlined } from "@mui/icons-material";
|
|
4
|
-
import { Box, Button, CircularProgress, Stack, Typography } from "@mui/material";
|
|
4
|
+
import { Box, Button, CircularProgress, Hidden, Stack, Typography } from "@mui/material";
|
|
5
|
+
import { styled } from "@mui/system";
|
|
5
6
|
import { useInfiniteScroll } from "ahooks";
|
|
6
7
|
import { joinURL } from "ufo";
|
|
7
8
|
import api from "../../api.js";
|
|
@@ -74,7 +75,7 @@ export default function CustomerInvoiceList({
|
|
|
74
75
|
}
|
|
75
76
|
const hasMore = data && data.list.length < data.count;
|
|
76
77
|
const grouped = groupByDate(data.list);
|
|
77
|
-
return /* @__PURE__ */ jsxs(
|
|
78
|
+
return /* @__PURE__ */ jsxs(Root, { direction: "column", gap: 1, sx: { mt: 1 }, children: [
|
|
78
79
|
Object.entries(grouped).map(([date, invoices]) => /* @__PURE__ */ jsxs(Box, { children: [
|
|
79
80
|
/* @__PURE__ */ jsx(Typography, { sx: { fontWeight: "bold", color: "text.secondary", mt: 2, mb: 1 }, children: date }),
|
|
80
81
|
invoices.map((invoice) => {
|
|
@@ -82,10 +83,7 @@ export default function CustomerInvoiceList({
|
|
|
82
83
|
return /* @__PURE__ */ jsxs(
|
|
83
84
|
Stack,
|
|
84
85
|
{
|
|
85
|
-
direction:
|
|
86
|
-
xs: "column",
|
|
87
|
-
sm: "row"
|
|
88
|
-
},
|
|
86
|
+
direction: "row",
|
|
89
87
|
sx: { my: 1 },
|
|
90
88
|
gap: {
|
|
91
89
|
xs: 0.5,
|
|
@@ -94,18 +92,18 @@ export default function CustomerInvoiceList({
|
|
|
94
92
|
},
|
|
95
93
|
flexWrap: "nowrap",
|
|
96
94
|
children: [
|
|
97
|
-
/* @__PURE__ */ jsx(Box, { flex:
|
|
95
|
+
/* @__PURE__ */ jsx(Box, { flex: 2, children: /* @__PURE__ */ jsx("a", { href: link.url, target: link.external ? "_blank" : target, rel: "noreferrer", children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: [
|
|
98
96
|
/* @__PURE__ */ jsx(Typography, { component: "span", children: invoice.number }),
|
|
99
|
-
link.external && /* @__PURE__ */ jsx(OpenInNewOutlined, { fontSize: "small", sx: { color: "text.secondary" } })
|
|
97
|
+
link.external && /* @__PURE__ */ jsx(Hidden, { mdDown: true, children: /* @__PURE__ */ jsx(OpenInNewOutlined, { fontSize: "small", sx: { color: "text.secondary" } }) })
|
|
100
98
|
] }) }) }),
|
|
101
|
-
/* @__PURE__ */ jsx(Box, { flex:
|
|
102
|
-
/* @__PURE__ */ jsx(Box, { flex:
|
|
99
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, textAlign: "right", children: /* @__PURE__ */ jsx(Typography, { children: formatToDate(invoice.created_at, "en", "HH:mm:ss") }) }),
|
|
100
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, textAlign: "right", children: /* @__PURE__ */ jsxs(Typography, { children: [
|
|
103
101
|
formatBNStr(invoice.total, invoice.paymentCurrency.decimal),
|
|
104
102
|
"\xA0",
|
|
105
103
|
invoice.paymentCurrency.symbol
|
|
106
104
|
] }) }),
|
|
107
|
-
/* @__PURE__ */ jsx(Box, { flex:
|
|
108
|
-
/* @__PURE__ */ jsx(Box, { flex:
|
|
105
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, textAlign: "right", children: /* @__PURE__ */ jsx(Status, { label: invoice.status, color: getInvoiceStatusColor(invoice.status) }) }),
|
|
106
|
+
/* @__PURE__ */ jsx(Hidden, { mdDown: true, children: /* @__PURE__ */ jsx(Box, { flex: 2, className: "invoice-description", textAlign: "right", children: /* @__PURE__ */ jsx(Typography, { children: invoice.description || invoice.id }) }) })
|
|
109
107
|
]
|
|
110
108
|
},
|
|
111
109
|
invoice.id
|
|
@@ -127,3 +125,13 @@ CustomerInvoiceList.defaultProps = {
|
|
|
127
125
|
target: "_self",
|
|
128
126
|
action: ""
|
|
129
127
|
};
|
|
128
|
+
const Root = styled(Stack)`
|
|
129
|
+
@media (max-width: 600px) {
|
|
130
|
+
.invoice-description {
|
|
131
|
+
display: none !important;
|
|
132
|
+
}
|
|
133
|
+
svg[data-testid='OpenInNewOutlinedIcon'] {
|
|
134
|
+
display: none !important;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
`;
|
package/es/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import ConfirmDialog from './components/confirm';
|
|
|
7
7
|
import FormInput from './components/input';
|
|
8
8
|
import Livemode from './components/livemode';
|
|
9
9
|
import PricingTable from './components/pricing-table';
|
|
10
|
+
import SafeGuard from './components/safe-guard';
|
|
10
11
|
import Status from './components/status';
|
|
11
12
|
import Switch from './components/switch-button';
|
|
12
13
|
import dayjs from './dayjs';
|
|
@@ -24,4 +25,4 @@ import PaymentSummary from './payment/summary';
|
|
|
24
25
|
export * from './util';
|
|
25
26
|
export * from './contexts/payment';
|
|
26
27
|
export { translations, createTranslator } from './locales';
|
|
27
|
-
export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, };
|
|
28
|
+
export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, SafeGuard, };
|
package/es/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import ConfirmDialog from "./components/confirm.js";
|
|
|
7
7
|
import FormInput from "./components/input.js";
|
|
8
8
|
import Livemode from "./components/livemode.js";
|
|
9
9
|
import PricingTable from "./components/pricing-table.js";
|
|
10
|
+
import SafeGuard from "./components/safe-guard.js";
|
|
10
11
|
import Status from "./components/status.js";
|
|
11
12
|
import Switch from "./components/switch-button.js";
|
|
12
13
|
import dayjs from "./dayjs.js";
|
|
@@ -47,5 +48,6 @@ export {
|
|
|
47
48
|
CustomerInvoiceList,
|
|
48
49
|
CustomerPaymentList,
|
|
49
50
|
MiniInvoiceList,
|
|
50
|
-
TxLink
|
|
51
|
+
TxLink,
|
|
52
|
+
SafeGuard
|
|
51
53
|
};
|
package/es/util.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { PaymentDetails, PriceCurrency, PriceRecurring, TLineItemExpanded, TPaymentCurrency, TPaymentMethod, TPaymentMethodExpanded, TPrice, TSubscriptionExpanded, TSubscriptionItemExpanded } from '@blocklet/payment-types';
|
|
3
3
|
export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
4
|
+
export declare const isPaymentKitMounted: () => any;
|
|
4
5
|
export declare const getPrefix: () => any;
|
|
5
|
-
export declare function formatToDate(date: Date | string | number, locale?: string): any;
|
|
6
|
+
export declare function formatToDate(date: Date | string | number, locale?: string, format?: string): any;
|
|
6
7
|
export declare function formatToDatetime(date: Date | string | number, locale?: string): any;
|
|
7
8
|
export declare function formatTime(date: Date | string | number, format?: string, locale?: string): any;
|
|
8
9
|
export declare function formatDateTime(date: Date | string | number, locale?: string): any;
|
package/es/util.js
CHANGED
|
@@ -6,6 +6,9 @@ import { joinURL } from "ufo";
|
|
|
6
6
|
import dayjs from "./dayjs.js";
|
|
7
7
|
import { t } from "./locales/index.js";
|
|
8
8
|
export const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
9
|
+
export const isPaymentKitMounted = () => {
|
|
10
|
+
return (window.blocklet?.componentMountPoints || []).some((x) => x.did === PAYMENT_KIT_DID);
|
|
11
|
+
};
|
|
9
12
|
export const getPrefix = () => {
|
|
10
13
|
const componentId = (window?.blocklet?.componentId || "").split("/").pop();
|
|
11
14
|
if (componentId === PAYMENT_KIT_DID) {
|
|
@@ -17,11 +20,11 @@ export const getPrefix = () => {
|
|
|
17
20
|
}
|
|
18
21
|
return window.blocklet?.prefix;
|
|
19
22
|
};
|
|
20
|
-
export function formatToDate(date, locale = "en") {
|
|
23
|
+
export function formatToDate(date, locale = "en", format = "YYYY-MM-DD HH:mm:ss") {
|
|
21
24
|
if (!date) {
|
|
22
25
|
return "-";
|
|
23
26
|
}
|
|
24
|
-
return dayjs(date).locale(formatLocale(locale)).format(
|
|
27
|
+
return dayjs(date).locale(formatLocale(locale)).format(format);
|
|
25
28
|
}
|
|
26
29
|
export function formatToDatetime(date, locale = "en") {
|
|
27
30
|
if (!date) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = SafeGuard;
|
|
7
|
+
var _util = require("../util");
|
|
8
|
+
function SafeGuard({
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
const mounted = (0, _util.isPaymentKitMounted)();
|
|
12
|
+
if (mounted === false) {
|
|
13
|
+
console.warn(`PaymentKit is required to use this feature: https://store.blocklet.dev/blocklets/${_util.PAYMENT_KIT_DID}`);
|
|
14
|
+
}
|
|
15
|
+
return mounted ? children : null;
|
|
16
|
+
}
|
|
@@ -8,6 +8,7 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
8
8
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
9
|
var _iconsMaterial = require("@mui/icons-material");
|
|
10
10
|
var _material = require("@mui/material");
|
|
11
|
+
var _system = require("@mui/system");
|
|
11
12
|
var _ahooks = require("ahooks");
|
|
12
13
|
var _ufo = require("ufo");
|
|
13
14
|
var _api = _interopRequireDefault(require("../../api"));
|
|
@@ -103,7 +104,7 @@ function CustomerInvoiceList({
|
|
|
103
104
|
}
|
|
104
105
|
const hasMore = data && data.list.length < data.count;
|
|
105
106
|
const grouped = groupByDate(data.list);
|
|
106
|
-
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(
|
|
107
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Root, {
|
|
107
108
|
direction: "column",
|
|
108
109
|
gap: 1,
|
|
109
110
|
sx: {
|
|
@@ -121,10 +122,7 @@ function CustomerInvoiceList({
|
|
|
121
122
|
}), invoices.map(invoice => {
|
|
122
123
|
const link = getInvoiceLink(invoice, action);
|
|
123
124
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
124
|
-
direction:
|
|
125
|
-
xs: "column",
|
|
126
|
-
sm: "row"
|
|
127
|
-
},
|
|
125
|
+
direction: "row",
|
|
128
126
|
sx: {
|
|
129
127
|
my: 1
|
|
130
128
|
},
|
|
@@ -135,7 +133,7 @@ function CustomerInvoiceList({
|
|
|
135
133
|
},
|
|
136
134
|
flexWrap: "nowrap",
|
|
137
135
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
138
|
-
flex:
|
|
136
|
+
flex: 2,
|
|
139
137
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
|
|
140
138
|
href: link.url,
|
|
141
139
|
target: link.external ? "_blank" : target,
|
|
@@ -147,35 +145,45 @@ function CustomerInvoiceList({
|
|
|
147
145
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
148
146
|
component: "span",
|
|
149
147
|
children: invoice.number
|
|
150
|
-
}), link.external && /* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
}), link.external && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Hidden, {
|
|
149
|
+
mdDown: true,
|
|
150
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.OpenInNewOutlined, {
|
|
151
|
+
fontSize: "small",
|
|
152
|
+
sx: {
|
|
153
|
+
color: "text.secondary"
|
|
154
|
+
}
|
|
155
|
+
})
|
|
155
156
|
})]
|
|
156
157
|
})
|
|
157
158
|
})
|
|
158
159
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
159
|
-
flex:
|
|
160
|
+
flex: 1,
|
|
161
|
+
textAlign: "right",
|
|
160
162
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
161
|
-
children: (0, _util.formatToDate)(invoice.created_at)
|
|
163
|
+
children: (0, _util.formatToDate)(invoice.created_at, "en", "HH:mm:ss")
|
|
162
164
|
})
|
|
163
165
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
164
|
-
flex:
|
|
166
|
+
flex: 1,
|
|
167
|
+
textAlign: "right",
|
|
165
168
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
166
|
-
textAlign: "right",
|
|
167
169
|
children: [(0, _util.formatBNStr)(invoice.total, invoice.paymentCurrency.decimal), "\xA0", invoice.paymentCurrency.symbol]
|
|
168
170
|
})
|
|
169
171
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
170
|
-
flex:
|
|
172
|
+
flex: 1,
|
|
173
|
+
textAlign: "right",
|
|
171
174
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
|
|
172
175
|
label: invoice.status,
|
|
173
176
|
color: (0, _util.getInvoiceStatusColor)(invoice.status)
|
|
174
177
|
})
|
|
175
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.
|
|
176
|
-
|
|
177
|
-
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.
|
|
178
|
-
|
|
178
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Hidden, {
|
|
179
|
+
mdDown: true,
|
|
180
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
181
|
+
flex: 2,
|
|
182
|
+
className: "invoice-description",
|
|
183
|
+
textAlign: "right",
|
|
184
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
185
|
+
children: invoice.description || invoice.id
|
|
186
|
+
})
|
|
179
187
|
})
|
|
180
188
|
})]
|
|
181
189
|
}, invoice.id);
|
|
@@ -209,4 +217,14 @@ CustomerInvoiceList.defaultProps = {
|
|
|
209
217
|
pageSize: 10,
|
|
210
218
|
target: "_self",
|
|
211
219
|
action: ""
|
|
212
|
-
};
|
|
220
|
+
};
|
|
221
|
+
const Root = (0, _system.styled)(_material.Stack)`
|
|
222
|
+
@media (max-width: 600px) {
|
|
223
|
+
.invoice-description {
|
|
224
|
+
display: none !important;
|
|
225
|
+
}
|
|
226
|
+
svg[data-testid='OpenInNewOutlinedIcon'] {
|
|
227
|
+
display: none !important;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
`;
|
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import ConfirmDialog from './components/confirm';
|
|
|
7
7
|
import FormInput from './components/input';
|
|
8
8
|
import Livemode from './components/livemode';
|
|
9
9
|
import PricingTable from './components/pricing-table';
|
|
10
|
+
import SafeGuard from './components/safe-guard';
|
|
10
11
|
import Status from './components/status';
|
|
11
12
|
import Switch from './components/switch-button';
|
|
12
13
|
import dayjs from './dayjs';
|
|
@@ -24,4 +25,4 @@ import PaymentSummary from './payment/summary';
|
|
|
24
25
|
export * from './util';
|
|
25
26
|
export * from './contexts/payment';
|
|
26
27
|
export { translations, createTranslator } from './locales';
|
|
27
|
-
export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, };
|
|
28
|
+
export { api, dayjs, FormInput, PhoneInput, AddressForm, StripeForm, Status, Livemode, Switch, ConfirmDialog, CheckoutForm, CheckoutTable, CheckoutDonate, CurrencySelector, Payment, PaymentSummary, PricingTable, ProductSkeleton, Amount, CustomerInvoiceList, CustomerPaymentList, MiniInvoiceList, TxLink, SafeGuard, };
|
package/lib/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var _exportNames = {
|
|
|
13
13
|
FormInput: true,
|
|
14
14
|
Livemode: true,
|
|
15
15
|
PricingTable: true,
|
|
16
|
+
SafeGuard: true,
|
|
16
17
|
Status: true,
|
|
17
18
|
Switch: true,
|
|
18
19
|
dayjs: true,
|
|
@@ -132,6 +133,12 @@ Object.defineProperty(exports, "ProductSkeleton", {
|
|
|
132
133
|
return _productSkeleton.default;
|
|
133
134
|
}
|
|
134
135
|
});
|
|
136
|
+
Object.defineProperty(exports, "SafeGuard", {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function () {
|
|
139
|
+
return _safeGuard.default;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
135
142
|
Object.defineProperty(exports, "Status", {
|
|
136
143
|
enumerable: true,
|
|
137
144
|
get: function () {
|
|
@@ -189,6 +196,7 @@ var _confirm = _interopRequireDefault(require("./components/confirm"));
|
|
|
189
196
|
var _input = _interopRequireDefault(require("./components/input"));
|
|
190
197
|
var _livemode = _interopRequireDefault(require("./components/livemode"));
|
|
191
198
|
var _pricingTable = _interopRequireDefault(require("./components/pricing-table"));
|
|
199
|
+
var _safeGuard = _interopRequireDefault(require("./components/safe-guard"));
|
|
192
200
|
var _status = _interopRequireDefault(require("./components/status"));
|
|
193
201
|
var _switchButton = _interopRequireDefault(require("./components/switch-button"));
|
|
194
202
|
var _dayjs = _interopRequireDefault(require("./dayjs"));
|
package/lib/util.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { PaymentDetails, PriceCurrency, PriceRecurring, TLineItemExpanded, TPaymentCurrency, TPaymentMethod, TPaymentMethodExpanded, TPrice, TSubscriptionExpanded, TSubscriptionItemExpanded } from '@blocklet/payment-types';
|
|
3
3
|
export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
4
|
+
export declare const isPaymentKitMounted: () => any;
|
|
4
5
|
export declare const getPrefix: () => any;
|
|
5
|
-
export declare function formatToDate(date: Date | string | number, locale?: string): any;
|
|
6
|
+
export declare function formatToDate(date: Date | string | number, locale?: string, format?: string): any;
|
|
6
7
|
export declare function formatToDatetime(date: Date | string | number, locale?: string): any;
|
|
7
8
|
export declare function formatTime(date: Date | string | number, format?: string, locale?: string): any;
|
|
8
9
|
export declare function formatDateTime(date: Date | string | number, locale?: string): any;
|
package/lib/util.js
CHANGED
|
@@ -35,6 +35,7 @@ exports.getSubscriptionAction = void 0;
|
|
|
35
35
|
exports.getSubscriptionStatusColor = getSubscriptionStatusColor;
|
|
36
36
|
exports.getTxLink = exports.getSubscriptionTimeSummary = void 0;
|
|
37
37
|
exports.getWebhookStatusColor = getWebhookStatusColor;
|
|
38
|
+
exports.isPaymentKitMounted = void 0;
|
|
38
39
|
exports.isValidCountry = isValidCountry;
|
|
39
40
|
exports.mergeExtraParams = void 0;
|
|
40
41
|
exports.sleep = sleep;
|
|
@@ -48,6 +49,10 @@ var _dayjs = _interopRequireDefault(require("./dayjs"));
|
|
|
48
49
|
var _locales = require("./locales");
|
|
49
50
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
50
51
|
const PAYMENT_KIT_DID = exports.PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
52
|
+
const isPaymentKitMounted = () => {
|
|
53
|
+
return (window.blocklet?.componentMountPoints || []).some(x => x.did === PAYMENT_KIT_DID);
|
|
54
|
+
};
|
|
55
|
+
exports.isPaymentKitMounted = isPaymentKitMounted;
|
|
51
56
|
const getPrefix = () => {
|
|
52
57
|
const componentId = (window?.blocklet?.componentId || "").split("/").pop();
|
|
53
58
|
if (componentId === PAYMENT_KIT_DID) {
|
|
@@ -60,11 +65,11 @@ const getPrefix = () => {
|
|
|
60
65
|
return window.blocklet?.prefix;
|
|
61
66
|
};
|
|
62
67
|
exports.getPrefix = getPrefix;
|
|
63
|
-
function formatToDate(date, locale = "en") {
|
|
68
|
+
function formatToDate(date, locale = "en", format = "YYYY-MM-DD HH:mm:ss") {
|
|
64
69
|
if (!date) {
|
|
65
70
|
return "-";
|
|
66
71
|
}
|
|
67
|
-
return (0, _dayjs.default)(date).locale(formatLocale(locale)).format(
|
|
72
|
+
return (0, _dayjs.default)(date).locale(formatLocale(locale)).format(format);
|
|
68
73
|
}
|
|
69
74
|
function formatToDatetime(date, locale = "en") {
|
|
70
75
|
if (!date) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.213",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"@babel/core": "^7.23.9",
|
|
91
91
|
"@babel/preset-env": "^7.23.9",
|
|
92
92
|
"@babel/preset-react": "^7.23.3",
|
|
93
|
-
"@blocklet/payment-types": "1.13.
|
|
93
|
+
"@blocklet/payment-types": "1.13.213",
|
|
94
94
|
"@storybook/addon-essentials": "^7.6.13",
|
|
95
95
|
"@storybook/addon-interactions": "^7.6.13",
|
|
96
96
|
"@storybook/addon-links": "^7.6.13",
|
|
@@ -119,5 +119,5 @@
|
|
|
119
119
|
"vite-plugin-babel": "^1.2.0",
|
|
120
120
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
121
121
|
},
|
|
122
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "209467c5da3ab2fa17f5ce802bcd8b086e7c08e5"
|
|
123
123
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PAYMENT_KIT_DID, isPaymentKitMounted } from '../util';
|
|
2
|
+
|
|
3
|
+
export default function SafeGuard({ children }: { children: any }) {
|
|
4
|
+
const mounted = isPaymentKitMounted();
|
|
5
|
+
if (mounted === false) {
|
|
6
|
+
console.warn(`PaymentKit is required to use this feature: https://store.blocklet.dev/blocklets/${PAYMENT_KIT_DID}`);
|
|
7
|
+
}
|
|
8
|
+
return mounted ? children : null;
|
|
9
|
+
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
3
3
|
import type { Paginated, TInvoiceExpanded, TSubscription } from '@blocklet/payment-types';
|
|
4
4
|
import { OpenInNewOutlined } from '@mui/icons-material';
|
|
5
|
-
import { Box, Button, CircularProgress, Stack, Typography } from '@mui/material';
|
|
5
|
+
import { Box, Button, CircularProgress, Hidden, Stack, Typography } from '@mui/material';
|
|
6
|
+
import { styled } from '@mui/system';
|
|
6
7
|
import { useInfiniteScroll } from 'ahooks';
|
|
7
8
|
import { joinURL } from 'ufo';
|
|
8
9
|
|
|
@@ -109,7 +110,7 @@ export default function CustomerInvoiceList({
|
|
|
109
110
|
const grouped = groupByDate(data.list as any);
|
|
110
111
|
|
|
111
112
|
return (
|
|
112
|
-
<
|
|
113
|
+
<Root direction="column" gap={1} sx={{ mt: 1 }}>
|
|
113
114
|
{Object.entries(grouped).map(([date, invoices]) => (
|
|
114
115
|
<Box key={date}>
|
|
115
116
|
<Typography sx={{ fontWeight: 'bold', color: 'text.secondary', mt: 2, mb: 1 }}>{date}</Typography>
|
|
@@ -118,10 +119,7 @@ export default function CustomerInvoiceList({
|
|
|
118
119
|
return (
|
|
119
120
|
<Stack
|
|
120
121
|
key={invoice.id}
|
|
121
|
-
direction=
|
|
122
|
-
xs: 'column',
|
|
123
|
-
sm: 'row',
|
|
124
|
-
}}
|
|
122
|
+
direction="row"
|
|
125
123
|
sx={{ my: 1 }}
|
|
126
124
|
gap={{
|
|
127
125
|
xs: 0.5,
|
|
@@ -129,29 +127,35 @@ export default function CustomerInvoiceList({
|
|
|
129
127
|
md: 3,
|
|
130
128
|
}}
|
|
131
129
|
flexWrap="nowrap">
|
|
132
|
-
<Box flex={
|
|
130
|
+
<Box flex={2}>
|
|
133
131
|
<a href={link.url} target={link.external ? '_blank' : target} rel="noreferrer">
|
|
134
132
|
<Stack direction="row" alignItems="center" spacing={0.5}>
|
|
135
133
|
<Typography component="span">{invoice.number}</Typography>
|
|
136
|
-
{link.external &&
|
|
134
|
+
{link.external && (
|
|
135
|
+
<Hidden mdDown>
|
|
136
|
+
<OpenInNewOutlined fontSize="small" sx={{ color: 'text.secondary' }} />
|
|
137
|
+
</Hidden>
|
|
138
|
+
)}
|
|
137
139
|
</Stack>
|
|
138
140
|
</a>
|
|
139
141
|
</Box>
|
|
140
|
-
<Box flex={
|
|
141
|
-
<Typography>{formatToDate(invoice.created_at)}</Typography>
|
|
142
|
+
<Box flex={1} textAlign="right">
|
|
143
|
+
<Typography>{formatToDate(invoice.created_at, 'en', 'HH:mm:ss')}</Typography>
|
|
142
144
|
</Box>
|
|
143
|
-
<Box flex={
|
|
144
|
-
<Typography
|
|
145
|
+
<Box flex={1} textAlign="right">
|
|
146
|
+
<Typography>
|
|
145
147
|
{formatBNStr(invoice.total, invoice.paymentCurrency.decimal)}
|
|
146
148
|
{invoice.paymentCurrency.symbol}
|
|
147
149
|
</Typography>
|
|
148
150
|
</Box>
|
|
149
|
-
<Box flex={
|
|
151
|
+
<Box flex={1} textAlign="right">
|
|
150
152
|
<Status label={invoice.status} color={getInvoiceStatusColor(invoice.status)} />
|
|
151
153
|
</Box>
|
|
152
|
-
<
|
|
153
|
-
<
|
|
154
|
-
|
|
154
|
+
<Hidden mdDown>
|
|
155
|
+
<Box flex={2} className="invoice-description" textAlign="right">
|
|
156
|
+
<Typography>{invoice.description || invoice.id}</Typography>
|
|
157
|
+
</Box>
|
|
158
|
+
</Hidden>
|
|
155
159
|
</Stack>
|
|
156
160
|
);
|
|
157
161
|
})}
|
|
@@ -171,7 +175,7 @@ export default function CustomerInvoiceList({
|
|
|
171
175
|
</Typography>
|
|
172
176
|
)}
|
|
173
177
|
</Box>
|
|
174
|
-
</
|
|
178
|
+
</Root>
|
|
175
179
|
);
|
|
176
180
|
}
|
|
177
181
|
|
|
@@ -184,3 +188,14 @@ CustomerInvoiceList.defaultProps = {
|
|
|
184
188
|
target: '_self',
|
|
185
189
|
action: '',
|
|
186
190
|
};
|
|
191
|
+
|
|
192
|
+
const Root = styled(Stack)`
|
|
193
|
+
@media (max-width: 600px) {
|
|
194
|
+
.invoice-description {
|
|
195
|
+
display: none !important;
|
|
196
|
+
}
|
|
197
|
+
svg[data-testid='OpenInNewOutlinedIcon'] {
|
|
198
|
+
display: none !important;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
`;
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import ConfirmDialog from './components/confirm';
|
|
|
7
7
|
import FormInput from './components/input';
|
|
8
8
|
import Livemode from './components/livemode';
|
|
9
9
|
import PricingTable from './components/pricing-table';
|
|
10
|
+
import SafeGuard from './components/safe-guard';
|
|
10
11
|
import Status from './components/status';
|
|
11
12
|
import Switch from './components/switch-button';
|
|
12
13
|
import dayjs from './dayjs';
|
|
@@ -51,4 +52,5 @@ export {
|
|
|
51
52
|
CustomerPaymentList,
|
|
52
53
|
MiniInvoiceList,
|
|
53
54
|
TxLink,
|
|
55
|
+
SafeGuard,
|
|
54
56
|
};
|
package/src/util.ts
CHANGED
|
@@ -23,6 +23,10 @@ import { t } from './locales';
|
|
|
23
23
|
|
|
24
24
|
export const PAYMENT_KIT_DID = 'z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk';
|
|
25
25
|
|
|
26
|
+
export const isPaymentKitMounted = () => {
|
|
27
|
+
return (window.blocklet?.componentMountPoints || []).some((x: any) => x.did === PAYMENT_KIT_DID);
|
|
28
|
+
};
|
|
29
|
+
|
|
26
30
|
export const getPrefix = () => {
|
|
27
31
|
const componentId = (window?.blocklet?.componentId || '').split('/').pop();
|
|
28
32
|
if (componentId === PAYMENT_KIT_DID) {
|
|
@@ -36,12 +40,12 @@ export const getPrefix = () => {
|
|
|
36
40
|
return window.blocklet?.prefix;
|
|
37
41
|
};
|
|
38
42
|
|
|
39
|
-
export function formatToDate(date: Date | string | number, locale = 'en') {
|
|
43
|
+
export function formatToDate(date: Date | string | number, locale = 'en', format = 'YYYY-MM-DD HH:mm:ss') {
|
|
40
44
|
if (!date) {
|
|
41
45
|
return '-';
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
return dayjs(date).locale(formatLocale(locale)).format(
|
|
48
|
+
return dayjs(date).locale(formatLocale(locale)).format(format);
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
export function formatToDatetime(date: Date | string | number, locale = 'en') {
|