@blocklet/payment-react 1.18.56 → 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 (251) hide show
  1. package/es/checkout/donate.d.ts +1 -15
  2. package/es/checkout/donate.js +301 -189
  3. package/es/checkout/form.d.ts +1 -15
  4. package/es/checkout/form.js +5 -13
  5. package/es/checkout/table.js +3 -3
  6. package/es/components/blockchain/gas.d.ts +1 -5
  7. package/es/components/blockchain/gas.js +10 -2
  8. package/es/components/blockchain/tx.d.ts +1 -8
  9. package/es/components/blockchain/tx.js +29 -10
  10. package/es/components/confirm.d.ts +1 -10
  11. package/es/components/confirm.js +4 -10
  12. package/es/components/country-select.d.ts +3 -2
  13. package/es/components/country-select.js +375 -352
  14. package/es/components/date-range-picker.d.ts +13 -0
  15. package/es/components/date-range-picker.js +279 -0
  16. package/es/components/input.d.ts +14 -20
  17. package/es/components/input.js +51 -44
  18. package/es/components/label.d.ts +7 -0
  19. package/es/components/label.js +49 -0
  20. package/es/components/lazy-loader.js +1 -2
  21. package/es/components/link.d.ts +2 -9
  22. package/es/components/link.js +9 -6
  23. package/es/components/livemode.d.ts +2 -8
  24. package/es/components/livemode.js +1 -5
  25. package/es/components/loading-button.d.ts +6 -1
  26. package/es/components/loading-button.js +56 -66
  27. package/es/components/over-due-invoice-payment.d.ts +0 -18
  28. package/es/components/over-due-invoice-payment.js +138 -95
  29. package/es/components/payment-beneficiaries.d.ts +2 -7
  30. package/es/components/payment-beneficiaries.js +86 -40
  31. package/es/components/pricing-item.d.ts +0 -5
  32. package/es/components/pricing-item.js +1 -4
  33. package/es/components/pricing-table.d.ts +2 -10
  34. package/es/components/pricing-table.js +8 -7
  35. package/es/components/resume-subscription.d.ts +0 -10
  36. package/es/components/resume-subscription.js +42 -21
  37. package/es/components/truncated-text.d.ts +2 -9
  38. package/es/components/truncated-text.js +0 -5
  39. package/es/contexts/donate.d.ts +0 -7
  40. package/es/contexts/donate.js +10 -8
  41. package/es/contexts/payment.d.ts +1 -4
  42. package/es/contexts/payment.js +7 -2
  43. package/es/history/credit/grants-list.d.ts +14 -0
  44. package/es/history/credit/grants-list.js +215 -0
  45. package/es/history/credit/transactions-list.d.ts +13 -0
  46. package/es/history/credit/transactions-list.js +255 -0
  47. package/es/history/invoice/list.d.ts +2 -18
  48. package/es/history/invoice/list.js +172 -74
  49. package/es/history/payment/list.js +115 -38
  50. package/es/hooks/keyboard.d.ts +1 -1
  51. package/es/hooks/keyboard.js +2 -4
  52. package/es/index.d.ts +5 -1
  53. package/es/index.js +10 -1
  54. package/es/libs/cached-request.js +2 -4
  55. package/es/libs/phone-validator.js +1 -2
  56. package/es/libs/util.d.ts +2 -0
  57. package/es/libs/util.js +14 -4
  58. package/es/libs/validator.js +2 -4
  59. package/es/locales/en.js +20 -2
  60. package/es/locales/zh.js +20 -2
  61. package/es/payment/amount.d.ts +2 -7
  62. package/es/payment/amount.js +1 -5
  63. package/es/payment/donation-form.d.ts +2 -10
  64. package/es/payment/donation-form.js +196 -160
  65. package/es/payment/error.d.ts +2 -8
  66. package/es/payment/error.js +40 -20
  67. package/es/payment/footer.d.ts +2 -3
  68. package/es/payment/footer.js +19 -6
  69. package/es/payment/form/addon.js +14 -4
  70. package/es/payment/form/address.d.ts +2 -9
  71. package/es/payment/form/address.js +3 -6
  72. package/es/payment/form/currency.js +45 -25
  73. package/es/payment/form/index.d.ts +2 -8
  74. package/es/payment/form/index.js +151 -71
  75. package/es/payment/form/phone.js +2 -4
  76. package/es/payment/form/stripe/form.d.ts +2 -8
  77. package/es/payment/form/stripe/form.js +1 -3
  78. package/es/payment/header.js +38 -16
  79. package/es/payment/index.d.ts +2 -9
  80. package/es/payment/index.js +23 -17
  81. package/es/payment/product-card.d.ts +2 -11
  82. package/es/payment/product-card.js +84 -50
  83. package/es/payment/product-donation.js +175 -114
  84. package/es/payment/product-item.d.ts +9 -9
  85. package/es/payment/product-item.js +320 -145
  86. package/es/payment/product-skeleton.js +2 -2
  87. package/es/payment/skeleton/donation.js +27 -7
  88. package/es/payment/skeleton/overview.js +22 -2
  89. package/es/payment/skeleton/payment.js +33 -5
  90. package/es/payment/success.d.ts +2 -9
  91. package/es/payment/success.js +41 -14
  92. package/es/payment/summary.d.ts +4 -17
  93. package/es/payment/summary.js +193 -111
  94. package/es/theme/index.d.ts +0 -5
  95. package/es/theme/index.js +2 -5
  96. package/es/theme/typography.d.ts +2 -2
  97. package/lib/checkout/donate.d.ts +1 -15
  98. package/lib/checkout/donate.js +75 -54
  99. package/lib/checkout/form.d.ts +1 -15
  100. package/lib/checkout/form.js +7 -15
  101. package/lib/checkout/table.js +4 -4
  102. package/lib/components/blockchain/gas.d.ts +1 -5
  103. package/lib/components/blockchain/gas.js +3 -2
  104. package/lib/components/blockchain/tx.d.ts +1 -8
  105. package/lib/components/blockchain/tx.js +15 -10
  106. package/lib/components/confirm.d.ts +1 -10
  107. package/lib/components/confirm.js +5 -11
  108. package/lib/components/country-select.d.ts +3 -2
  109. package/lib/components/country-select.js +23 -22
  110. package/lib/components/date-range-picker.d.ts +13 -0
  111. package/lib/components/date-range-picker.js +329 -0
  112. package/lib/components/input.d.ts +14 -20
  113. package/lib/components/input.js +28 -27
  114. package/lib/components/label.d.ts +7 -0
  115. package/lib/components/label.js +60 -0
  116. package/lib/components/lazy-loader.js +1 -1
  117. package/lib/components/link.d.ts +2 -9
  118. package/lib/components/link.js +3 -8
  119. package/lib/components/livemode.d.ts +2 -8
  120. package/lib/components/livemode.js +3 -7
  121. package/lib/components/loading-button.d.ts +6 -1
  122. package/lib/components/loading-button.js +9 -17
  123. package/lib/components/over-due-invoice-payment.d.ts +0 -18
  124. package/lib/components/over-due-invoice-payment.js +31 -33
  125. package/lib/components/payment-beneficiaries.d.ts +2 -7
  126. package/lib/components/payment-beneficiaries.js +12 -11
  127. package/lib/components/pricing-item.d.ts +0 -5
  128. package/lib/components/pricing-item.js +2 -5
  129. package/lib/components/pricing-table.d.ts +2 -10
  130. package/lib/components/pricing-table.js +5 -11
  131. package/lib/components/resume-subscription.d.ts +0 -10
  132. package/lib/components/resume-subscription.js +16 -16
  133. package/lib/components/table.js +1 -1
  134. package/lib/components/truncated-text.d.ts +2 -9
  135. package/lib/components/truncated-text.js +1 -6
  136. package/lib/contexts/donate.d.ts +0 -7
  137. package/lib/contexts/donate.js +4 -7
  138. package/lib/contexts/payment.d.ts +1 -4
  139. package/lib/contexts/payment.js +4 -7
  140. package/lib/history/credit/grants-list.d.ts +14 -0
  141. package/lib/history/credit/grants-list.js +277 -0
  142. package/lib/history/credit/transactions-list.d.ts +13 -0
  143. package/lib/history/credit/transactions-list.js +301 -0
  144. package/lib/history/invoice/list.d.ts +2 -18
  145. package/lib/history/invoice/list.js +73 -37
  146. package/lib/history/payment/list.js +30 -16
  147. package/lib/hooks/keyboard.d.ts +1 -1
  148. package/lib/hooks/mobile.js +1 -1
  149. package/lib/hooks/subscription.js +1 -1
  150. package/lib/index.d.ts +5 -1
  151. package/lib/index.js +41 -2
  152. package/lib/libs/api.js +1 -1
  153. package/lib/libs/dayjs.js +1 -1
  154. package/lib/libs/phone-validator.js +0 -2
  155. package/lib/libs/theme.js +1 -1
  156. package/lib/libs/util.d.ts +2 -0
  157. package/lib/libs/util.js +15 -1
  158. package/lib/libs/validator.js +1 -1
  159. package/lib/locales/en.js +21 -3
  160. package/lib/locales/index.js +1 -1
  161. package/lib/locales/zh.js +21 -3
  162. package/lib/payment/amount.d.ts +2 -7
  163. package/lib/payment/amount.js +2 -6
  164. package/lib/payment/donation-form.d.ts +2 -10
  165. package/lib/payment/donation-form.js +33 -38
  166. package/lib/payment/error.d.ts +2 -8
  167. package/lib/payment/error.js +11 -13
  168. package/lib/payment/footer.d.ts +2 -3
  169. package/lib/payment/footer.js +5 -5
  170. package/lib/payment/form/addon.js +5 -3
  171. package/lib/payment/form/address.d.ts +2 -9
  172. package/lib/payment/form/address.js +5 -8
  173. package/lib/payment/form/currency.js +3 -3
  174. package/lib/payment/form/index.d.ts +2 -8
  175. package/lib/payment/form/index.js +64 -21
  176. package/lib/payment/form/phone.js +1 -1
  177. package/lib/payment/form/stripe/form.d.ts +2 -8
  178. package/lib/payment/form/stripe/form.js +3 -6
  179. package/lib/payment/header.js +8 -4
  180. package/lib/payment/index.d.ts +2 -9
  181. package/lib/payment/index.js +27 -18
  182. package/lib/payment/product-card.d.ts +2 -11
  183. package/lib/payment/product-card.js +13 -20
  184. package/lib/payment/product-donation.js +71 -66
  185. package/lib/payment/product-item.d.ts +9 -9
  186. package/lib/payment/product-item.js +168 -29
  187. package/lib/payment/product-skeleton.js +2 -2
  188. package/lib/payment/skeleton/donation.js +8 -4
  189. package/lib/payment/skeleton/overview.js +6 -2
  190. package/lib/payment/skeleton/payment.js +9 -3
  191. package/lib/payment/success.d.ts +2 -9
  192. package/lib/payment/success.js +12 -15
  193. package/lib/payment/summary.d.ts +4 -17
  194. package/lib/payment/summary.js +53 -45
  195. package/lib/theme/index.d.ts +0 -5
  196. package/lib/theme/index.js +2 -5
  197. package/lib/theme/typography.d.ts +2 -2
  198. package/package.json +40 -40
  199. package/src/checkout/donate.tsx +103 -35
  200. package/src/checkout/form.tsx +5 -14
  201. package/src/checkout/table.tsx +3 -3
  202. package/src/components/blockchain/gas.tsx +5 -3
  203. package/src/components/blockchain/tx.tsx +19 -11
  204. package/src/components/confirm.tsx +4 -11
  205. package/src/components/country-select.tsx +391 -378
  206. package/src/components/date-range-picker.tsx +310 -0
  207. package/src/components/input.tsx +61 -46
  208. package/src/components/label.tsx +58 -0
  209. package/src/components/link.tsx +9 -7
  210. package/src/components/livemode.tsx +2 -6
  211. package/src/components/loading-button.tsx +63 -76
  212. package/src/components/over-due-invoice-payment.tsx +43 -28
  213. package/src/components/payment-beneficiaries.tsx +33 -14
  214. package/src/components/pricing-item.tsx +1 -4
  215. package/src/components/pricing-table.tsx +8 -8
  216. package/src/components/resume-subscription.tsx +20 -14
  217. package/src/components/table.tsx +2 -2
  218. package/src/components/truncated-text.tsx +0 -6
  219. package/src/contexts/donate.tsx +6 -7
  220. package/src/contexts/payment.tsx +7 -3
  221. package/src/history/credit/grants-list.tsx +276 -0
  222. package/src/history/credit/transactions-list.tsx +317 -0
  223. package/src/history/invoice/list.tsx +92 -36
  224. package/src/history/payment/list.tsx +53 -16
  225. package/src/hooks/keyboard.ts +1 -1
  226. package/src/index.ts +9 -0
  227. package/src/libs/util.ts +14 -0
  228. package/src/locales/en.tsx +20 -0
  229. package/src/locales/zh.tsx +19 -0
  230. package/src/payment/amount.tsx +1 -6
  231. package/src/payment/donation-form.tsx +47 -29
  232. package/src/payment/error.tsx +16 -8
  233. package/src/payment/footer.tsx +11 -3
  234. package/src/payment/form/addon.tsx +6 -1
  235. package/src/payment/form/address.tsx +3 -7
  236. package/src/payment/form/currency.tsx +12 -2
  237. package/src/payment/form/index.tsx +121 -45
  238. package/src/payment/form/stripe/form.tsx +1 -5
  239. package/src/payment/header.tsx +14 -2
  240. package/src/payment/index.tsx +27 -22
  241. package/src/payment/product-card.tsx +41 -18
  242. package/src/payment/product-donation.tsx +85 -47
  243. package/src/payment/product-item.tsx +198 -28
  244. package/src/payment/product-skeleton.tsx +3 -2
  245. package/src/payment/skeleton/donation.tsx +12 -2
  246. package/src/payment/skeleton/overview.tsx +12 -2
  247. package/src/payment/skeleton/payment.tsx +16 -3
  248. package/src/payment/success.tsx +26 -15
  249. package/src/payment/summary.tsx +87 -44
  250. package/src/theme/index.tsx +5 -8
  251. package/src/theme/typography.ts +2 -2
@@ -27,11 +27,13 @@ const recoverSubscription = async (params) => {
27
27
  };
28
28
  function RecoverSubscription({
29
29
  subscriptionId,
30
- dialogProps = {},
30
+ dialogProps = {
31
+ open: true
32
+ },
31
33
  onResumed = () => {
32
34
  },
33
35
  successToast = true,
34
- authToken
36
+ authToken = void 0
35
37
  }) {
36
38
  const { t, locale } = useLocaleContext();
37
39
  const { connect } = usePaymentContext();
@@ -133,26 +135,45 @@ function RecoverSubscription({
133
135
  title: dialogProps?.title || t("payment.customer.recover.title"),
134
136
  sx: { "& .MuiDialogContent-root": { pt: 0 } },
135
137
  onClose: handleClose,
136
- children: error ? /* @__PURE__ */ jsx(Alert, { severity: "error", children: error.message }) : /* @__PURE__ */ jsxs(Stack, { gap: 2, children: [
137
- /* @__PURE__ */ jsx(Typography, { color: "text.secondary", variant: "body2", children: t("payment.customer.recover.description", {
138
- date: formatToDate(Number(data?.subscription?.current_period_end || "0") * 1e3)
139
- }) }),
140
- needStake && /* @__PURE__ */ jsx(Alert, { severity: "warning", children: t("payment.customer.recover.stakeRequiredDescription") }),
141
- /* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "flex-end", gap: 2, mt: 2, children: [
142
- /* @__PURE__ */ jsx(Button, { variant: "outlined", color: "primary", onClick: handleClose, children: t("common.cancel") }),
143
- /* @__PURE__ */ jsx(LoadingButton, { variant: "contained", size: "small", loading: recoverLoading, onClick: handleRecover, children: t("common.confirm") })
144
- ] })
145
- ] })
138
+ children: error ? /* @__PURE__ */ jsx(Alert, { severity: "error", children: error.message }) : /* @__PURE__ */ jsxs(
139
+ Stack,
140
+ {
141
+ sx: {
142
+ gap: 2
143
+ },
144
+ children: [
145
+ /* @__PURE__ */ jsx(
146
+ Typography,
147
+ {
148
+ variant: "body2",
149
+ sx: {
150
+ color: "text.secondary"
151
+ },
152
+ children: t("payment.customer.recover.description", {
153
+ date: formatToDate(Number(data?.subscription?.current_period_end || "0") * 1e3)
154
+ })
155
+ }
156
+ ),
157
+ needStake && /* @__PURE__ */ jsx(Alert, { severity: "warning", children: t("payment.customer.recover.stakeRequiredDescription") }),
158
+ /* @__PURE__ */ jsxs(
159
+ Stack,
160
+ {
161
+ direction: "row",
162
+ sx: {
163
+ justifyContent: "flex-end",
164
+ gap: 2,
165
+ mt: 2
166
+ },
167
+ children: [
168
+ /* @__PURE__ */ jsx(Button, { variant: "outlined", color: "primary", onClick: handleClose, children: t("common.cancel") }),
169
+ /* @__PURE__ */ jsx(LoadingButton, { variant: "contained", size: "small", loading: recoverLoading, onClick: handleRecover, children: t("common.confirm") })
170
+ ]
171
+ }
172
+ )
173
+ ]
174
+ }
175
+ )
146
176
  }
147
177
  );
148
178
  }
149
- RecoverSubscription.defaultProps = {
150
- onResumed: () => {
151
- },
152
- dialogProps: {
153
- open: true
154
- },
155
- successToast: true,
156
- authToken: void 0
157
- };
158
179
  export default RecoverSubscription;
@@ -3,12 +3,5 @@ interface TruncatedTextProps {
3
3
  maxLength?: number;
4
4
  useWidth?: boolean;
5
5
  }
6
- declare function TruncatedText({ text, maxLength, useWidth }: TruncatedTextProps): import("react").JSX.Element | null;
7
- declare namespace TruncatedText {
8
- var defaultProps: {
9
- useWidth: boolean;
10
- text: string;
11
- maxLength: number;
12
- };
13
- }
14
- export default TruncatedText;
6
+ export default function TruncatedText({ text, maxLength, useWidth }: TruncatedTextProps): import("react").JSX.Element | null;
7
+ export {};
@@ -21,8 +21,3 @@ export default function TruncatedText({ text = "", maxLength = 100, useWidth = f
21
21
  }
22
22
  return /* @__PURE__ */ jsx(CustomTooltip, { title: text, placement: "bottom", enterTouchDelay: 0, children: /* @__PURE__ */ jsx(Typography, { children: truncatedText }) });
23
23
  }
24
- TruncatedText.defaultProps = {
25
- useWidth: false,
26
- text: "",
27
- maxLength: 100
28
- };
@@ -28,13 +28,6 @@ export type DonateContextProps = {
28
28
  declare const DonateContext: import("react").Context<DonateContextType>;
29
29
  declare const Consumer: import("react").Consumer<DonateContextType>;
30
30
  declare function DonateProvider({ mountLocation, description, defaultSettings, children, active, enableDonate, }: DonateContextProps): import("react").JSX.Element | null;
31
- declare namespace DonateProvider {
32
- var defaultProps: {
33
- defaultSettings: {};
34
- active: boolean;
35
- enableDonate: boolean;
36
- };
37
- }
38
31
  declare function useDonateContext(): DonateContextType;
39
32
  export declare const clearDonateCache: (mountLocation: string) => void;
40
33
  export declare const clearDonateSettings: (mountLocation: string) => Promise<void>;
@@ -83,8 +83,7 @@ function DonateProvider({
83
83
  };
84
84
  const supportPaymentKit = getPaymentKitComponent();
85
85
  const handleEnable = async () => {
86
- if (!enableDonate || !data || data?.active)
87
- return;
86
+ if (!enableDonate || !data || data?.active) return;
88
87
  try {
89
88
  await api.put(`/api/settings/${data.id}`, { active: true });
90
89
  if (supportPaymentKit) {
@@ -111,7 +110,15 @@ function DonateProvider({
111
110
  },
112
111
  children: data?.active === false ? /* @__PURE__ */ jsxs(Fragment, { children: [
113
112
  enableDonate && isAdmin && /* @__PURE__ */ jsxs(Stack, { spacing: 1, sx: { alignItems: "center" }, children: [
114
- /* @__PURE__ */ jsx(Typography, { color: "text.secondary", children: t("payment.checkout.donation.inactive") }),
113
+ /* @__PURE__ */ jsx(
114
+ Typography,
115
+ {
116
+ sx: {
117
+ color: "text.secondary"
118
+ },
119
+ children: t("payment.checkout.donation.inactive")
120
+ }
121
+ ),
115
122
  /* @__PURE__ */ jsx(
116
123
  Button,
117
124
  {
@@ -151,11 +158,6 @@ function useDonateContext() {
151
158
  const context = useContext(DonateContext);
152
159
  return context;
153
160
  }
154
- DonateProvider.defaultProps = {
155
- defaultSettings: {},
156
- active: true,
157
- enableDonate: false
158
- };
159
161
  export const clearDonateCache = (mountLocation) => {
160
162
  const livemode = localStorage.getItem("livemode") !== "false";
161
163
  const cacheKey = `donate-settings-${mountLocation}-${livemode}`;
@@ -29,9 +29,6 @@ export type PaymentContextProps = {
29
29
  };
30
30
  declare const PaymentContext: import("react").Context<PaymentContextType>;
31
31
  declare const Consumer: import("react").Consumer<PaymentContextType>;
32
- declare function PaymentProvider({ session, connect, children, baseUrl, authToken }: PaymentContextProps): import("react").JSX.Element | null;
33
- declare namespace PaymentProvider {
34
- var defaultProps: {};
35
- }
32
+ declare function PaymentProvider({ session, connect, children, baseUrl, authToken, }: PaymentContextProps): import("react").JSX.Element | null;
36
33
  declare function usePaymentContext(): PaymentContextType;
37
34
  export { PaymentContext, PaymentProvider, Consumer as SettingsConsumer, usePaymentContext };
@@ -48,7 +48,13 @@ const syncToSpaceRequest = (userDid, spaceDid) => {
48
48
  return res;
49
49
  });
50
50
  };
51
- function PaymentProvider({ session, connect, children, baseUrl, authToken }) {
51
+ function PaymentProvider({
52
+ session,
53
+ connect,
54
+ children,
55
+ baseUrl = void 0,
56
+ authToken = void 0
57
+ }) {
52
58
  const [crossOriginLoading, setCrossOriginLoading] = useState(false);
53
59
  if (authToken) {
54
60
  window.__PAYMENT_KIT_AUTH_TOKEN = authToken;
@@ -150,5 +156,4 @@ function usePaymentContext() {
150
156
  const context = useContext(PaymentContext);
151
157
  return context;
152
158
  }
153
- PaymentProvider.defaultProps = {};
154
159
  export { PaymentContext, PaymentProvider, Consumer as SettingsConsumer, usePaymentContext };
@@ -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 {};
@@ -0,0 +1,215 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
+ import { Box, Typography, Chip } from "@mui/material";
4
+ import { useRequest } from "ahooks";
5
+ import React, { useEffect, useRef, useState } from "react";
6
+ import { useNavigate } from "react-router-dom";
7
+ import { styled } from "@mui/system";
8
+ import { formatBNStr, formatToDate } from "../../libs/util.js";
9
+ import { usePaymentContext } from "../../contexts/payment.js";
10
+ import api from "../../libs/api.js";
11
+ import Table from "../../components/table.js";
12
+ import { createLink, handleNavigation } from "../../libs/navigation.js";
13
+ const fetchData = (params = {}) => {
14
+ const search = new URLSearchParams();
15
+ Object.keys(params).forEach((key) => {
16
+ if (params[key]) {
17
+ search.set(key, String(params[key]));
18
+ }
19
+ });
20
+ return api.get(`/api/credit-grants?${search.toString()}`).then((res) => res.data);
21
+ };
22
+ export function StatusChip({ status, label }) {
23
+ const getStatusColor = (statusValue) => {
24
+ switch (statusValue) {
25
+ case "granted":
26
+ return "success";
27
+ case "pending":
28
+ return "warning";
29
+ case "expired":
30
+ return "default";
31
+ case "depleted":
32
+ return "default";
33
+ case "voided":
34
+ return "default";
35
+ default:
36
+ return "default";
37
+ }
38
+ };
39
+ return /* @__PURE__ */ jsx(Chip, { label: label || status, size: "small", color: getStatusColor(status) });
40
+ }
41
+ const getLink = (grant, inDashboard) => {
42
+ let path = `/customer/credit-grant/${grant.id}`;
43
+ if (inDashboard) {
44
+ path = `/admin/customers/${grant.id}`;
45
+ }
46
+ return {
47
+ link: createLink(path),
48
+ connect: false
49
+ };
50
+ };
51
+ const GrantsTable = React.memo((props) => {
52
+ const { pageSize, status = "", customer_id, subscription_id, onTableDataChange } = props;
53
+ const listKey = "credit-grants-table";
54
+ const { t, locale } = useLocaleContext();
55
+ const { session } = usePaymentContext();
56
+ const navigate = useNavigate();
57
+ const isAdmin = ["owner", "admin"].includes(session?.user?.role || "");
58
+ const inDashboard = props.mode === "dashboard" && isAdmin;
59
+ const effectiveCustomerId = customer_id || session?.user?.did;
60
+ const [search, setSearch] = useState({
61
+ pageSize: pageSize || 10,
62
+ page: 1
63
+ });
64
+ const { loading, data = { list: [], count: 0 } } = useRequest(
65
+ () => fetchData({
66
+ ...search,
67
+ status,
68
+ customer_id: effectiveCustomerId,
69
+ subscription_id
70
+ }),
71
+ {
72
+ refreshDeps: [search, status, effectiveCustomerId, subscription_id]
73
+ }
74
+ );
75
+ const prevData = useRef(data);
76
+ const handleLinkClick = (e, grant) => {
77
+ const { link } = getLink(grant, inDashboard);
78
+ handleNavigation(e, link, navigate, { target: link.external ? "_blank" : "_self" });
79
+ };
80
+ useEffect(() => {
81
+ if (onTableDataChange) {
82
+ onTableDataChange(data, prevData.current);
83
+ prevData.current = data;
84
+ }
85
+ }, [data]);
86
+ const columns = [
87
+ {
88
+ label: t("common.name"),
89
+ name: "name",
90
+ options: {
91
+ customBodyRenderLite: (_, index) => {
92
+ const grant = data?.list[index];
93
+ return /* @__PURE__ */ jsx(Box, { onClick: (e) => handleLinkClick(e, grant), children: grant.name || grant.id });
94
+ }
95
+ }
96
+ },
97
+ {
98
+ label: t("common.status"),
99
+ name: "status",
100
+ options: {
101
+ customBodyRenderLite: (_, index) => {
102
+ const grant = data?.list[index];
103
+ return /* @__PURE__ */ jsx(Box, { onClick: (e) => handleLinkClick(e, grant), children: /* @__PURE__ */ jsx(StatusChip, { status: grant.status, label: t(`admin.customer.creditGrants.status.${grant.status}`) }) });
104
+ }
105
+ }
106
+ },
107
+ {
108
+ label: t("common.remainingCredit"),
109
+ name: "remaining_amount",
110
+ align: "right",
111
+ options: {
112
+ customBodyRenderLite: (_, index) => {
113
+ const grant = data?.list[index];
114
+ return /* @__PURE__ */ jsx(Box, { onClick: (e) => handleLinkClick(e, grant), children: /* @__PURE__ */ jsxs(Typography, { variant: "body2", children: [
115
+ formatBNStr(grant.remaining_amount, grant.paymentCurrency.decimal),
116
+ " ",
117
+ grant.paymentCurrency.symbol
118
+ ] }) });
119
+ }
120
+ }
121
+ },
122
+ {
123
+ label: t("common.scope"),
124
+ name: "scope",
125
+ options: {
126
+ customBodyRenderLite: (_, index) => {
127
+ const grant = data?.list[index];
128
+ let scope = "general";
129
+ if (grant.applicability_config?.scope?.prices) {
130
+ scope = "specific";
131
+ }
132
+ return /* @__PURE__ */ jsx(Box, { onClick: (e) => handleLinkClick(e, grant), children: scope === "specific" ? t("common.specific") : t("common.general") });
133
+ }
134
+ }
135
+ },
136
+ {
137
+ label: t("common.effectiveDate"),
138
+ name: "effective_at",
139
+ options: {
140
+ customBodyRenderLite: (_, index) => {
141
+ const grant = data?.list[index];
142
+ const effectiveAt = grant.effective_at ? grant.effective_at * 1e3 : grant.created_at;
143
+ return /* @__PURE__ */ jsx(Box, { onClick: (e) => handleLinkClick(e, grant), children: formatToDate(effectiveAt, locale, "YYYY-MM-DD HH:mm") });
144
+ }
145
+ }
146
+ },
147
+ {
148
+ label: t("common.expirationDate"),
149
+ name: "expires_at",
150
+ options: {
151
+ customBodyRenderLite: (_, index) => {
152
+ const grant = data?.list[index];
153
+ return /* @__PURE__ */ jsx(Box, { onClick: (e) => handleLinkClick(e, grant), children: /* @__PURE__ */ jsx(Typography, { variant: "body2", children: grant.expires_at ? formatToDate(grant.expires_at * 1e3, locale, "YYYY-MM-DD HH:mm") : "-" }) });
154
+ }
155
+ }
156
+ }
157
+ ];
158
+ const onTableChange = ({ page, rowsPerPage }) => {
159
+ if (search.pageSize !== rowsPerPage) {
160
+ setSearch((x) => ({ ...x, pageSize: rowsPerPage, page: 1 }));
161
+ } else if (search.page !== page + 1) {
162
+ setSearch((x) => ({ ...x, page: page + 1 }));
163
+ }
164
+ };
165
+ return /* @__PURE__ */ jsx(TableRoot, { children: /* @__PURE__ */ jsx(
166
+ Table,
167
+ {
168
+ hasRowLink: true,
169
+ durable: `__${listKey}__`,
170
+ durableKeys: ["page", "rowsPerPage", "searchText"],
171
+ data: data.list,
172
+ columns,
173
+ options: {
174
+ count: data.count,
175
+ page: search.page - 1,
176
+ rowsPerPage: search.pageSize
177
+ },
178
+ loading,
179
+ onChange: onTableChange,
180
+ toolbar: false,
181
+ sx: { mt: 2 },
182
+ showMobile: false,
183
+ mobileTDFlexDirection: "row",
184
+ emptyNodeText: t("admin.creditGrants.noGrants")
185
+ }
186
+ ) });
187
+ });
188
+ const TableRoot = styled(Box)`
189
+ @media (max-width: ${({ theme }) => theme.breakpoints.values.md}px) {
190
+ .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > td.MuiTableCell-root {
191
+ > div {
192
+ width: fit-content;
193
+ flex: inherit;
194
+ font-size: 14px;
195
+ }
196
+ }
197
+ .invoice-summary {
198
+ padding-right: 20px;
199
+ }
200
+ }
201
+ `;
202
+ export default function CreditGrantsList(rawProps) {
203
+ const props = Object.assign(
204
+ {
205
+ customer_id: "",
206
+ subscription_id: "",
207
+ status: "granted,pending,depleted,expired",
208
+ pageSize: 10,
209
+ onTableDataChange: () => {
210
+ }
211
+ },
212
+ rawProps
213
+ );
214
+ return /* @__PURE__ */ jsx(GrantsTable, { ...props });
215
+ }
@@ -0,0 +1,13 @@
1
+ type Props = {
2
+ customer_id?: string;
3
+ subscription_id?: string;
4
+ credit_grant_id?: string;
5
+ pageSize?: number;
6
+ onTableDataChange?: Function;
7
+ showAdminColumns?: boolean;
8
+ showTimeFilter?: boolean;
9
+ source?: string;
10
+ mode?: 'dashboard' | 'portal';
11
+ };
12
+ export default function CreditTransactionsList(rawProps: Props): JSX.Element;
13
+ export {};