@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.
- package/es/checkout/donate.d.ts +1 -15
- package/es/checkout/donate.js +301 -189
- package/es/checkout/form.d.ts +1 -15
- package/es/checkout/form.js +5 -13
- package/es/checkout/table.js +3 -3
- package/es/components/blockchain/gas.d.ts +1 -5
- package/es/components/blockchain/gas.js +10 -2
- package/es/components/blockchain/tx.d.ts +1 -8
- package/es/components/blockchain/tx.js +29 -10
- package/es/components/confirm.d.ts +1 -10
- package/es/components/confirm.js +4 -10
- package/es/components/country-select.d.ts +3 -2
- package/es/components/country-select.js +375 -352
- package/es/components/date-range-picker.d.ts +13 -0
- package/es/components/date-range-picker.js +279 -0
- package/es/components/input.d.ts +14 -20
- package/es/components/input.js +51 -44
- package/es/components/label.d.ts +7 -0
- package/es/components/label.js +49 -0
- package/es/components/lazy-loader.js +1 -2
- package/es/components/link.d.ts +2 -9
- package/es/components/link.js +9 -6
- package/es/components/livemode.d.ts +2 -8
- package/es/components/livemode.js +1 -5
- package/es/components/loading-button.d.ts +6 -1
- package/es/components/loading-button.js +56 -66
- package/es/components/over-due-invoice-payment.d.ts +0 -18
- package/es/components/over-due-invoice-payment.js +138 -95
- package/es/components/payment-beneficiaries.d.ts +2 -7
- package/es/components/payment-beneficiaries.js +86 -40
- package/es/components/pricing-item.d.ts +0 -5
- package/es/components/pricing-item.js +1 -4
- package/es/components/pricing-table.d.ts +2 -10
- package/es/components/pricing-table.js +8 -7
- package/es/components/resume-subscription.d.ts +0 -10
- package/es/components/resume-subscription.js +42 -21
- package/es/components/truncated-text.d.ts +2 -9
- package/es/components/truncated-text.js +0 -5
- package/es/contexts/donate.d.ts +0 -7
- package/es/contexts/donate.js +10 -8
- package/es/contexts/payment.d.ts +1 -4
- package/es/contexts/payment.js +7 -2
- package/es/history/credit/grants-list.d.ts +14 -0
- package/es/history/credit/grants-list.js +215 -0
- package/es/history/credit/transactions-list.d.ts +13 -0
- package/es/history/credit/transactions-list.js +255 -0
- package/es/history/invoice/list.d.ts +2 -18
- package/es/history/invoice/list.js +172 -74
- package/es/history/payment/list.js +115 -38
- package/es/hooks/keyboard.d.ts +1 -1
- package/es/hooks/keyboard.js +2 -4
- package/es/index.d.ts +5 -1
- package/es/index.js +10 -1
- package/es/libs/cached-request.js +2 -4
- package/es/libs/phone-validator.js +1 -2
- package/es/libs/util.d.ts +2 -0
- package/es/libs/util.js +14 -4
- package/es/libs/validator.js +2 -4
- package/es/locales/en.js +20 -2
- package/es/locales/zh.js +20 -2
- package/es/payment/amount.d.ts +2 -7
- package/es/payment/amount.js +1 -5
- package/es/payment/donation-form.d.ts +2 -10
- package/es/payment/donation-form.js +196 -160
- package/es/payment/error.d.ts +2 -8
- package/es/payment/error.js +40 -20
- package/es/payment/footer.d.ts +2 -3
- package/es/payment/footer.js +19 -6
- package/es/payment/form/addon.js +14 -4
- package/es/payment/form/address.d.ts +2 -9
- package/es/payment/form/address.js +3 -6
- package/es/payment/form/currency.js +45 -25
- package/es/payment/form/index.d.ts +2 -8
- package/es/payment/form/index.js +151 -71
- package/es/payment/form/phone.js +2 -4
- package/es/payment/form/stripe/form.d.ts +2 -8
- package/es/payment/form/stripe/form.js +1 -3
- package/es/payment/header.js +38 -16
- package/es/payment/index.d.ts +2 -9
- package/es/payment/index.js +23 -17
- package/es/payment/product-card.d.ts +2 -11
- package/es/payment/product-card.js +84 -50
- package/es/payment/product-donation.js +175 -114
- package/es/payment/product-item.d.ts +9 -9
- package/es/payment/product-item.js +320 -145
- package/es/payment/product-skeleton.js +2 -2
- package/es/payment/skeleton/donation.js +27 -7
- package/es/payment/skeleton/overview.js +22 -2
- package/es/payment/skeleton/payment.js +33 -5
- package/es/payment/success.d.ts +2 -9
- package/es/payment/success.js +41 -14
- package/es/payment/summary.d.ts +4 -17
- package/es/payment/summary.js +193 -111
- package/es/theme/index.d.ts +0 -5
- package/es/theme/index.js +2 -5
- package/es/theme/typography.d.ts +2 -2
- package/lib/checkout/donate.d.ts +1 -15
- package/lib/checkout/donate.js +75 -54
- package/lib/checkout/form.d.ts +1 -15
- package/lib/checkout/form.js +7 -15
- package/lib/checkout/table.js +4 -4
- package/lib/components/blockchain/gas.d.ts +1 -5
- package/lib/components/blockchain/gas.js +3 -2
- package/lib/components/blockchain/tx.d.ts +1 -8
- package/lib/components/blockchain/tx.js +15 -10
- package/lib/components/confirm.d.ts +1 -10
- package/lib/components/confirm.js +5 -11
- package/lib/components/country-select.d.ts +3 -2
- package/lib/components/country-select.js +23 -22
- package/lib/components/date-range-picker.d.ts +13 -0
- package/lib/components/date-range-picker.js +329 -0
- package/lib/components/input.d.ts +14 -20
- package/lib/components/input.js +28 -27
- package/lib/components/label.d.ts +7 -0
- package/lib/components/label.js +60 -0
- package/lib/components/lazy-loader.js +1 -1
- package/lib/components/link.d.ts +2 -9
- package/lib/components/link.js +3 -8
- package/lib/components/livemode.d.ts +2 -8
- package/lib/components/livemode.js +3 -7
- package/lib/components/loading-button.d.ts +6 -1
- package/lib/components/loading-button.js +9 -17
- package/lib/components/over-due-invoice-payment.d.ts +0 -18
- package/lib/components/over-due-invoice-payment.js +31 -33
- package/lib/components/payment-beneficiaries.d.ts +2 -7
- package/lib/components/payment-beneficiaries.js +12 -11
- package/lib/components/pricing-item.d.ts +0 -5
- package/lib/components/pricing-item.js +2 -5
- package/lib/components/pricing-table.d.ts +2 -10
- package/lib/components/pricing-table.js +5 -11
- package/lib/components/resume-subscription.d.ts +0 -10
- package/lib/components/resume-subscription.js +16 -16
- package/lib/components/table.js +1 -1
- package/lib/components/truncated-text.d.ts +2 -9
- package/lib/components/truncated-text.js +1 -6
- package/lib/contexts/donate.d.ts +0 -7
- package/lib/contexts/donate.js +4 -7
- package/lib/contexts/payment.d.ts +1 -4
- package/lib/contexts/payment.js +4 -7
- package/lib/history/credit/grants-list.d.ts +14 -0
- package/lib/history/credit/grants-list.js +277 -0
- package/lib/history/credit/transactions-list.d.ts +13 -0
- package/lib/history/credit/transactions-list.js +301 -0
- package/lib/history/invoice/list.d.ts +2 -18
- package/lib/history/invoice/list.js +73 -37
- package/lib/history/payment/list.js +30 -16
- package/lib/hooks/keyboard.d.ts +1 -1
- package/lib/hooks/mobile.js +1 -1
- package/lib/hooks/subscription.js +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +41 -2
- package/lib/libs/api.js +1 -1
- package/lib/libs/dayjs.js +1 -1
- package/lib/libs/phone-validator.js +0 -2
- package/lib/libs/theme.js +1 -1
- package/lib/libs/util.d.ts +2 -0
- package/lib/libs/util.js +15 -1
- package/lib/libs/validator.js +1 -1
- package/lib/locales/en.js +21 -3
- package/lib/locales/index.js +1 -1
- package/lib/locales/zh.js +21 -3
- package/lib/payment/amount.d.ts +2 -7
- package/lib/payment/amount.js +2 -6
- package/lib/payment/donation-form.d.ts +2 -10
- package/lib/payment/donation-form.js +33 -38
- package/lib/payment/error.d.ts +2 -8
- package/lib/payment/error.js +11 -13
- package/lib/payment/footer.d.ts +2 -3
- package/lib/payment/footer.js +5 -5
- package/lib/payment/form/addon.js +5 -3
- package/lib/payment/form/address.d.ts +2 -9
- package/lib/payment/form/address.js +5 -8
- package/lib/payment/form/currency.js +3 -3
- package/lib/payment/form/index.d.ts +2 -8
- package/lib/payment/form/index.js +64 -21
- package/lib/payment/form/phone.js +1 -1
- package/lib/payment/form/stripe/form.d.ts +2 -8
- package/lib/payment/form/stripe/form.js +3 -6
- package/lib/payment/header.js +8 -4
- package/lib/payment/index.d.ts +2 -9
- package/lib/payment/index.js +27 -18
- package/lib/payment/product-card.d.ts +2 -11
- package/lib/payment/product-card.js +13 -20
- package/lib/payment/product-donation.js +71 -66
- package/lib/payment/product-item.d.ts +9 -9
- package/lib/payment/product-item.js +168 -29
- package/lib/payment/product-skeleton.js +2 -2
- package/lib/payment/skeleton/donation.js +8 -4
- package/lib/payment/skeleton/overview.js +6 -2
- package/lib/payment/skeleton/payment.js +9 -3
- package/lib/payment/success.d.ts +2 -9
- package/lib/payment/success.js +12 -15
- package/lib/payment/summary.d.ts +4 -17
- package/lib/payment/summary.js +53 -45
- package/lib/theme/index.d.ts +0 -5
- package/lib/theme/index.js +2 -5
- package/lib/theme/typography.d.ts +2 -2
- package/package.json +40 -40
- package/src/checkout/donate.tsx +103 -35
- package/src/checkout/form.tsx +5 -14
- package/src/checkout/table.tsx +3 -3
- package/src/components/blockchain/gas.tsx +5 -3
- package/src/components/blockchain/tx.tsx +19 -11
- package/src/components/confirm.tsx +4 -11
- package/src/components/country-select.tsx +391 -378
- package/src/components/date-range-picker.tsx +310 -0
- package/src/components/input.tsx +61 -46
- package/src/components/label.tsx +58 -0
- package/src/components/link.tsx +9 -7
- package/src/components/livemode.tsx +2 -6
- package/src/components/loading-button.tsx +63 -76
- package/src/components/over-due-invoice-payment.tsx +43 -28
- package/src/components/payment-beneficiaries.tsx +33 -14
- package/src/components/pricing-item.tsx +1 -4
- package/src/components/pricing-table.tsx +8 -8
- package/src/components/resume-subscription.tsx +20 -14
- package/src/components/table.tsx +2 -2
- package/src/components/truncated-text.tsx +0 -6
- package/src/contexts/donate.tsx +6 -7
- package/src/contexts/payment.tsx +7 -3
- package/src/history/credit/grants-list.tsx +276 -0
- package/src/history/credit/transactions-list.tsx +317 -0
- package/src/history/invoice/list.tsx +92 -36
- package/src/history/payment/list.tsx +53 -16
- package/src/hooks/keyboard.ts +1 -1
- package/src/index.ts +9 -0
- package/src/libs/util.ts +14 -0
- package/src/locales/en.tsx +20 -0
- package/src/locales/zh.tsx +19 -0
- package/src/payment/amount.tsx +1 -6
- package/src/payment/donation-form.tsx +47 -29
- package/src/payment/error.tsx +16 -8
- package/src/payment/footer.tsx +11 -3
- package/src/payment/form/addon.tsx +6 -1
- package/src/payment/form/address.tsx +3 -7
- package/src/payment/form/currency.tsx +12 -2
- package/src/payment/form/index.tsx +121 -45
- package/src/payment/form/stripe/form.tsx +1 -5
- package/src/payment/header.tsx +14 -2
- package/src/payment/index.tsx +27 -22
- package/src/payment/product-card.tsx +41 -18
- package/src/payment/product-donation.tsx +85 -47
- package/src/payment/product-item.tsx +198 -28
- package/src/payment/product-skeleton.tsx +3 -2
- package/src/payment/skeleton/donation.tsx +12 -2
- package/src/payment/skeleton/overview.tsx +12 -2
- package/src/payment/skeleton/payment.tsx +16 -3
- package/src/payment/success.tsx +26 -15
- package/src/payment/summary.tsx +87 -44
- package/src/theme/index.tsx +5 -8
- 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(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
7
|
-
|
|
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
|
-
};
|
package/es/contexts/donate.d.ts
CHANGED
|
@@ -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>;
|
package/es/contexts/donate.js
CHANGED
|
@@ -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(
|
|
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}`;
|
package/es/contexts/payment.d.ts
CHANGED
|
@@ -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 };
|
package/es/contexts/payment.js
CHANGED
|
@@ -48,7 +48,13 @@ const syncToSpaceRequest = (userDid, spaceDid) => {
|
|
|
48
48
|
return res;
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
|
-
function PaymentProvider({
|
|
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 {};
|