@blocklet/payment-react 1.18.4 → 1.18.6

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.
@@ -274,7 +274,7 @@ function useDonation(settings, livemode, mode = "default") {
274
274
  state,
275
275
  setState,
276
276
  donateSettings,
277
- supportUpdateSettings: !!donateContext
277
+ supportUpdateSettings: !!donateContext.settings
278
278
  };
279
279
  }
280
280
  function CheckoutDonateInner({
@@ -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: { p: 2, bgcolor: "background.neutral", borderRadius: 1 }, children: [
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(Button, { size: "small", variant: "outlined", color: "primary", onClick: handleEnable, children: t("payment.checkout.donation.enable") })
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
- window.open(
924
- `${window.location.origin}${paymentKit.mountPoint === "/" ? "" : paymentKit.mountPoint}/integrations/donations`,
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
  }
@@ -238,7 +238,7 @@ export default function PaymentForm({
238
238
  action: checkoutSession.mode,
239
239
  prefix: joinURL(getPrefix(), "/api/did"),
240
240
  saveConnect: false,
241
- extraParams: { checkoutSessionId: checkoutSession.id },
241
+ extraParams: { checkoutSessionId: checkoutSession.id, sessionUserDid: session?.user?.did },
242
242
  onSuccess: async () => {
243
243
  connect.close();
244
244
  await handleConnected();
@@ -337,7 +337,7 @@ function useDonation(settings, livemode, mode = "default") {
337
337
  state,
338
338
  setState,
339
339
  donateSettings,
340
- supportUpdateSettings: !!donateContext
340
+ supportUpdateSettings: !!donateContext.settings
341
341
  };
342
342
  }
343
343
  function CheckoutDonateInner({
@@ -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
- p: 2,
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
- window.open(`${window.location.origin}${paymentKit.mountPoint === "/" ? "" : paymentKit.mountPoint}/integrations/donations`, openInNewTab ? "_blank" : "_self");
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
  }
@@ -276,7 +276,8 @@ function PaymentForm({
276
276
  prefix: (0, _ufo.joinURL)((0, _util.getPrefix)(), "/api/did"),
277
277
  saveConnect: false,
278
278
  extraParams: {
279
- checkoutSessionId: checkoutSession.id
279
+ checkoutSessionId: checkoutSession.id,
280
+ sessionUserDid: session?.user?.did
280
281
  },
281
282
  onSuccess: async () => {
282
283
  connect.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.18.4",
3
+ "version": "1.18.6",
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.4",
95
+ "@blocklet/payment-types": "1.18.6",
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": "003d3b762bc9e3e224e4814dea95ff02d014868d"
126
+ "gitHead": "784ba57910d780a44d0792ef503b666ee8f8d9c3"
127
127
  }
@@ -383,7 +383,7 @@ function useDonation(
383
383
  state,
384
384
  setState,
385
385
  donateSettings,
386
- supportUpdateSettings: !!donateContext,
386
+ supportUpdateSettings: !!donateContext.settings,
387
387
  };
388
388
  }
389
389
 
@@ -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={{ p: 2, bgcolor: 'background.neutral', borderRadius: 1 }}>
163
+ {enableDonate && isAdmin && (
164
+ <Stack spacing={1} sx={{ alignItems: 'center' }}>
162
165
  <Typography color="text.secondary">{t('payment.checkout.donation.inactive')}</Typography>
163
- <Button size="small" variant="outlined" color="primary" onClick={handleEnable}>
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
- window.open(
1184
- `${window.location.origin}${paymentKit.mountPoint === '/' ? '' : paymentKit.mountPoint}/integrations/donations`,
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
  }
@@ -316,7 +316,7 @@ export default function PaymentForm({
316
316
  action: checkoutSession.mode,
317
317
  prefix: joinURL(getPrefix(), '/api/did'),
318
318
  saveConnect: false,
319
- extraParams: { checkoutSessionId: checkoutSession.id },
319
+ extraParams: { checkoutSessionId: checkoutSession.id, sessionUserDid: session?.user?.did },
320
320
  onSuccess: async () => {
321
321
  connect.close();
322
322
  await handleConnected();