@blocklet/payment-react 1.18.11 → 1.18.13

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.
@@ -12,7 +12,7 @@ var _material = require("@mui/material");
12
12
  var _system = require("@mui/system");
13
13
  var _ahooks = require("ahooks");
14
14
  var _react = _interopRequireWildcard(require("react"));
15
- var _ufo = require("ufo");
15
+ var _reactRouterDom = require("react-router-dom");
16
16
  var _debounce = _interopRequireDefault(require("lodash/debounce"));
17
17
  var _status = _interopRequireDefault(require("../../components/status"));
18
18
  var _payment = require("../../contexts/payment");
@@ -20,6 +20,7 @@ var _subscription = require("../../hooks/subscription");
20
20
  var _api = _interopRequireDefault(require("../../libs/api"));
21
21
  var _util = require("../../libs/util");
22
22
  var _table = _interopRequireDefault(require("../../components/table"));
23
+ var _navigation = require("../../libs/navigation");
23
24
  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); }
24
25
  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 && Object.prototype.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; }
25
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -45,18 +46,20 @@ const fetchData = (params = {}) => {
45
46
  };
46
47
  const getInvoiceLink = (invoice, action) => {
47
48
  if (invoice.id.startsWith("in_")) {
49
+ const path = `/customer/invoice/${invoice.id}${invoice.status === "uncollectible" && action ? `?action=${action}` : ""}`;
48
50
  return {
49
- external: false,
50
51
  connect: invoice.status === "uncollectible",
51
- url: (0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/invoice/${invoice.id}?action=${invoice.status === "uncollectible" ? action : ""}`)
52
+ link: (0, _navigation.createLink)(path)
52
53
  };
53
54
  }
54
55
  return {
55
- external: true,
56
56
  connect: false,
57
- url: (0, _util.getTxLink)(invoice.paymentMethod, invoice.metadata?.payment_details).link
57
+ link: (0, _navigation.createLink)((0, _util.getTxLink)(invoice.paymentMethod, invoice.metadata?.payment_details).link, true)
58
58
  };
59
59
  };
60
+ const linkStyle = {
61
+ cursor: "pointer"
62
+ };
60
63
  const InvoiceTable = _react.default.memo(props => {
61
64
  const {
62
65
  pageSize,
@@ -77,6 +80,7 @@ const InvoiceTable = _react.default.memo(props => {
77
80
  t,
78
81
  locale
79
82
  } = (0, _context.useLocaleContext)();
83
+ const navigate = (0, _reactRouterDom.useNavigate)();
80
84
  const [search, setSearch] = (0, _react.useState)({
81
85
  pageSize: pageSize || 10,
82
86
  page: 1
@@ -129,6 +133,14 @@ const InvoiceTable = _react.default.memo(props => {
129
133
  });
130
134
  }
131
135
  }, [subscription]);
136
+ const handleLinkClick = (e, invoice) => {
137
+ const {
138
+ link
139
+ } = getInvoiceLink(invoice, action);
140
+ (0, _navigation.handleNavigation)(e, link, navigate, {
141
+ target: link.external ? "_blank" : target
142
+ });
143
+ };
132
144
  const columns = [{
133
145
  label: t("common.amount"),
134
146
  name: "total",
@@ -137,11 +149,9 @@ const InvoiceTable = _react.default.memo(props => {
137
149
  options: {
138
150
  customBodyRenderLite: (_, index) => {
139
151
  const invoice = data?.list[index];
140
- const link = getInvoiceLink(invoice, action);
141
- return /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
142
- href: link.url,
143
- target: link.external ? "_blank" : target,
144
- rel: "noreferrer",
152
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
153
+ onClick: e => handleLinkClick(e, invoice),
154
+ sx: linkStyle,
145
155
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
146
156
  children: [(0, _util.formatBNStr)(invoice.total, invoice.paymentCurrency.decimal), "\xA0", invoice.paymentCurrency.symbol]
147
157
  })
@@ -154,11 +164,9 @@ const InvoiceTable = _react.default.memo(props => {
154
164
  options: {
155
165
  customBodyRenderLite: (_, index) => {
156
166
  const invoice = data.list[index];
157
- const link = getInvoiceLink(invoice, action);
158
- return /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
159
- href: link.url,
160
- target: link.external ? "_blank" : target,
161
- rel: "noreferrer",
167
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
168
+ onClick: e => handleLinkClick(e, invoice),
169
+ sx: linkStyle,
162
170
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
163
171
  label: (0, _util.getInvoiceDescriptionAndReason)(invoice, locale)?.type
164
172
  })
@@ -171,11 +179,9 @@ const InvoiceTable = _react.default.memo(props => {
171
179
  options: {
172
180
  customBodyRenderLite: (_, index) => {
173
181
  const invoice = data?.list[index];
174
- const link = getInvoiceLink(invoice, action);
175
- return /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
176
- href: link.url,
177
- target: link.external ? "_blank" : target,
178
- rel: "noreferrer",
182
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
183
+ onClick: e => handleLinkClick(e, invoice),
184
+ sx: linkStyle,
179
185
  children: invoice?.number
180
186
  });
181
187
  }
@@ -186,11 +192,9 @@ const InvoiceTable = _react.default.memo(props => {
186
192
  options: {
187
193
  customBodyRenderLite: (val, index) => {
188
194
  const invoice = data?.list[index];
189
- const link = getInvoiceLink(invoice, action);
190
- return /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
191
- href: link.url,
192
- target: link.external ? "_blank" : target,
193
- rel: "noreferrer",
195
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
196
+ onClick: e => handleLinkClick(e, invoice),
197
+ sx: linkStyle,
194
198
  children: (0, _util.formatToDate)(invoice.created_at, locale, "YYYY-MM-DD HH:mm:ss")
195
199
  });
196
200
  }
@@ -202,11 +206,9 @@ const InvoiceTable = _react.default.memo(props => {
202
206
  sort: false,
203
207
  customBodyRenderLite: (val, index) => {
204
208
  const invoice = data?.list[index];
205
- const link = getInvoiceLink(invoice, action);
206
- return /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
207
- href: link.url,
208
- target: link.external ? "_blank" : target,
209
- rel: "noreferrer",
209
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
210
+ onClick: e => handleLinkClick(e, invoice),
211
+ sx: linkStyle,
210
212
  children: (0, _util.getInvoiceDescriptionAndReason)(invoice, locale)?.description || invoice.id
211
213
  });
212
214
  }
@@ -217,10 +219,12 @@ const InvoiceTable = _react.default.memo(props => {
217
219
  options: {
218
220
  customBodyRenderLite: (val, index) => {
219
221
  const invoice = data?.list[index];
220
- const link = getInvoiceLink(invoice, action);
221
222
  const hidePay = invoice.billing_reason === "overdraft-protection";
223
+ const {
224
+ connect
225
+ } = getInvoiceLink(invoice, action);
222
226
  if (action && !hidePay) {
223
- return link.connect ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
227
+ return connect ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
224
228
  variant: "text",
225
229
  size: "small",
226
230
  onClick: () => onPay(invoice.id),
@@ -232,8 +236,7 @@ const InvoiceTable = _react.default.memo(props => {
232
236
  component: "a",
233
237
  variant: "text",
234
238
  size: "small",
235
- href: link.url,
236
- target: link.external ? "_blank" : target,
239
+ onClick: e => handleLinkClick(e, invoice),
237
240
  sx: {
238
241
  color: "var(--foregrounds-fg-interactive, #0086FF) !important"
239
242
  },
@@ -241,10 +244,9 @@ const InvoiceTable = _react.default.memo(props => {
241
244
  children: t("payment.customer.invoice.pay")
242
245
  });
243
246
  }
244
- return /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
245
- href: link.url,
246
- target: link.external ? "_blank" : target,
247
- rel: "noreferrer",
247
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
248
+ onClick: e => handleLinkClick(e, invoice),
249
+ sx: linkStyle,
248
250
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
249
251
  label: invoice.status,
250
252
  color: (0, _util.getInvoiceStatusColor)(invoice.status)
@@ -330,6 +332,7 @@ const InvoiceList = _react.default.memo(props => {
330
332
  t,
331
333
  locale
332
334
  } = (0, _context.useLocaleContext)();
335
+ const navigate = (0, _reactRouterDom.useNavigate)();
333
336
  const {
334
337
  data,
335
338
  loadMore,
@@ -404,6 +407,11 @@ const InvoiceList = _react.default.memo(props => {
404
407
  }
405
408
  const hasMore = data && data.list.length < data.count;
406
409
  const grouped = groupByDate(data.list);
410
+ const handleLinkClick = (e, link) => {
411
+ (0, _navigation.handleNavigation)(e, link, navigate, {
412
+ target: link.external ? "_blank" : target
413
+ });
414
+ };
407
415
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Root, {
408
416
  direction: "column",
409
417
  gap: 1,
@@ -420,7 +428,10 @@ const InvoiceList = _react.default.memo(props => {
420
428
  },
421
429
  children: date
422
430
  }), invoices.map(invoice => {
423
- const link = getInvoiceLink(invoice, action);
431
+ const {
432
+ link,
433
+ connect
434
+ } = getInvoiceLink(invoice, action);
424
435
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
425
436
  direction: "row",
426
437
  sx: {
@@ -439,6 +450,7 @@ const InvoiceList = _react.default.memo(props => {
439
450
  href: link.url,
440
451
  target: link.external ? "_blank" : target,
441
452
  rel: "noreferrer",
453
+ onClick: e => handleLinkClick(e, link),
442
454
  children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
443
455
  direction: "row",
444
456
  alignItems: "center",
@@ -482,7 +494,7 @@ const InvoiceList = _react.default.memo(props => {
482
494
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
483
495
  flex: 1,
484
496
  textAlign: "right",
485
- children: action ? link.connect ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
497
+ children: action ? connect ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
486
498
  variant: "contained",
487
499
  color: "primary",
488
500
  size: "small",
@@ -495,8 +507,7 @@ const InvoiceList = _react.default.memo(props => {
495
507
  component: "a",
496
508
  variant: "contained",
497
509
  size: "small",
498
- href: link.url,
499
- target: link.external ? "_blank" : target,
510
+ onClick: e => handleLinkClick(e, link),
500
511
  sx: {
501
512
  whiteSpace: "nowrap"
502
513
  },
@@ -0,0 +1,33 @@
1
+ import { NavigateFunction } from 'react-router-dom';
2
+ export interface LinkInfo {
3
+ url: string;
4
+ external: boolean;
5
+ path: string;
6
+ }
7
+ /**
8
+ * Check if currently running inside Payment Kit
9
+ */
10
+ export declare function isInPaymentKit(): boolean;
11
+ /**
12
+ * Create link information object
13
+ * @param path Path or URL
14
+ * @param external Force external link behavior
15
+ */
16
+ export declare function createLink(path: string, external?: boolean): LinkInfo;
17
+ /**
18
+ * Get HTML attributes for a link
19
+ * @param link Link information
20
+ * @param target Link target (default: _self)
21
+ */
22
+ export declare function getLinkProps(link: LinkInfo, target?: string): Record<string, any>;
23
+ /**
24
+ * Handle link navigation
25
+ * @param e Click event
26
+ * @param link Link information
27
+ * @param navigate React Router navigate function
28
+ * @param options Navigation options
29
+ */
30
+ export declare function handleNavigation(e: React.MouseEvent, link: LinkInfo, navigate?: NavigateFunction, options?: {
31
+ replace?: boolean;
32
+ target?: string;
33
+ }): void;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createLink = createLink;
7
+ exports.getLinkProps = getLinkProps;
8
+ exports.handleNavigation = handleNavigation;
9
+ exports.isInPaymentKit = isInPaymentKit;
10
+ var _ufo = require("ufo");
11
+ var _util = require("./util");
12
+ function isInPaymentKit() {
13
+ const componentId = (window.blocklet?.componentId || "").split("/").pop();
14
+ return componentId === _util.PAYMENT_KIT_DID;
15
+ }
16
+ function createLink(path, external = false) {
17
+ const isAbsoluteUrl = /^https?:\/\//.test(path);
18
+ const isExternal = external || isAbsoluteUrl;
19
+ const url = isExternal ? path : (0, _ufo.joinURL)((0, _util.getPrefix)(), path);
20
+ return {
21
+ url,
22
+ external: isExternal,
23
+ path
24
+ };
25
+ }
26
+ function getLinkProps(link, target = "_self") {
27
+ const props = {
28
+ href: link.url
29
+ };
30
+ if (link.external) {
31
+ props.target = target;
32
+ props.rel = target === "_blank" ? "noopener noreferrer" : void 0;
33
+ }
34
+ return props;
35
+ }
36
+ function handleNavigation(e, link, navigate, options = {}) {
37
+ if (e) {
38
+ e.preventDefault();
39
+ }
40
+ const {
41
+ replace = false,
42
+ target = "_self"
43
+ } = options;
44
+ if (link.external || target === "_blank") {
45
+ window.open(link.url, target);
46
+ return;
47
+ }
48
+ if (isInPaymentKit() && navigate) {
49
+ navigate(link.path, {
50
+ replace
51
+ });
52
+ return;
53
+ }
54
+ if (replace) {
55
+ window.location.replace(link.url);
56
+ } else {
57
+ window.location.href = link.url;
58
+ }
59
+ }
package/lib/locales/en.js CHANGED
@@ -252,8 +252,8 @@ module.exports = (0, _flat.default)({
252
252
  }
253
253
  },
254
254
  recover: {
255
- button: "Renew",
256
- title: "Renew your subscription",
255
+ button: "Resume Subscription",
256
+ title: "Resume Your Subscription",
257
257
  description: "Your subscription will not be canceled and will be automatically renewed on {date}, please confirm to continue"
258
258
  },
259
259
  changePlan: {
package/lib/locales/zh.js CHANGED
@@ -252,8 +252,8 @@ module.exports = (0, _flat.default)({
252
252
  }
253
253
  },
254
254
  recover: {
255
- button: "\u7EED\u8BA2",
256
- title: "\u7EED\u8BA2\u60A8\u7684\u8BA2\u9605",
255
+ button: "\u6062\u590D\u8BA2\u9605",
256
+ title: "\u6062\u590D\u60A8\u7684\u8BA2\u9605",
257
257
  description: "\u60A8\u7684\u8BA2\u9605\u5C06\u4E0D\u4F1A\u88AB\u53D6\u6D88\uFF0C\u5E76\u5C06\u5728{date}\u81EA\u52A8\u7EED\u8BA2\uFF0C\u8BF7\u786E\u8BA4\u662F\u5426\u7EE7\u7EED"
258
258
  },
259
259
  changePlan: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.18.11",
3
+ "version": "1.18.13",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -55,13 +55,13 @@
55
55
  "dependencies": {
56
56
  "@arcblock/did-connect": "^2.11.48",
57
57
  "@arcblock/ux": "^2.11.48",
58
- "@arcblock/ws": "^1.19.10",
58
+ "@arcblock/ws": "^1.19.14",
59
59
  "@blocklet/ui-react": "^2.11.48",
60
60
  "@mui/icons-material": "^5.16.6",
61
61
  "@mui/lab": "^5.0.0-alpha.173",
62
62
  "@mui/material": "^5.16.6",
63
63
  "@mui/system": "^5.16.6",
64
- "@ocap/util": "^1.19.10",
64
+ "@ocap/util": "^1.19.14",
65
65
  "@stripe/react-stripe-js": "^2.7.3",
66
66
  "@stripe/stripe-js": "^2.4.0",
67
67
  "@vitejs/plugin-legacy": "^5.4.1",
@@ -92,7 +92,7 @@
92
92
  "@babel/core": "^7.25.2",
93
93
  "@babel/preset-env": "^7.25.2",
94
94
  "@babel/preset-react": "^7.24.7",
95
- "@blocklet/payment-types": "1.18.11",
95
+ "@blocklet/payment-types": "1.18.13",
96
96
  "@storybook/addon-essentials": "^7.6.20",
97
97
  "@storybook/addon-interactions": "^7.6.20",
98
98
  "@storybook/addon-links": "^7.6.20",
@@ -123,5 +123,5 @@
123
123
  "vite-plugin-babel": "^1.2.0",
124
124
  "vite-plugin-node-polyfills": "^0.21.0"
125
125
  },
126
- "gitHead": "370cb327400359ab5972ef60316ccd7fc86c174e"
126
+ "gitHead": "b26aa859ba5961c7a8dedfc238a31476cf16036c"
127
127
  }
@@ -22,6 +22,7 @@ export default function Link({ to, children, onClick, replace, target, outLink =
22
22
  e.preventDefault();
23
23
  window.location.href = to;
24
24
  }
25
+ e.preventDefault();
25
26
  onClick?.(e);
26
27
  };
27
28
 
@@ -22,6 +22,7 @@ type Props = {
22
22
  mode?: 'default' | 'custom';
23
23
  onPaid?: (subscriptionId: string, currencyId: string) => void;
24
24
  dialogProps?: DialogProps;
25
+ inSubscriptionDetail?: boolean;
25
26
  children?: (
26
27
  handlePay: (item: SummaryItem) => void,
27
28
  data: {
@@ -56,6 +57,7 @@ function OverdueInvoicePayment({
56
57
  dialogProps = {},
57
58
  children,
58
59
  onPaid = () => {},
60
+ inSubscriptionDetail = false,
59
61
  }: Props) {
60
62
  const { t } = useLocaleContext();
61
63
  const { connect } = usePaymentContext();
@@ -141,8 +143,15 @@ function OverdueInvoicePayment({
141
143
  dialogProps.onClose?.();
142
144
  };
143
145
 
146
+ const handleViewDetailClick = (e: React.MouseEvent) => {
147
+ if (inSubscriptionDetail) {
148
+ e.preventDefault();
149
+ handleClose();
150
+ }
151
+ };
152
+
144
153
  if (loading) {
145
- return <CircularProgress />;
154
+ return null;
146
155
  }
147
156
 
148
157
  const renderPayButton = (item: SummaryItem, props: any) => {
@@ -184,6 +193,7 @@ function OverdueInvoicePayment({
184
193
  {...(dialogProps || {})}
185
194
  open={dialogOpen}
186
195
  title={dialogProps?.title || t('payment.subscription.overdue.pastDue')}
196
+ sx={{ '& .MuiDialogContent-root': { pt: 0 } }}
187
197
  onClose={handleClose}>
188
198
  {error ? (
189
199
  <Alert severity="error">{error.message}</Alert>
@@ -220,6 +230,7 @@ function OverdueInvoicePayment({
220
230
  <a
221
231
  href={subscriptionUrl}
222
232
  target="_blank"
233
+ onClick={handleViewDetailClick}
223
234
  rel="noreferrer"
224
235
  style={{ color: 'var(--foregrounds-fg-interactive, 0086FF)' }}>
225
236
  {t('payment.subscription.overdue.view')}
@@ -250,6 +261,7 @@ function OverdueInvoicePayment({
250
261
  href={subscriptionUrl}
251
262
  target="_blank"
252
263
  rel="noreferrer"
264
+ onClick={handleViewDetailClick}
253
265
  style={{ color: 'var(--foregrounds-fg-interactive, 0086FF)' }}>
254
266
  {t('payment.subscription.overdue.view')}
255
267
  </a>
@@ -303,6 +315,7 @@ OverdueInvoicePayment.defaultProps = {
303
315
  open: true,
304
316
  },
305
317
  children: null,
318
+ inSubscriptionDetail: false,
306
319
  };
307
320
 
308
321
  export default OverdueInvoicePayment;