@blocklet/payment-react 1.19.0 → 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.
Files changed (73) hide show
  1. package/es/components/blockchain/tx.d.ts +1 -1
  2. package/es/components/blockchain/tx.js +9 -11
  3. package/es/components/country-select.d.ts +1 -1
  4. package/es/components/date-range-picker.d.ts +13 -0
  5. package/es/components/date-range-picker.js +279 -0
  6. package/es/components/input.d.ts +5 -2
  7. package/es/components/input.js +6 -2
  8. package/es/components/label.d.ts +7 -0
  9. package/es/components/label.js +49 -0
  10. package/es/components/loading-button.d.ts +1 -1
  11. package/es/history/credit/grants-list.d.ts +14 -0
  12. package/es/history/credit/grants-list.js +215 -0
  13. package/es/history/credit/transactions-list.d.ts +13 -0
  14. package/es/history/credit/transactions-list.js +255 -0
  15. package/es/history/invoice/list.js +21 -1
  16. package/es/index.d.ts +5 -1
  17. package/es/index.js +10 -1
  18. package/es/libs/util.d.ts +2 -0
  19. package/es/libs/util.js +12 -0
  20. package/es/locales/en.js +20 -2
  21. package/es/locales/zh.js +20 -2
  22. package/es/payment/form/index.js +44 -6
  23. package/es/payment/index.js +18 -3
  24. package/es/payment/product-item.d.ts +8 -1
  25. package/es/payment/product-item.js +137 -5
  26. package/es/payment/summary.d.ts +3 -1
  27. package/es/payment/summary.js +9 -0
  28. package/lib/components/blockchain/tx.d.ts +1 -1
  29. package/lib/components/blockchain/tx.js +9 -8
  30. package/lib/components/country-select.d.ts +1 -1
  31. package/lib/components/date-range-picker.d.ts +13 -0
  32. package/lib/components/date-range-picker.js +329 -0
  33. package/lib/components/input.d.ts +5 -2
  34. package/lib/components/input.js +8 -4
  35. package/lib/components/label.d.ts +7 -0
  36. package/lib/components/label.js +60 -0
  37. package/lib/components/loading-button.d.ts +1 -1
  38. package/lib/history/credit/grants-list.d.ts +14 -0
  39. package/lib/history/credit/grants-list.js +277 -0
  40. package/lib/history/credit/transactions-list.d.ts +13 -0
  41. package/lib/history/credit/transactions-list.js +301 -0
  42. package/lib/history/invoice/list.js +24 -0
  43. package/lib/index.d.ts +5 -1
  44. package/lib/index.js +39 -0
  45. package/lib/libs/util.d.ts +2 -0
  46. package/lib/libs/util.js +14 -0
  47. package/lib/locales/en.js +20 -2
  48. package/lib/locales/zh.js +20 -2
  49. package/lib/payment/form/index.js +45 -6
  50. package/lib/payment/index.js +20 -2
  51. package/lib/payment/product-item.d.ts +8 -1
  52. package/lib/payment/product-item.js +144 -4
  53. package/lib/payment/summary.d.ts +3 -1
  54. package/lib/payment/summary.js +9 -0
  55. package/package.json +3 -3
  56. package/src/components/blockchain/tx.tsx +9 -15
  57. package/src/components/country-select.tsx +2 -2
  58. package/src/components/date-range-picker.tsx +310 -0
  59. package/src/components/input.tsx +14 -3
  60. package/src/components/label.tsx +58 -0
  61. package/src/components/loading-button.tsx +1 -1
  62. package/src/history/credit/grants-list.tsx +276 -0
  63. package/src/history/credit/transactions-list.tsx +317 -0
  64. package/src/history/invoice/list.tsx +18 -1
  65. package/src/index.ts +9 -0
  66. package/src/libs/util.ts +14 -0
  67. package/src/locales/en.tsx +20 -0
  68. package/src/locales/zh.tsx +19 -0
  69. package/src/payment/form/address.tsx +2 -2
  70. package/src/payment/form/index.tsx +110 -52
  71. package/src/payment/index.tsx +17 -1
  72. package/src/payment/product-item.tsx +152 -4
  73. package/src/payment/summary.tsx +13 -2
@@ -1,5 +1,5 @@
1
1
  import type { PaymentDetails, TPaymentMethod } from '@blocklet/payment-types';
2
- export default function TxLink(rawProps: {
2
+ export default function TxLink({ details, method, mode, align, }: {
3
3
  details: PaymentDetails;
4
4
  method: TPaymentMethod;
5
5
  mode?: 'customer' | 'dashboard';
@@ -4,16 +4,14 @@ import { OpenInNewOutlined } from "@mui/icons-material";
4
4
  import { Link, Stack, Typography } from "@mui/material";
5
5
  import { styled } from "@mui/system";
6
6
  import { getTxLink } from "../../libs/util.js";
7
- export default function TxLink(rawProps) {
8
- const props = Object.assign(
9
- {
10
- mode: "dashboard",
11
- align: "left"
12
- },
13
- rawProps
14
- );
7
+ export default function TxLink({
8
+ details,
9
+ method,
10
+ mode = "dashboard",
11
+ align = "left"
12
+ }) {
15
13
  const { t } = useLocaleContext();
16
- if (!props.details || props.mode === "customer" && props.method.type === "stripe") {
14
+ if (!details || mode === "customer" && method.type === "stripe") {
17
15
  return /* @__PURE__ */ jsx(
18
16
  Typography,
19
17
  {
@@ -25,14 +23,14 @@ export default function TxLink(rawProps) {
25
23
  }
26
24
  );
27
25
  }
28
- const { text, link } = getTxLink(props.method, props.details);
26
+ const { text, link } = getTxLink(method, details);
29
27
  if (link && text) {
30
28
  return /* @__PURE__ */ jsx(Link, { href: link, target: "_blank", rel: "noopener noreferrer", children: /* @__PURE__ */ jsxs(
31
29
  Root,
32
30
  {
33
31
  direction: "row",
34
32
  alignItems: "center",
35
- justifyContent: props.align === "left" ? "flex-start" : "flex-end",
33
+ justifyContent: align === "left" ? "flex-start" : "flex-end",
36
34
  sx: { color: "text.link" },
37
35
  spacing: 1,
38
36
  children: [
@@ -8,5 +8,5 @@ export type CountrySelectProps = {
8
8
  showDialCode?: boolean;
9
9
  };
10
10
  export default function CountrySelect({ ref, value, onChange, name, sx, showDialCode, }: CountrySelectProps & {
11
- ref?: React.RefObject<HTMLDivElement>;
11
+ ref?: React.RefObject<HTMLDivElement | null>;
12
12
  }): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ export interface DateRangeValue {
2
+ start: number | undefined;
3
+ end: number | undefined;
4
+ }
5
+ export interface DateRangePickerProps {
6
+ value: DateRangeValue;
7
+ onChange: (value: DateRangeValue) => void;
8
+ label?: string;
9
+ size?: 'small' | 'medium';
10
+ fullWidth?: boolean;
11
+ disabled?: boolean;
12
+ }
13
+ export default function DateRangePicker({ value, onChange, label, size, fullWidth, disabled, }: DateRangePickerProps): import("react").JSX.Element;
@@ -0,0 +1,279 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef } from "react";
3
+ import {
4
+ TextField,
5
+ Stack,
6
+ Typography,
7
+ useMediaQuery,
8
+ useTheme,
9
+ Popover,
10
+ Dialog,
11
+ DialogTitle,
12
+ DialogContent,
13
+ DialogActions,
14
+ Button,
15
+ Box,
16
+ IconButton
17
+ } from "@mui/material";
18
+ import { DateRange, Close, Clear } from "@mui/icons-material";
19
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
20
+ import FormLabel from "./label.js";
21
+ import { formatToDate } from "../libs/util.js";
22
+ function DatePickerContent({
23
+ tempValue,
24
+ setTempValue,
25
+ handleCancel,
26
+ handleApply,
27
+ handleClear
28
+ }) {
29
+ const { t } = useLocaleContext();
30
+ return /* @__PURE__ */ jsx(Box, { sx: { p: 2, minWidth: 320 }, children: /* @__PURE__ */ jsxs(Stack, { spacing: 2, children: [
31
+ /* @__PURE__ */ jsxs(Box, { children: [
32
+ /* @__PURE__ */ jsx(FormLabel, { children: t("common.startDate") }),
33
+ /* @__PURE__ */ jsx(
34
+ TextField,
35
+ {
36
+ type: "date",
37
+ value: tempValue.startDate,
38
+ onChange: (e) => setTempValue((prev) => ({ ...prev, startDate: e.target.value })),
39
+ size: "small",
40
+ fullWidth: true,
41
+ slotProps: {
42
+ inputLabel: { shrink: true }
43
+ }
44
+ }
45
+ )
46
+ ] }),
47
+ /* @__PURE__ */ jsxs(Box, { children: [
48
+ /* @__PURE__ */ jsx(FormLabel, { children: t("common.endDate") }),
49
+ /* @__PURE__ */ jsx(
50
+ TextField,
51
+ {
52
+ type: "date",
53
+ value: tempValue.endDate,
54
+ onChange: (e) => setTempValue((prev) => ({ ...prev, endDate: e.target.value })),
55
+ size: "small",
56
+ fullWidth: true,
57
+ slotProps: {
58
+ inputLabel: { shrink: true }
59
+ }
60
+ }
61
+ )
62
+ ] }),
63
+ /* @__PURE__ */ jsxs(
64
+ Stack,
65
+ {
66
+ direction: "row",
67
+ spacing: 1,
68
+ sx: {
69
+ justifyContent: "space-between"
70
+ },
71
+ children: [
72
+ /* @__PURE__ */ jsx(Button, { variant: "text", onClick: handleClear, size: "small", color: "secondary", sx: { px: 0.5, minWidth: 0 }, children: t("common.clear") }),
73
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, children: [
74
+ /* @__PURE__ */ jsx(Button, { variant: "outlined", onClick: handleCancel, size: "small", children: t("common.cancel") }),
75
+ /* @__PURE__ */ jsx(Button, { variant: "contained", onClick: handleApply, size: "small", children: t("common.confirm") })
76
+ ] })
77
+ ]
78
+ }
79
+ )
80
+ ] }) });
81
+ }
82
+ const DateFormat = "YYYY-MM-DD";
83
+ export default function DateRangePicker({
84
+ value,
85
+ onChange,
86
+ label = "",
87
+ size = "small",
88
+ fullWidth = false,
89
+ disabled = false
90
+ }) {
91
+ const theme = useTheme();
92
+ const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
93
+ const [open, setOpen] = useState(false);
94
+ const { t, locale } = useLocaleContext();
95
+ const [tempValue, setTempValue] = useState({
96
+ startDate: value.start ? formatToDate(value.start * 1e3, locale, DateFormat) : "",
97
+ endDate: value.end ? formatToDate(value.end * 1e3, locale, DateFormat) : ""
98
+ });
99
+ const anchorRef = useRef(null);
100
+ const formatDisplayValue = (startUnix, endUnix) => {
101
+ if (!startUnix || !endUnix) return t("common.selectTimeRange");
102
+ const start = formatToDate(startUnix * 1e3, locale, DateFormat);
103
+ const end = formatToDate(endUnix * 1e3, locale, DateFormat);
104
+ return `${start} ~ ${end}`;
105
+ };
106
+ const handleOpen = () => {
107
+ if (disabled) return;
108
+ setTempValue({
109
+ startDate: value.start ? formatToDate(value.start * 1e3, locale, DateFormat) : "",
110
+ endDate: value.end ? formatToDate(value.end * 1e3, locale, DateFormat) : ""
111
+ });
112
+ setOpen(true);
113
+ };
114
+ const handleClose = () => {
115
+ setOpen(false);
116
+ };
117
+ const handleApply = () => {
118
+ const unixValue = {
119
+ start: tempValue.startDate ? Math.floor((/* @__PURE__ */ new Date(`${tempValue.startDate}T00:00:00`)).getTime() / 1e3) : 0,
120
+ end: tempValue.endDate ? Math.floor((/* @__PURE__ */ new Date(`${tempValue.endDate}T23:59:59`)).getTime() / 1e3) : 0
121
+ };
122
+ onChange(unixValue);
123
+ setOpen(false);
124
+ };
125
+ const handleCancel = () => {
126
+ setTempValue({
127
+ startDate: value.start ? formatToDate(value.start * 1e3, locale, DateFormat) : "",
128
+ endDate: value.end ? formatToDate(value.end * 1e3, locale, DateFormat) : ""
129
+ });
130
+ setOpen(false);
131
+ };
132
+ const handleClear = () => {
133
+ const emptyValue = { start: void 0, end: void 0 };
134
+ onChange(emptyValue);
135
+ setTempValue({ startDate: "", endDate: "" });
136
+ setOpen(false);
137
+ };
138
+ const hasValue = !!value.start && !!value.end;
139
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
140
+ /* @__PURE__ */ jsx(
141
+ TextField,
142
+ {
143
+ ref: anchorRef,
144
+ label,
145
+ value: formatDisplayValue(value.start, value.end),
146
+ size,
147
+ fullWidth,
148
+ disabled,
149
+ sx: {
150
+ "& .MuiInputBase-input": {
151
+ cursor: disabled ? "default" : "pointer"
152
+ }
153
+ },
154
+ onClick: handleOpen,
155
+ placeholder: t("common.selectTimeRange"),
156
+ slotProps: {
157
+ input: {
158
+ readOnly: true,
159
+ startAdornment: /* @__PURE__ */ jsx(DateRange, { fontSize: "small", sx: { mr: 1, color: "text.secondary" } }),
160
+ endAdornment: hasValue && !disabled && /* @__PURE__ */ jsx(
161
+ IconButton,
162
+ {
163
+ size: "small",
164
+ onClick: (e) => {
165
+ e.stopPropagation();
166
+ handleClear();
167
+ },
168
+ sx: {
169
+ color: "text.secondary",
170
+ "&:hover": { color: "text.primary" }
171
+ },
172
+ children: /* @__PURE__ */ jsx(Clear, { fontSize: "small" })
173
+ }
174
+ )
175
+ },
176
+ inputLabel: { shrink: true }
177
+ }
178
+ }
179
+ ),
180
+ !isMobile && /* @__PURE__ */ jsx(
181
+ Popover,
182
+ {
183
+ open,
184
+ anchorEl: anchorRef.current,
185
+ onClose: handleClose,
186
+ anchorOrigin: {
187
+ vertical: "bottom",
188
+ horizontal: "left"
189
+ },
190
+ transformOrigin: {
191
+ vertical: "top",
192
+ horizontal: "left"
193
+ },
194
+ sx: {
195
+ "& .MuiPaper-root": {
196
+ boxShadow: theme.shadows[8],
197
+ border: `1px solid ${theme.palette.divider}`
198
+ }
199
+ },
200
+ children: /* @__PURE__ */ jsx(
201
+ DatePickerContent,
202
+ {
203
+ tempValue,
204
+ setTempValue,
205
+ handleCancel,
206
+ handleApply,
207
+ handleClear
208
+ }
209
+ )
210
+ }
211
+ ),
212
+ isMobile && /* @__PURE__ */ jsxs(
213
+ Dialog,
214
+ {
215
+ open,
216
+ onClose: handleClose,
217
+ fullWidth: true,
218
+ maxWidth: "sm",
219
+ PaperProps: {
220
+ sx: {
221
+ m: 1,
222
+ maxHeight: "calc(100% - 64px)"
223
+ }
224
+ },
225
+ children: [
226
+ /* @__PURE__ */ jsxs(
227
+ DialogTitle,
228
+ {
229
+ sx: {
230
+ display: "flex",
231
+ justifyContent: "space-between",
232
+ alignItems: "center",
233
+ pb: 1
234
+ },
235
+ children: [
236
+ /* @__PURE__ */ jsx(Typography, { variant: "h6", children: t("common.selectTimeRange") }),
237
+ /* @__PURE__ */ jsx(IconButton, { edge: "end", color: "inherit", onClick: handleClose, "aria-label": "close", size: "small", children: /* @__PURE__ */ jsx(Close, {}) })
238
+ ]
239
+ }
240
+ ),
241
+ /* @__PURE__ */ jsx(DialogContent, { sx: { pb: 1 }, children: /* @__PURE__ */ jsxs(Stack, { spacing: 2, sx: { mt: 1 }, children: [
242
+ /* @__PURE__ */ jsx(FormLabel, { children: t("common.startDate") }),
243
+ /* @__PURE__ */ jsx(
244
+ TextField,
245
+ {
246
+ type: "date",
247
+ value: tempValue.startDate,
248
+ onChange: (e) => setTempValue((prev) => ({ ...prev, startDate: e.target.value })),
249
+ size: "small",
250
+ fullWidth: true,
251
+ slotProps: {
252
+ inputLabel: { shrink: true }
253
+ }
254
+ }
255
+ ),
256
+ /* @__PURE__ */ jsx(FormLabel, { children: t("common.endDate") }),
257
+ /* @__PURE__ */ jsx(
258
+ TextField,
259
+ {
260
+ type: "date",
261
+ value: tempValue.endDate,
262
+ onChange: (e) => setTempValue((prev) => ({ ...prev, endDate: e.target.value })),
263
+ size: "small",
264
+ fullWidth: true,
265
+ slotProps: {
266
+ inputLabel: { shrink: true }
267
+ }
268
+ }
269
+ )
270
+ ] }) }),
271
+ /* @__PURE__ */ jsxs(DialogActions, { sx: { px: 3, pb: 2 }, children: [
272
+ /* @__PURE__ */ jsx(Button, { onClick: handleCancel, color: "inherit", children: t("common.cancel") }),
273
+ /* @__PURE__ */ jsx(Button, { onClick: handleApply, variant: "contained", children: t("common.confirm") })
274
+ ] })
275
+ ]
276
+ }
277
+ )
278
+ ] });
279
+ }
@@ -8,9 +8,12 @@ type InputProps = TextFieldProps & {
8
8
  errorPosition?: 'right' | 'bottom';
9
9
  rules?: RegisterOptions;
10
10
  wrapperStyle?: React.CSSProperties;
11
+ required?: boolean;
12
+ tooltip?: ReactNode | string;
13
+ description?: ReactNode | string;
11
14
  };
12
- export default function FormInput({ ref, name, label, placeholder, rules, errorPosition, wrapperStyle, inputProps, ...rest }: InputProps & {
13
- ref?: React.RefObject<HTMLInputElement>;
15
+ export default function FormInput({ ref, name, label, placeholder, rules, errorPosition, wrapperStyle, inputProps, required, tooltip, description, ...rest }: InputProps & {
16
+ ref?: React.RefObject<HTMLInputElement | null>;
14
17
  inputProps?: TextFieldProps['inputProps'];
15
18
  }): JSX.Element;
16
19
  export {};
@@ -1,8 +1,9 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useImperativeHandle, useRef } from "react";
3
- import { Box, FormLabel, InputAdornment, TextField, Typography } from "@mui/material";
3
+ import { Box, InputAdornment, TextField, Typography } from "@mui/material";
4
4
  import get from "lodash/get";
5
5
  import { Controller, useFormContext } from "react-hook-form";
6
+ import FormLabel from "./label.js";
6
7
  function FormInputError({ error }) {
7
8
  return /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(Typography, { component: "span", color: "error", children: error }) });
8
9
  }
@@ -15,6 +16,9 @@ export default function FormInput({
15
16
  errorPosition = "bottom",
16
17
  wrapperStyle = {},
17
18
  inputProps = {},
19
+ required = false,
20
+ tooltip = "",
21
+ description = "",
18
22
  ...rest
19
23
  }) {
20
24
  const { control, formState } = useFormContext();
@@ -30,7 +34,7 @@ export default function FormInput({
30
34
  control,
31
35
  rules,
32
36
  render: ({ field }) => /* @__PURE__ */ jsxs(Box, { sx: { width: "100%", ...wrapperStyle }, children: [
33
- !!label && /* @__PURE__ */ jsx(FormLabel, { sx: { color: "text.primary" }, children: label }),
37
+ !!label && /* @__PURE__ */ jsx(FormLabel, { required, tooltip, description, children: label }),
34
38
  /* @__PURE__ */ jsx(
35
39
  TextField,
36
40
  {
@@ -0,0 +1,7 @@
1
+ import type { FormLabelProps } from '@mui/material';
2
+ import type { ReactNode } from 'react';
3
+ export default function CustomFormLabel({ children, required, tooltip, description, ...props }: FormLabelProps & {
4
+ required?: boolean;
5
+ tooltip?: ReactNode | string;
6
+ description?: ReactNode | string;
7
+ }): import("react").JSX.Element;
@@ -0,0 +1,49 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { InfoOutlined } from "@mui/icons-material";
3
+ import { Box, FormLabel, Tooltip, Typography } from "@mui/material";
4
+ export default function CustomFormLabel({
5
+ children,
6
+ required = false,
7
+ tooltip = "",
8
+ description = "",
9
+ ...props
10
+ }) {
11
+ return /* @__PURE__ */ jsxs(Box, { sx: { mb: 1, width: "100%" }, children: [
12
+ /* @__PURE__ */ jsxs(
13
+ FormLabel,
14
+ {
15
+ ...props,
16
+ sx: {
17
+ display: "flex",
18
+ alignItems: "center",
19
+ gap: 0.5,
20
+ fontWeight: 500,
21
+ color: "text.primary",
22
+ "&.MuiFormLabel-root": {
23
+ display: "flex",
24
+ alignItems: "center",
25
+ gap: 0.5,
26
+ fontWeight: 500,
27
+ color: "text.primary"
28
+ },
29
+ ...props.sx || {}
30
+ },
31
+ children: [
32
+ children,
33
+ required && /* @__PURE__ */ jsx(Typography, { component: "span", color: "error", children: "*" }),
34
+ tooltip && (typeof tooltip === "string" ? /* @__PURE__ */ jsx(Tooltip, { title: tooltip, children: /* @__PURE__ */ jsx(InfoOutlined, { fontSize: "small", sx: { opacity: 0.7 } }) }) : tooltip)
35
+ ]
36
+ }
37
+ ),
38
+ description && /* @__PURE__ */ jsx(
39
+ Typography,
40
+ {
41
+ variant: "caption",
42
+ sx: {
43
+ color: "text.secondary"
44
+ },
45
+ children: description
46
+ }
47
+ )
48
+ ] });
49
+ }
@@ -7,7 +7,7 @@ export interface LoadingButtonProps extends ButtonProps {
7
7
  loadingOnly?: boolean;
8
8
  }
9
9
  declare function LoadingButton({ ref, children, loading, loadingPosition, loadingIndicator, loadingProps, loadingOnly, onClick, sx, ...props }: LoadingButtonProps & {
10
- ref?: React.RefObject<HTMLButtonElement>;
10
+ ref?: React.RefObject<HTMLButtonElement | null>;
11
11
  }): import("react").JSX.Element;
12
12
  declare namespace LoadingButton {
13
13
  var displayName: string;
@@ -0,0 +1,14 @@
1
+ type Props = {
2
+ customer_id?: string;
3
+ subscription_id?: string;
4
+ status?: string;
5
+ pageSize?: number;
6
+ onTableDataChange?: Function;
7
+ mode?: 'dashboard' | 'portal';
8
+ };
9
+ export declare function StatusChip({ status, label }: {
10
+ status: string;
11
+ label?: string;
12
+ }): JSX.Element;
13
+ export default function CreditGrantsList(rawProps: Props): JSX.Element;
14
+ export {};