@blocklet/payment-react 1.18.4 → 1.18.5
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.js +1 -1
- package/es/contexts/donate.js +15 -2
- package/es/libs/util.js +2 -4
- package/lib/checkout/donate.js +1 -1
- package/lib/contexts/donate.js +10 -4
- package/lib/libs/util.js +2 -1
- package/package.json +3 -3
- package/src/checkout/donate.tsx +1 -1
- package/src/contexts/donate.tsx +11 -3
- package/src/libs/util.ts +2 -4
package/es/checkout/donate.js
CHANGED
package/es/contexts/donate.js
CHANGED
|
@@ -8,6 +8,7 @@ import api from "../libs/api.js";
|
|
|
8
8
|
import { formatError, getPaymentKitComponent, openDonationSettings } from "../libs/util.js";
|
|
9
9
|
import { CachedRequest } from "../libs/cached-request.js";
|
|
10
10
|
import ConfirmDialog from "../components/confirm.js";
|
|
11
|
+
import { usePaymentContext } from "./payment.js";
|
|
11
12
|
const DonateContext = createContext({ api });
|
|
12
13
|
const { Provider, Consumer } = DonateContext;
|
|
13
14
|
const fetchDonateSetting = (params, forceRefresh = false) => {
|
|
@@ -38,6 +39,8 @@ function DonateProvider({
|
|
|
38
39
|
}) {
|
|
39
40
|
const { t } = useLocaleContext();
|
|
40
41
|
const [showConfirm, setShowConfirm] = useState(false);
|
|
42
|
+
const { session } = usePaymentContext();
|
|
43
|
+
const isAdmin = ["owner", "admin"].includes(session?.user?.role);
|
|
41
44
|
const {
|
|
42
45
|
data = {
|
|
43
46
|
settings: {},
|
|
@@ -107,9 +110,19 @@ function DonateProvider({
|
|
|
107
110
|
api
|
|
108
111
|
},
|
|
109
112
|
children: data?.active === false ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
110
|
-
enableDonate && /* @__PURE__ */ jsxs(Stack, { spacing: 1, sx: {
|
|
113
|
+
enableDonate && isAdmin && /* @__PURE__ */ jsxs(Stack, { spacing: 1, sx: { alignItems: "center" }, children: [
|
|
111
114
|
/* @__PURE__ */ jsx(Typography, { color: "text.secondary", children: t("payment.checkout.donation.inactive") }),
|
|
112
|
-
/* @__PURE__ */ jsx(
|
|
115
|
+
/* @__PURE__ */ jsx(
|
|
116
|
+
Button,
|
|
117
|
+
{
|
|
118
|
+
size: "small",
|
|
119
|
+
variant: "outlined",
|
|
120
|
+
color: "primary",
|
|
121
|
+
onClick: handleEnable,
|
|
122
|
+
sx: { width: "fit-content" },
|
|
123
|
+
children: t("payment.checkout.donation.enable")
|
|
124
|
+
}
|
|
125
|
+
)
|
|
113
126
|
] }),
|
|
114
127
|
showConfirm && /* @__PURE__ */ jsx(
|
|
115
128
|
ConfirmDialog,
|
package/es/libs/util.js
CHANGED
|
@@ -920,9 +920,7 @@ export function getPaymentKitComponent() {
|
|
|
920
920
|
export function openDonationSettings(openInNewTab = false) {
|
|
921
921
|
const paymentKit = getPaymentKitComponent();
|
|
922
922
|
if (paymentKit) {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
openInNewTab ? "_blank" : "_self"
|
|
926
|
-
);
|
|
923
|
+
const mountPoint = paymentKit.mountPoint.endsWith("/") ? paymentKit.mountPoint.slice(0, -1) : paymentKit.mountPoint;
|
|
924
|
+
window.open(`${window.location.origin}${mountPoint}/integrations/donations`, openInNewTab ? "_blank" : "_self");
|
|
927
925
|
}
|
|
928
926
|
}
|
package/lib/checkout/donate.js
CHANGED
package/lib/contexts/donate.js
CHANGED
|
@@ -17,6 +17,7 @@ var _api = _interopRequireDefault(require("../libs/api"));
|
|
|
17
17
|
var _util = require("../libs/util");
|
|
18
18
|
var _cachedRequest = require("../libs/cached-request");
|
|
19
19
|
var _confirm = _interopRequireDefault(require("../components/confirm"));
|
|
20
|
+
var _payment = require("./payment");
|
|
20
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
22
|
const DonateContext = exports.DonateContext = (0, _react.createContext)({
|
|
22
23
|
api: _api.default
|
|
@@ -52,6 +53,10 @@ function DonateProvider({
|
|
|
52
53
|
t
|
|
53
54
|
} = (0, _context.useLocaleContext)();
|
|
54
55
|
const [showConfirm, setShowConfirm] = (0, _react.useState)(false);
|
|
56
|
+
const {
|
|
57
|
+
session
|
|
58
|
+
} = (0, _payment.usePaymentContext)();
|
|
59
|
+
const isAdmin = ["owner", "admin"].includes(session?.user?.role);
|
|
55
60
|
const {
|
|
56
61
|
data = {
|
|
57
62
|
settings: {},
|
|
@@ -114,12 +119,10 @@ function DonateProvider({
|
|
|
114
119
|
api: _api.default
|
|
115
120
|
},
|
|
116
121
|
children: data?.active === false ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
117
|
-
children: [enableDonate && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
122
|
+
children: [enableDonate && isAdmin && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
118
123
|
spacing: 1,
|
|
119
124
|
sx: {
|
|
120
|
-
|
|
121
|
-
bgcolor: "background.neutral",
|
|
122
|
-
borderRadius: 1
|
|
125
|
+
alignItems: "center"
|
|
123
126
|
},
|
|
124
127
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
125
128
|
color: "text.secondary",
|
|
@@ -129,6 +132,9 @@ function DonateProvider({
|
|
|
129
132
|
variant: "outlined",
|
|
130
133
|
color: "primary",
|
|
131
134
|
onClick: handleEnable,
|
|
135
|
+
sx: {
|
|
136
|
+
width: "fit-content"
|
|
137
|
+
},
|
|
132
138
|
children: t("payment.checkout.donation.enable")
|
|
133
139
|
})]
|
|
134
140
|
}), showConfirm && /* @__PURE__ */(0, _jsxRuntime.jsx)(_confirm.default, {
|
package/lib/libs/util.js
CHANGED
|
@@ -1106,6 +1106,7 @@ function getPaymentKitComponent() {
|
|
|
1106
1106
|
function openDonationSettings(openInNewTab = false) {
|
|
1107
1107
|
const paymentKit = getPaymentKitComponent();
|
|
1108
1108
|
if (paymentKit) {
|
|
1109
|
-
|
|
1109
|
+
const mountPoint = paymentKit.mountPoint.endsWith("/") ? paymentKit.mountPoint.slice(0, -1) : paymentKit.mountPoint;
|
|
1110
|
+
window.open(`${window.location.origin}${mountPoint}/integrations/donations`, openInNewTab ? "_blank" : "_self");
|
|
1110
1111
|
}
|
|
1111
1112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.5",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"@babel/core": "^7.25.2",
|
|
93
93
|
"@babel/preset-env": "^7.25.2",
|
|
94
94
|
"@babel/preset-react": "^7.24.7",
|
|
95
|
-
"@blocklet/payment-types": "1.18.
|
|
95
|
+
"@blocklet/payment-types": "1.18.5",
|
|
96
96
|
"@storybook/addon-essentials": "^7.6.20",
|
|
97
97
|
"@storybook/addon-interactions": "^7.6.20",
|
|
98
98
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"vite-plugin-babel": "^1.2.0",
|
|
124
124
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
125
125
|
},
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "83cca0f1ac5814964c8bedd04f34a3a2a986f554"
|
|
127
127
|
}
|
package/src/checkout/donate.tsx
CHANGED
package/src/contexts/donate.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import api from '../libs/api';
|
|
|
10
10
|
import { formatError, getPaymentKitComponent, openDonationSettings } from '../libs/util';
|
|
11
11
|
import { CachedRequest } from '../libs/cached-request';
|
|
12
12
|
import ConfirmDialog from '../components/confirm';
|
|
13
|
+
import { usePaymentContext } from './payment';
|
|
13
14
|
|
|
14
15
|
export interface DonateConfigSettings {
|
|
15
16
|
amount?: {
|
|
@@ -83,6 +84,8 @@ function DonateProvider({
|
|
|
83
84
|
}: DonateContextProps) {
|
|
84
85
|
const { t } = useLocaleContext();
|
|
85
86
|
const [showConfirm, setShowConfirm] = useState(false);
|
|
87
|
+
const { session } = usePaymentContext();
|
|
88
|
+
const isAdmin = ['owner', 'admin'].includes(session?.user?.role);
|
|
86
89
|
const {
|
|
87
90
|
data = {
|
|
88
91
|
settings: {},
|
|
@@ -157,10 +160,15 @@ function DonateProvider({
|
|
|
157
160
|
}}>
|
|
158
161
|
{(data as TSetting)?.active === false ? (
|
|
159
162
|
<>
|
|
160
|
-
{enableDonate && (
|
|
161
|
-
<Stack spacing={1} sx={{
|
|
163
|
+
{enableDonate && isAdmin && (
|
|
164
|
+
<Stack spacing={1} sx={{ alignItems: 'center' }}>
|
|
162
165
|
<Typography color="text.secondary">{t('payment.checkout.donation.inactive')}</Typography>
|
|
163
|
-
<Button
|
|
166
|
+
<Button
|
|
167
|
+
size="small"
|
|
168
|
+
variant="outlined"
|
|
169
|
+
color="primary"
|
|
170
|
+
onClick={handleEnable}
|
|
171
|
+
sx={{ width: 'fit-content' }}>
|
|
164
172
|
{t('payment.checkout.donation.enable')}
|
|
165
173
|
</Button>
|
|
166
174
|
</Stack>
|
package/src/libs/util.ts
CHANGED
|
@@ -1180,9 +1180,7 @@ export function getPaymentKitComponent() {
|
|
|
1180
1180
|
export function openDonationSettings(openInNewTab: boolean = false) {
|
|
1181
1181
|
const paymentKit = getPaymentKitComponent();
|
|
1182
1182
|
if (paymentKit) {
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
openInNewTab ? '_blank' : '_self'
|
|
1186
|
-
);
|
|
1183
|
+
const mountPoint = paymentKit.mountPoint.endsWith('/') ? paymentKit.mountPoint.slice(0, -1) : paymentKit.mountPoint;
|
|
1184
|
+
window.open(`${window.location.origin}${mountPoint}/integrations/donations`, openInNewTab ? '_blank' : '_self');
|
|
1187
1185
|
}
|
|
1188
1186
|
}
|