@blocklet/payment-react 1.13.189 → 1.13.190

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.
@@ -1,6 +1,7 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
3
  import {
4
+ Alert,
4
5
  Box,
5
6
  Button,
6
7
  CircularProgress,
@@ -18,6 +19,7 @@ import api from "../../api.js";
18
19
  import Status from "../../components/status.js";
19
20
  import {
20
21
  formatBNStr,
22
+ formatError,
21
23
  formatSubscriptionProduct,
22
24
  formatTime,
23
25
  formatToDate,
@@ -32,20 +34,34 @@ const fetchInvoiceData = (params = {}) => {
32
34
  });
33
35
  return api.get(`/api/invoices?${search.toString()}`).then((res) => res.data);
34
36
  };
35
- const fetchSubscriptionData = (id) => {
36
- return api.get(`/api/subscriptions/${id}`).then((res) => res.data);
37
+ const fetchSubscriptionData = (id, authToken) => {
38
+ if (!id) {
39
+ throw new Error("Subscription ID is missing");
40
+ }
41
+ return api.get(`/api/subscriptions/${id}?authToken=${authToken}`).then((res) => res.data);
37
42
  };
38
43
  export default function MiniInvoiceList() {
39
44
  const { t, locale } = useLocaleContext();
40
- const subscriptionId = new URL(window.location.href).searchParams.get("id");
41
- const { data: subscription } = useRequest(() => fetchSubscriptionData(subscriptionId));
45
+ const params = new URL(window.location.href).searchParams;
46
+ const subscriptionId = params.get("id") || "";
47
+ const authToken = params.get("authToken") || "";
48
+ const { data: subscription, error, loading } = useRequest(() => fetchSubscriptionData(subscriptionId, authToken));
42
49
  const { data } = useRequest(
43
- () => fetchInvoiceData({ page: 1, pageSize: 10, status: "open,paid,uncollectible", subscription_id: subscriptionId })
50
+ () => fetchInvoiceData({
51
+ page: 1,
52
+ pageSize: 20,
53
+ status: "open,paid,uncollectible",
54
+ subscription_id: subscriptionId,
55
+ authToken
56
+ })
44
57
  );
45
- if (!subscription || !data) {
58
+ if (error) {
59
+ return /* @__PURE__ */ jsx(Position, { children: /* @__PURE__ */ jsx(Alert, { severity: "error", children: formatError(error) }) });
60
+ }
61
+ if (!subscription || loading) {
46
62
  return /* @__PURE__ */ jsx(Position, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
47
63
  }
48
- const invoices = data.list || [];
64
+ const invoices = data?.list || [];
49
65
  const infoList = [
50
66
  {
51
67
  name: t("payment.customer.subscriptions.plan"),
package/es/locales/en.js CHANGED
@@ -231,13 +231,13 @@ export default flat({
231
231
  renew: "Renew the subscription",
232
232
  renewSuccess: "You have successfully renewed the subscription",
233
233
  renewError: "Failed to renew the subscription",
234
- empty: "There are no invoices here"
234
+ empty: "There are no invoices"
235
235
  },
236
236
  payment: {
237
- empty: "There are no payments here"
237
+ empty: "There are no payments"
238
238
  },
239
239
  refund: {
240
- empty: "There are no refunds here"
240
+ empty: "There are no refunds"
241
241
  },
242
242
  subscriptions: {
243
243
  plan: "Plan",
@@ -20,32 +20,48 @@ const fetchInvoiceData = (params = {}) => {
20
20
  });
21
21
  return _api.default.get(`/api/invoices?${search.toString()}`).then(res => res.data);
22
22
  };
23
- const fetchSubscriptionData = id => {
24
- return _api.default.get(`/api/subscriptions/${id}`).then(res => res.data);
23
+ const fetchSubscriptionData = (id, authToken) => {
24
+ if (!id) {
25
+ throw new Error("Subscription ID is missing");
26
+ }
27
+ return _api.default.get(`/api/subscriptions/${id}?authToken=${authToken}`).then(res => res.data);
25
28
  };
26
29
  function MiniInvoiceList() {
27
30
  const {
28
31
  t,
29
32
  locale
30
33
  } = (0, _context.useLocaleContext)();
31
- const subscriptionId = new URL(window.location.href).searchParams.get("id");
34
+ const params = new URL(window.location.href).searchParams;
35
+ const subscriptionId = params.get("id") || "";
36
+ const authToken = params.get("authToken") || "";
32
37
  const {
33
- data: subscription
34
- } = (0, _ahooks.useRequest)(() => fetchSubscriptionData(subscriptionId));
38
+ data: subscription,
39
+ error,
40
+ loading
41
+ } = (0, _ahooks.useRequest)(() => fetchSubscriptionData(subscriptionId, authToken));
35
42
  const {
36
43
  data
37
44
  } = (0, _ahooks.useRequest)(() => fetchInvoiceData({
38
45
  page: 1,
39
- pageSize: 10,
46
+ pageSize: 20,
40
47
  status: "open,paid,uncollectible",
41
- subscription_id: subscriptionId
48
+ subscription_id: subscriptionId,
49
+ authToken
42
50
  }));
43
- if (!subscription || !data) {
51
+ if (error) {
52
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(Position, {
53
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Alert, {
54
+ severity: "error",
55
+ children: (0, _util.formatError)(error)
56
+ })
57
+ });
58
+ }
59
+ if (!subscription || loading) {
44
60
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(Position, {
45
61
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {})
46
62
  });
47
63
  }
48
- const invoices = data.list || [];
64
+ const invoices = data?.list || [];
49
65
  const infoList = [{
50
66
  name: t("payment.customer.subscriptions.plan"),
51
67
  value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
package/lib/locales/en.js CHANGED
@@ -238,13 +238,13 @@ module.exports = (0, _flat.default)({
238
238
  renew: "Renew the subscription",
239
239
  renewSuccess: "You have successfully renewed the subscription",
240
240
  renewError: "Failed to renew the subscription",
241
- empty: "There are no invoices here"
241
+ empty: "There are no invoices"
242
242
  },
243
243
  payment: {
244
- empty: "There are no payments here"
244
+ empty: "There are no payments"
245
245
  },
246
246
  refund: {
247
- empty: "There are no refunds here"
247
+ empty: "There are no refunds"
248
248
  },
249
249
  subscriptions: {
250
250
  plan: "Plan",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.189",
3
+ "version": "1.13.190",
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.189",
93
+ "@blocklet/payment-types": "1.13.190",
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.19.0"
121
121
  },
122
- "gitHead": "74acb8bab72fdcd83ef007b661fe9017d0c2840d"
122
+ "gitHead": "282f562ac2145ad6b5ea7732ddfd865e7706b920"
123
123
  }
@@ -2,6 +2,7 @@
2
2
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
3
  import type { Paginated, TInvoiceExpanded, TSubscriptionExpanded } from '@blocklet/payment-types';
4
4
  import {
5
+ Alert,
5
6
  Box,
6
7
  Button,
7
8
  CircularProgress,
@@ -20,6 +21,7 @@ import api from '../../api';
20
21
  import Status from '../../components/status';
21
22
  import {
22
23
  formatBNStr,
24
+ formatError,
23
25
  formatSubscriptionProduct,
24
26
  formatTime,
25
27
  formatToDate,
@@ -36,21 +38,40 @@ const fetchInvoiceData = (params: Record<string, any> = {}): Promise<Paginated<T
36
38
  return api.get(`/api/invoices?${search.toString()}`).then((res: any) => res.data);
37
39
  };
38
40
 
39
- const fetchSubscriptionData = (id: string): Promise<TSubscriptionExpanded> => {
40
- return api.get(`/api/subscriptions/${id}`).then((res) => res.data);
41
+ const fetchSubscriptionData = (id: string, authToken: string): Promise<TSubscriptionExpanded> => {
42
+ if (!id) {
43
+ throw new Error('Subscription ID is missing');
44
+ }
45
+
46
+ return api.get(`/api/subscriptions/${id}?authToken=${authToken}`).then((res) => res.data);
41
47
  };
42
48
 
43
49
  export default function MiniInvoiceList() {
44
50
  const { t, locale } = useLocaleContext();
51
+ const params = new URL(window.location.href).searchParams;
45
52
 
46
- const subscriptionId = new URL(window.location.href).searchParams.get('id');
53
+ const subscriptionId = params.get('id') || '';
54
+ const authToken = params.get('authToken') || '';
47
55
 
48
- const { data: subscription } = useRequest(() => fetchSubscriptionData(subscriptionId as string));
56
+ const { data: subscription, error, loading } = useRequest(() => fetchSubscriptionData(subscriptionId, authToken));
49
57
  const { data } = useRequest(() =>
50
- fetchInvoiceData({ page: 1, pageSize: 10, status: 'open,paid,uncollectible', subscription_id: subscriptionId })
58
+ fetchInvoiceData({
59
+ page: 1,
60
+ pageSize: 20,
61
+ status: 'open,paid,uncollectible',
62
+ subscription_id: subscriptionId,
63
+ authToken,
64
+ })
51
65
  );
52
66
 
53
- if (!subscription || !data) {
67
+ if (error) {
68
+ return (
69
+ <Position>
70
+ <Alert severity="error">{formatError(error)}</Alert>
71
+ </Position>
72
+ );
73
+ }
74
+ if (!subscription || loading) {
54
75
  return (
55
76
  <Position>
56
77
  <CircularProgress />
@@ -58,7 +79,7 @@ export default function MiniInvoiceList() {
58
79
  );
59
80
  }
60
81
 
61
- const invoices = data.list || [];
82
+ const invoices = data?.list || [];
62
83
 
63
84
  const infoList = [
64
85
  {
@@ -240,13 +240,13 @@ export default flat({
240
240
  renew: 'Renew the subscription',
241
241
  renewSuccess: 'You have successfully renewed the subscription',
242
242
  renewError: 'Failed to renew the subscription',
243
- empty: 'There are no invoices here',
243
+ empty: 'There are no invoices',
244
244
  },
245
245
  payment: {
246
- empty: 'There are no payments here',
246
+ empty: 'There are no payments',
247
247
  },
248
248
  refund: {
249
- empty: 'There are no refunds here',
249
+ empty: 'There are no refunds',
250
250
  },
251
251
  subscriptions: {
252
252
  plan: 'Plan',