@blocklet/payment-react 1.13.129 → 1.13.130

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.
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ customer_id?: string;
4
+ subscription_id?: string;
5
+ };
6
+ declare function CustomerInvoiceList({ customer_id, subscription_id }: Props): import("react").JSX.Element;
7
+ declare namespace CustomerInvoiceList {
8
+ var defaultProps: {
9
+ customer_id: string;
10
+ subscription_id: string;
11
+ };
12
+ }
13
+ export default CustomerInvoiceList;
@@ -20,17 +20,19 @@ const groupByDate = (items) => {
20
20
  const fetchData = (params = {}) => {
21
21
  const search = new URLSearchParams();
22
22
  Object.keys(params).forEach((key) => {
23
- search.set(key, String(params[key]));
23
+ if (params[key]) {
24
+ search.set(key, String(params[key]));
25
+ }
24
26
  });
25
27
  return api.get(`/api/invoices?${search.toString()}`).then((res) => res.data);
26
28
  };
27
29
  const pageSize = 10;
28
- export default function CustomerInvoiceList({ customer_id }) {
30
+ export default function CustomerInvoiceList({ customer_id, subscription_id }) {
29
31
  const { t } = useLocaleContext();
30
32
  const { data, loadMore, loadingMore, loading } = useInfiniteScroll(
31
33
  (d) => {
32
34
  const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
33
- return fetchData({ page, pageSize, status: "open,paid,uncollectible", customer_id });
35
+ return fetchData({ page, pageSize, status: "open,paid,uncollectible", customer_id, subscription_id });
34
36
  },
35
37
  {
36
38
  reloadDeps: [customer_id]
@@ -82,3 +84,7 @@ export default function CustomerInvoiceList({ customer_id }) {
82
84
  ] })
83
85
  ] });
84
86
  }
87
+ CustomerInvoiceList.defaultProps = {
88
+ customer_id: "",
89
+ subscription_id: ""
90
+ };
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function MiniInvoiceList(): import("react").JSX.Element;
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
3
  import { Box, Button, CircularProgress, Divider, List, ListItem, ListSubheader, Typography } from "@mui/material";
4
4
  import { fromUnitToToken } from "@ocap/util";
5
- import { useInfiniteScroll } from "ahooks";
5
+ import { useRequest } from "ahooks";
6
6
  import api from "../../api.js";
7
7
  import Status from "../../components/status.js";
8
8
  import {
@@ -12,26 +12,24 @@ import {
12
12
  getInvoiceStatusColor,
13
13
  getSubscriptionStatusColor
14
14
  } from "../../util.js";
15
- const fetchData = (params = {}) => {
15
+ const fetchInvoiceData = (params = {}) => {
16
16
  const search = new URLSearchParams();
17
17
  Object.keys(params).forEach((key) => {
18
18
  search.set(key, String(params[key]));
19
19
  });
20
20
  return api.get(`/api/invoices?${search.toString()}`).then((res) => res.data);
21
21
  };
22
- const pageSize = 10;
23
- export default function MiniInvoiceList({ subscription }) {
22
+ const fetchSubscriptionData = (id) => {
23
+ return api.get(`/api/subscriptions/${id}`).then((res) => res.data);
24
+ };
25
+ export default function MiniInvoiceList() {
24
26
  const { t } = useLocaleContext();
25
- const { data, loading } = useInfiniteScroll(
26
- (d) => {
27
- const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
28
- return fetchData({ page, pageSize, status: "open,paid,uncollectible", subscription_id: subscription.id });
29
- },
30
- {
31
- reloadDeps: [subscription.id]
32
- }
27
+ const subscriptionId = new URL(window.location.href).searchParams.get("id");
28
+ const { data: subscription } = useRequest(() => fetchSubscriptionData(subscriptionId));
29
+ const { data } = useRequest(
30
+ () => fetchInvoiceData({ page: 1, pageSize: 10, status: "open,paid,uncollectible", subscription_id: subscriptionId })
33
31
  );
34
- if (loading || !data) {
32
+ if (!data || !subscription) {
35
33
  return /* @__PURE__ */ jsx(Position, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
36
34
  }
37
35
  if (data && data.list.length === 0) {
@@ -43,7 +41,7 @@ export default function MiniInvoiceList({ subscription }) {
43
41
  value: /* @__PURE__ */ jsx(Typography, { fontWeight: 600, sx: { marginRight: "10px" }, children: formatSubscriptionProduct(subscription.items) })
44
42
  },
45
43
  {
46
- name: t("payment.common.status"),
44
+ name: t("common.status"),
47
45
  value: /* @__PURE__ */ jsx(Status, { label: subscription.status, color: getSubscriptionStatusColor(subscription.status) })
48
46
  },
49
47
  {
@@ -53,7 +51,8 @@ export default function MiniInvoiceList({ subscription }) {
53
51
  {
54
52
  sx: {
55
53
  color: "#34BE74",
56
- fontWeight: "bold"
54
+ fontWeight: "bold",
55
+ marginRight: "10px"
57
56
  },
58
57
  children: formatTime(subscription.current_period_end * 1e3)
59
58
  }
@@ -83,21 +82,28 @@ export default function MiniInvoiceList({ subscription }) {
83
82
  ] }, name);
84
83
  }) }) }),
85
84
  /* @__PURE__ */ jsx(Divider, {}),
86
- /* @__PURE__ */ jsx(Box, { sx: { marginTop: "12px" }, children: /* @__PURE__ */ jsxs(List, { sx: { overflow: "auto", maxHeight: { xs: "240px", md: "360px", padding: 0 } }, children: [
87
- /* @__PURE__ */ jsx(ListSubheader, { disableGutters: true, sx: { padding: 0 }, children: /* @__PURE__ */ jsx(Typography, { component: "h2", variant: "h6", fontSize: "16px", children: t("payment.customer.invoices") }) }),
88
- (data.list || []).map((item) => {
89
- return /* @__PURE__ */ jsxs(ListItem, { disableGutters: true, sx: { display: "flex", justifyContent: "space-between" }, children: [
90
- /* @__PURE__ */ jsx(Typography, { component: "span", children: formatToDate(item.created_at) }),
91
- /* @__PURE__ */ jsxs(Typography, { component: "span", children: [
92
- fromUnitToToken(item.total, item.paymentCurrency.decimal),
93
- "\xA0",
94
- item.paymentCurrency.symbol
95
- ] }),
96
- /* @__PURE__ */ jsx(Status, { label: item.status, color: getInvoiceStatusColor(item.status) })
97
- ] }, item.id);
98
- })
99
- ] }) }),
100
- /* @__PURE__ */ jsx(Button, { target: "_top", variant: "contained", sx: { marginTop: "auto", width: "100%" }, href: "", children: t("payment.customer.subscriptions.title") })
85
+ /* @__PURE__ */ jsx(Box, { sx: { marginTop: "12px" }, children: /* @__PURE__ */ jsxs(
86
+ List,
87
+ {
88
+ sx: { overflow: "auto", maxHeight: { xs: "240px", md: "360px", padding: 0 } },
89
+ className: "mini-invoice-list",
90
+ children: [
91
+ /* @__PURE__ */ jsx(ListSubheader, { disableGutters: true, sx: { padding: 0 }, children: /* @__PURE__ */ jsx(Typography, { component: "h2", variant: "h6", fontSize: "16px", children: t("payment.customer.invoices") }) }),
92
+ (data.list || []).map((item) => {
93
+ return /* @__PURE__ */ jsxs(ListItem, { disableGutters: true, sx: { display: "flex", justifyContent: "space-between" }, children: [
94
+ /* @__PURE__ */ jsx(Typography, { component: "span", sx: { flex: 3 }, children: formatToDate(item.created_at) }),
95
+ /* @__PURE__ */ jsxs(Typography, { component: "span", sx: { flex: 1 }, children: [
96
+ fromUnitToToken(item.total, item.paymentCurrency.decimal),
97
+ "\xA0",
98
+ item.paymentCurrency.symbol
99
+ ] }),
100
+ /* @__PURE__ */ jsx(Typography, { component: "span", sx: { flex: 2, textAlign: "right" }, children: /* @__PURE__ */ jsx(Status, { label: item.status, color: getInvoiceStatusColor(item.status), sx: { flex: 2 } }) })
101
+ ] }, item.id);
102
+ })
103
+ ]
104
+ }
105
+ ) }),
106
+ /* @__PURE__ */ jsx(Button, { target: "_top", variant: "contained", sx: { marginTop: "10px 0", width: "100%" }, href: "", children: t("payment.customer.subscriptions.title") })
101
107
  ]
102
108
  }
103
109
  )
@@ -109,15 +115,12 @@ function Position({ children }) {
109
115
  {
110
116
  className: "mini-invoice-box",
111
117
  sx: {
112
- position: "absolute",
113
- right: 0,
114
- top: "30px",
115
118
  justifyContent: "center",
116
119
  padding: "8px",
117
- minWidth: "400px",
120
+ width: "100%",
121
+ maxWidth: "500px",
118
122
  background: "#fff",
119
- zIndex: 9,
120
- boxShadow: "0 4px 8px rgba(0, 0, 0, 20%)"
123
+ margin: "0 auto"
121
124
  },
122
125
  children
123
126
  }
package/es/index.d.ts CHANGED
@@ -8,9 +8,9 @@ import PricingTable from './components/pricing-table';
8
8
  import Status from './components/status';
9
9
  import Switch from './components/switch-button';
10
10
  import dayjs from './dayjs';
11
- import CustomerInvoiceList from './histroy/invoice/list';
12
- import MiniInvoiceList from './histroy/mini-invoice/list';
13
- import CustomerPaymentList from './histroy/payment/list';
11
+ import CustomerInvoiceList from './history/invoice/list';
12
+ import MiniInvoiceList from './history/mini-invoice/list';
13
+ import CustomerPaymentList from './history/payment/list';
14
14
  import Amount from './payment/amount';
15
15
  import PhoneInput from './payment/form/phone';
16
16
  import Payment from './payment/index';
package/es/index.js CHANGED
@@ -8,9 +8,9 @@ import PricingTable from "./components/pricing-table.js";
8
8
  import Status from "./components/status.js";
9
9
  import Switch from "./components/switch-button.js";
10
10
  import dayjs from "./dayjs.js";
11
- import CustomerInvoiceList from "./histroy/invoice/list.js";
12
- import MiniInvoiceList from "./histroy/mini-invoice/list.js";
13
- import CustomerPaymentList from "./histroy/payment/list.js";
11
+ import CustomerInvoiceList from "./history/invoice/list.js";
12
+ import MiniInvoiceList from "./history/mini-invoice/list.js";
13
+ import CustomerPaymentList from "./history/payment/list.js";
14
14
  import Amount from "./payment/amount.js";
15
15
  import PhoneInput from "./payment/form/phone.js";
16
16
  import Payment from "./payment/index.js";
package/es/locales/en.js CHANGED
@@ -211,7 +211,7 @@ export default flat({
211
211
  plan: "Plan",
212
212
  nextInvoice: "Next Invoice",
213
213
  title: "Manage subscriptions",
214
- current: "Current subscriptions",
214
+ current: "Current subscription",
215
215
  empty: "Seems you do not have any subscriptions here"
216
216
  }
217
217
  }
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ customer_id?: string;
4
+ subscription_id?: string;
5
+ };
6
+ declare function CustomerInvoiceList({ customer_id, subscription_id }: Props): import("react").JSX.Element;
7
+ declare namespace CustomerInvoiceList {
8
+ var defaultProps: {
9
+ customer_id: string;
10
+ subscription_id: string;
11
+ };
12
+ }
13
+ export default CustomerInvoiceList;
@@ -27,13 +27,16 @@ const groupByDate = items => {
27
27
  const fetchData = (params = {}) => {
28
28
  const search = new URLSearchParams();
29
29
  Object.keys(params).forEach(key => {
30
- search.set(key, String(params[key]));
30
+ if (params[key]) {
31
+ search.set(key, String(params[key]));
32
+ }
31
33
  });
32
34
  return _api.default.get(`/api/invoices?${search.toString()}`).then(res => res.data);
33
35
  };
34
36
  const pageSize = 10;
35
37
  function CustomerInvoiceList({
36
- customer_id
38
+ customer_id,
39
+ subscription_id
37
40
  }) {
38
41
  const {
39
42
  t
@@ -49,7 +52,8 @@ function CustomerInvoiceList({
49
52
  page,
50
53
  pageSize,
51
54
  status: "open,paid,uncollectible",
52
- customer_id
55
+ customer_id,
56
+ subscription_id
53
57
  });
54
58
  }, {
55
59
  reloadDeps: [customer_id]
@@ -147,4 +151,8 @@ function CustomerInvoiceList({
147
151
  })]
148
152
  })]
149
153
  });
150
- }
154
+ }
155
+ CustomerInvoiceList.defaultProps = {
156
+ customer_id: "",
157
+ subscription_id: ""
158
+ };
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function MiniInvoiceList(): import("react").JSX.Element;
@@ -13,35 +13,33 @@ var _api = _interopRequireDefault(require("../../api"));
13
13
  var _status = _interopRequireDefault(require("../../components/status"));
14
14
  var _util2 = require("../../util");
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
- const fetchData = (params = {}) => {
16
+ const fetchInvoiceData = (params = {}) => {
17
17
  const search = new URLSearchParams();
18
18
  Object.keys(params).forEach(key => {
19
19
  search.set(key, String(params[key]));
20
20
  });
21
21
  return _api.default.get(`/api/invoices?${search.toString()}`).then(res => res.data);
22
22
  };
23
- const pageSize = 10;
24
- function MiniInvoiceList({
25
- subscription
26
- }) {
23
+ const fetchSubscriptionData = id => {
24
+ return _api.default.get(`/api/subscriptions/${id}`).then(res => res.data);
25
+ };
26
+ function MiniInvoiceList() {
27
27
  const {
28
28
  t
29
29
  } = (0, _context.useLocaleContext)();
30
+ const subscriptionId = new URL(window.location.href).searchParams.get("id");
30
31
  const {
31
- data,
32
- loading
33
- } = (0, _ahooks.useInfiniteScroll)(d => {
34
- const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
35
- return fetchData({
36
- page,
37
- pageSize,
38
- status: "open,paid,uncollectible",
39
- subscription_id: subscription.id
40
- });
41
- }, {
42
- reloadDeps: [subscription.id]
43
- });
44
- if (loading || !data) {
32
+ data: subscription
33
+ } = (0, _ahooks.useRequest)(() => fetchSubscriptionData(subscriptionId));
34
+ const {
35
+ data
36
+ } = (0, _ahooks.useRequest)(() => fetchInvoiceData({
37
+ page: 1,
38
+ pageSize: 10,
39
+ status: "open,paid,uncollectible",
40
+ subscription_id: subscriptionId
41
+ }));
42
+ if (!data || !subscription) {
45
43
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(Position, {
46
44
  children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {})
47
45
  });
@@ -64,7 +62,7 @@ function MiniInvoiceList({
64
62
  children: (0, _util2.formatSubscriptionProduct)(subscription.items)
65
63
  })
66
64
  }, {
67
- name: t("payment.common.status"),
65
+ name: t("common.status"),
68
66
  value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
69
67
  label: subscription.status,
70
68
  color: (0, _util2.getSubscriptionStatusColor)(subscription.status)
@@ -74,7 +72,8 @@ function MiniInvoiceList({
74
72
  value: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
75
73
  sx: {
76
74
  color: "#34BE74",
77
- fontWeight: "bold"
75
+ fontWeight: "bold",
76
+ marginRight: "10px"
78
77
  },
79
78
  children: (0, _util2.formatTime)(subscription.current_period_end * 1e3)
80
79
  })
@@ -138,6 +137,7 @@ function MiniInvoiceList({
138
137
  padding: 0
139
138
  }
140
139
  },
140
+ className: "mini-invoice-list",
141
141
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.ListSubheader, {
142
142
  disableGutters: true,
143
143
  sx: {
@@ -158,13 +158,29 @@ function MiniInvoiceList({
158
158
  },
159
159
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
160
160
  component: "span",
161
+ sx: {
162
+ flex: 3
163
+ },
161
164
  children: (0, _util2.formatToDate)(item.created_at)
162
165
  }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
163
166
  component: "span",
167
+ sx: {
168
+ flex: 1
169
+ },
164
170
  children: [(0, _util.fromUnitToToken)(item.total, item.paymentCurrency.decimal), "\xA0", item.paymentCurrency.symbol]
165
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
166
- label: item.status,
167
- color: (0, _util2.getInvoiceStatusColor)(item.status)
171
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
172
+ component: "span",
173
+ sx: {
174
+ flex: 2,
175
+ textAlign: "right"
176
+ },
177
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
178
+ label: item.status,
179
+ color: (0, _util2.getInvoiceStatusColor)(item.status),
180
+ sx: {
181
+ flex: 2
182
+ }
183
+ })
168
184
  })]
169
185
  }, item.id);
170
186
  })]
@@ -173,7 +189,7 @@ function MiniInvoiceList({
173
189
  target: "_top",
174
190
  variant: "contained",
175
191
  sx: {
176
- marginTop: "auto",
192
+ marginTop: "10px 0",
177
193
  width: "100%"
178
194
  },
179
195
  href: "",
@@ -188,15 +204,12 @@ function Position({
188
204
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
189
205
  className: "mini-invoice-box",
190
206
  sx: {
191
- position: "absolute",
192
- right: 0,
193
- top: "30px",
194
207
  justifyContent: "center",
195
208
  padding: "8px",
196
- minWidth: "400px",
209
+ width: "100%",
210
+ maxWidth: "500px",
197
211
  background: "#fff",
198
- zIndex: 9,
199
- boxShadow: "0 4px 8px rgba(0, 0, 0, 20%)"
212
+ margin: "0 auto"
200
213
  },
201
214
  children
202
215
  });
package/lib/index.d.ts CHANGED
@@ -8,9 +8,9 @@ import PricingTable from './components/pricing-table';
8
8
  import Status from './components/status';
9
9
  import Switch from './components/switch-button';
10
10
  import dayjs from './dayjs';
11
- import CustomerInvoiceList from './histroy/invoice/list';
12
- import MiniInvoiceList from './histroy/mini-invoice/list';
13
- import CustomerPaymentList from './histroy/payment/list';
11
+ import CustomerInvoiceList from './history/invoice/list';
12
+ import MiniInvoiceList from './history/mini-invoice/list';
13
+ import CustomerPaymentList from './history/payment/list';
14
14
  import Amount from './payment/amount';
15
15
  import PhoneInput from './payment/form/phone';
16
16
  import Payment from './payment/index';
package/lib/index.js CHANGED
@@ -148,9 +148,9 @@ var _pricingTable = _interopRequireDefault(require("./components/pricing-table")
148
148
  var _status = _interopRequireDefault(require("./components/status"));
149
149
  var _switchButton = _interopRequireDefault(require("./components/switch-button"));
150
150
  var _dayjs = _interopRequireDefault(require("./dayjs"));
151
- var _list = _interopRequireDefault(require("./histroy/invoice/list"));
152
- var _list2 = _interopRequireDefault(require("./histroy/mini-invoice/list"));
153
- var _list3 = _interopRequireDefault(require("./histroy/payment/list"));
151
+ var _list = _interopRequireDefault(require("./history/invoice/list"));
152
+ var _list2 = _interopRequireDefault(require("./history/mini-invoice/list"));
153
+ var _list3 = _interopRequireDefault(require("./history/payment/list"));
154
154
  var _amount = _interopRequireDefault(require("./payment/amount"));
155
155
  var _phone = _interopRequireDefault(require("./payment/form/phone"));
156
156
  var _index = _interopRequireDefault(require("./payment/index"));
package/lib/locales/en.js CHANGED
@@ -218,7 +218,7 @@ module.exports = (0, _flat.default)({
218
218
  plan: "Plan",
219
219
  nextInvoice: "Next Invoice",
220
220
  title: "Manage subscriptions",
221
- current: "Current subscriptions",
221
+ current: "Current subscription",
222
222
  empty: "Seems you do not have any subscriptions here"
223
223
  }
224
224
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.129",
3
+ "version": "1.13.130",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -89,7 +89,7 @@
89
89
  "@babel/core": "^7.19.3",
90
90
  "@babel/preset-env": "^7.19.3",
91
91
  "@babel/preset-react": "^7.18.6",
92
- "@blocklet/payment-types": "1.13.129",
92
+ "@blocklet/payment-types": "1.13.130",
93
93
  "@storybook/addon-essentials": "^7.6.10",
94
94
  "@storybook/addon-interactions": "^7.6.10",
95
95
  "@storybook/addon-links": "^7.6.10",
@@ -118,5 +118,5 @@
118
118
  "vite-plugin-babel": "^1.2.0",
119
119
  "vite-plugin-node-polyfills": "^0.19.0"
120
120
  },
121
- "gitHead": "4ad81bea01de3268d9cf0bda552a0a0a67abd85d"
121
+ "gitHead": "95aaa56f16ce303e514aa7dde9e542628d7acd2c"
122
122
  }
@@ -24,24 +24,27 @@ const groupByDate = (items: TInvoiceExpanded[]) => {
24
24
  const fetchData = (params: Record<string, any> = {}): Promise<Paginated<TInvoiceExpanded>> => {
25
25
  const search = new URLSearchParams();
26
26
  Object.keys(params).forEach((key) => {
27
- search.set(key, String(params[key]));
27
+ if (params[key]) {
28
+ search.set(key, String(params[key]));
29
+ }
28
30
  });
29
31
  return api.get(`/api/invoices?${search.toString()}`).then((res: any) => res.data);
30
32
  };
31
33
 
32
34
  type Props = {
33
- customer_id: string;
35
+ customer_id?: string;
36
+ subscription_id?: string;
34
37
  };
35
38
 
36
39
  const pageSize = 10;
37
40
 
38
- export default function CustomerInvoiceList({ customer_id }: Props) {
41
+ export default function CustomerInvoiceList({ customer_id, subscription_id }: Props) {
39
42
  const { t } = useLocaleContext();
40
43
 
41
44
  const { data, loadMore, loadingMore, loading } = useInfiniteScroll<Paginated<TInvoiceExpanded>>(
42
45
  (d) => {
43
46
  const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
44
- return fetchData({ page, pageSize, status: 'open,paid,uncollectible', customer_id });
47
+ return fetchData({ page, pageSize, status: 'open,paid,uncollectible', customer_id, subscription_id });
45
48
  },
46
49
  {
47
50
  reloadDeps: [customer_id],
@@ -120,3 +123,8 @@ export default function CustomerInvoiceList({ customer_id }: Props) {
120
123
  </Stack>
121
124
  );
122
125
  }
126
+
127
+ CustomerInvoiceList.defaultProps = {
128
+ customer_id: '',
129
+ subscription_id: '',
130
+ };
@@ -3,7 +3,7 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
3
  import type { Paginated, TInvoiceExpanded, TSubscriptionExpanded } from '@blocklet/payment-types';
4
4
  import { Box, Button, CircularProgress, Divider, List, ListItem, ListSubheader, Typography } from '@mui/material';
5
5
  import { fromUnitToToken } from '@ocap/util';
6
- import { useInfiniteScroll } from 'ahooks';
6
+ import { useRequest } from 'ahooks';
7
7
 
8
8
  import api from '../../api';
9
9
  import Status from '../../components/status';
@@ -15,7 +15,7 @@ import {
15
15
  getSubscriptionStatusColor,
16
16
  } from '../../util';
17
17
 
18
- const fetchData = (params: Record<string, any> = {}): Promise<Paginated<TInvoiceExpanded>> => {
18
+ const fetchInvoiceData = (params: Record<string, any> = {}): Promise<Paginated<TInvoiceExpanded>> => {
19
19
  const search = new URLSearchParams();
20
20
  Object.keys(params).forEach((key) => {
21
21
  search.set(key, String(params[key]));
@@ -23,26 +23,21 @@ const fetchData = (params: Record<string, any> = {}): Promise<Paginated<TInvoice
23
23
  return api.get(`/api/invoices?${search.toString()}`).then((res: any) => res.data);
24
24
  };
25
25
 
26
- type Props = {
27
- subscription: TSubscriptionExpanded;
26
+ const fetchSubscriptionData = (id: string): Promise<TSubscriptionExpanded> => {
27
+ return api.get(`/api/subscriptions/${id}`).then((res) => res.data);
28
28
  };
29
29
 
30
- const pageSize = 10;
31
-
32
- export default function MiniInvoiceList({ subscription }: Props) {
30
+ export default function MiniInvoiceList() {
33
31
  const { t } = useLocaleContext();
34
32
 
35
- const { data, loading } = useInfiniteScroll<Paginated<TInvoiceExpanded>>(
36
- (d) => {
37
- const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
38
- return fetchData({ page, pageSize, status: 'open,paid,uncollectible', subscription_id: subscription.id });
39
- },
40
- {
41
- reloadDeps: [subscription.id],
42
- }
33
+ const subscriptionId = new URL(window.location.href).searchParams.get('id');
34
+
35
+ const { data: subscription } = useRequest(() => fetchSubscriptionData(subscriptionId as string));
36
+ const { data } = useRequest(() =>
37
+ fetchInvoiceData({ page: 1, pageSize: 10, status: 'open,paid,uncollectible', subscription_id: subscriptionId })
43
38
  );
44
39
 
45
- if (loading || !data) {
40
+ if (!data || !subscription) {
46
41
  return (
47
42
  <Position>
48
43
  <CircularProgress />
@@ -68,7 +63,7 @@ export default function MiniInvoiceList({ subscription }: Props) {
68
63
  ),
69
64
  },
70
65
  {
71
- name: t('payment.common.status'),
66
+ name: t('common.status'),
72
67
  value: <Status label={subscription.status} color={getSubscriptionStatusColor(subscription.status)} />,
73
68
  },
74
69
 
@@ -79,6 +74,7 @@ export default function MiniInvoiceList({ subscription }: Props) {
79
74
  sx={{
80
75
  color: '#34BE74',
81
76
  fontWeight: 'bold',
77
+ marginRight: '10px',
82
78
  }}>
83
79
  {formatTime(subscription.current_period_end * 1000)}
84
80
  </Typography>
@@ -116,7 +112,9 @@ export default function MiniInvoiceList({ subscription }: Props) {
116
112
  </Box>
117
113
  <Divider />
118
114
  <Box sx={{ marginTop: '12px' }}>
119
- <List sx={{ overflow: 'auto', maxHeight: { xs: '240px', md: '360px', padding: 0 } }}>
115
+ <List
116
+ sx={{ overflow: 'auto', maxHeight: { xs: '240px', md: '360px', padding: 0 } }}
117
+ className="mini-invoice-list">
120
118
  <ListSubheader disableGutters sx={{ padding: 0 }}>
121
119
  <Typography component="h2" variant="h6" fontSize="16px">
122
120
  {t('payment.customer.invoices')}
@@ -125,18 +123,22 @@ export default function MiniInvoiceList({ subscription }: Props) {
125
123
  {(data.list || []).map((item: any) => {
126
124
  return (
127
125
  <ListItem key={item.id} disableGutters sx={{ display: 'flex', justifyContent: 'space-between' }}>
128
- <Typography component="span">{formatToDate(item.created_at)}</Typography>
129
- <Typography component="span">
126
+ <Typography component="span" sx={{ flex: 3 }}>
127
+ {formatToDate(item.created_at)}
128
+ </Typography>
129
+ <Typography component="span" sx={{ flex: 1 }}>
130
130
  {fromUnitToToken(item.total, item.paymentCurrency.decimal)}&nbsp;
131
131
  {item.paymentCurrency.symbol}
132
132
  </Typography>
133
- <Status label={item.status} color={getInvoiceStatusColor(item.status)} />
133
+ <Typography component="span" sx={{ flex: 2, textAlign: 'right' }}>
134
+ <Status label={item.status} color={getInvoiceStatusColor(item.status)} sx={{ flex: 2 }} />
135
+ </Typography>
134
136
  </ListItem>
135
137
  );
136
138
  })}
137
139
  </List>
138
140
  </Box>
139
- <Button target="_top" variant="contained" sx={{ marginTop: 'auto', width: '100%' }} href="">
141
+ <Button target="_top" variant="contained" sx={{ marginTop: '10px 0', width: '100%' }} href="">
140
142
  {t('payment.customer.subscriptions.title')}
141
143
  </Button>
142
144
  </Box>
@@ -149,15 +151,12 @@ function Position({ children }: any) {
149
151
  <Box
150
152
  className="mini-invoice-box" // 预留 class 用于设置定位
151
153
  sx={{
152
- position: 'absolute',
153
- right: 0,
154
- top: '30px',
155
154
  justifyContent: 'center',
156
155
  padding: '8px',
157
- minWidth: '400px',
156
+ width: '100%',
157
+ maxWidth: '500px',
158
158
  background: '#fff',
159
- zIndex: 9,
160
- boxShadow: '0 4px 8px rgba(0, 0, 0, 20%)',
159
+ margin: '0 auto',
161
160
  }}>
162
161
  {children}
163
162
  </Box>
package/src/index.ts CHANGED
@@ -8,9 +8,9 @@ import PricingTable from './components/pricing-table';
8
8
  import Status from './components/status';
9
9
  import Switch from './components/switch-button';
10
10
  import dayjs from './dayjs';
11
- import CustomerInvoiceList from './histroy/invoice/list';
12
- import MiniInvoiceList from './histroy/mini-invoice/list';
13
- import CustomerPaymentList from './histroy/payment/list';
11
+ import CustomerInvoiceList from './history/invoice/list';
12
+ import MiniInvoiceList from './history/mini-invoice/list';
13
+ import CustomerPaymentList from './history/payment/list';
14
14
  import Amount from './payment/amount';
15
15
  import PhoneInput from './payment/form/phone';
16
16
  import Payment from './payment/index';
@@ -216,7 +216,7 @@ export default flat({
216
216
  plan: 'Plan',
217
217
  nextInvoice: 'Next Invoice',
218
218
  title: 'Manage subscriptions',
219
- current: 'Current subscriptions',
219
+ current: 'Current subscription',
220
220
  empty: 'Seems you do not have any subscriptions here',
221
221
  },
222
222
  },
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- type Props = {
3
- customer_id: string;
4
- };
5
- export default function CustomerInvoiceList({ customer_id }: Props): import("react").JSX.Element;
6
- export {};
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- import type { TSubscriptionExpanded } from '@blocklet/payment-types';
3
- type Props = {
4
- subscription: TSubscriptionExpanded;
5
- };
6
- export default function MiniInvoiceList({ subscription }: Props): import("react").JSX.Element;
7
- export {};
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- type Props = {
3
- customer_id: string;
4
- };
5
- export default function CustomerInvoiceList({ customer_id }: Props): import("react").JSX.Element;
6
- export {};
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- import type { TSubscriptionExpanded } from '@blocklet/payment-types';
3
- type Props = {
4
- subscription: TSubscriptionExpanded;
5
- };
6
- export default function MiniInvoiceList({ subscription }: Props): import("react").JSX.Element;
7
- export {};
File without changes
File without changes
File without changes
File without changes
File without changes