@blocklet/payment-react 1.18.0 → 1.18.2

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 (54) hide show
  1. package/es/checkout/donate.js +55 -10
  2. package/es/checkout/form.d.ts +2 -1
  3. package/es/checkout/form.js +32 -45
  4. package/es/components/payment-beneficiaries.d.ts +24 -0
  5. package/es/components/payment-beneficiaries.js +70 -0
  6. package/es/index.d.ts +2 -1
  7. package/es/index.js +3 -1
  8. package/es/locales/en.js +13 -1
  9. package/es/locales/zh.js +13 -1
  10. package/es/payment/donation-form.d.ts +24 -0
  11. package/es/payment/donation-form.js +604 -0
  12. package/es/payment/error.d.ts +1 -1
  13. package/es/payment/error.js +11 -1
  14. package/es/payment/form/index.d.ts +9 -3
  15. package/es/payment/form/index.js +60 -12
  16. package/es/payment/product-donation.js +101 -56
  17. package/es/payment/skeleton/donation.d.ts +1 -0
  18. package/es/payment/skeleton/donation.js +30 -0
  19. package/es/theme/index.js +13 -0
  20. package/es/types/index.d.ts +2 -0
  21. package/lib/checkout/donate.js +85 -10
  22. package/lib/checkout/form.d.ts +2 -1
  23. package/lib/checkout/form.js +39 -49
  24. package/lib/components/payment-beneficiaries.d.ts +24 -0
  25. package/lib/components/payment-beneficiaries.js +113 -0
  26. package/lib/index.d.ts +2 -1
  27. package/lib/index.js +8 -0
  28. package/lib/locales/en.js +13 -1
  29. package/lib/locales/zh.js +13 -1
  30. package/lib/payment/donation-form.d.ts +24 -0
  31. package/lib/payment/donation-form.js +645 -0
  32. package/lib/payment/error.d.ts +1 -1
  33. package/lib/payment/error.js +2 -2
  34. package/lib/payment/form/index.d.ts +9 -3
  35. package/lib/payment/form/index.js +60 -8
  36. package/lib/payment/product-donation.js +143 -72
  37. package/lib/payment/skeleton/donation.d.ts +1 -0
  38. package/lib/payment/skeleton/donation.js +66 -0
  39. package/lib/theme/index.js +13 -0
  40. package/lib/types/index.d.ts +2 -0
  41. package/package.json +3 -3
  42. package/src/checkout/donate.tsx +64 -11
  43. package/src/checkout/form.tsx +17 -31
  44. package/src/components/payment-beneficiaries.tsx +97 -0
  45. package/src/index.ts +2 -0
  46. package/src/locales/en.tsx +12 -0
  47. package/src/locales/zh.tsx +12 -0
  48. package/src/payment/donation-form.tsx +647 -0
  49. package/src/payment/error.tsx +13 -4
  50. package/src/payment/form/index.tsx +66 -11
  51. package/src/payment/product-donation.tsx +94 -39
  52. package/src/payment/skeleton/donation.tsx +35 -0
  53. package/src/theme/index.tsx +13 -0
  54. package/src/types/index.ts +2 -0
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  module.exports = PaymentForm;
7
+ exports.waitForCheckoutComplete = exports.hasDidWallet = void 0;
7
8
  var _jsxRuntime = require("react/jsx-runtime");
8
9
  require("react-international-phone/style.css");
9
10
  var _context = require("@arcblock/ux/lib/Locale/context");
10
11
  var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
11
- var _lab = require("@mui/lab");
12
12
  var _material = require("@mui/material");
13
13
  var _ahooks = require("ahooks");
14
14
  var _pWaitFor = _interopRequireDefault(require("p-wait-for"));
@@ -51,11 +51,15 @@ const waitForCheckoutComplete = async sessionId => {
51
51
  });
52
52
  return result;
53
53
  };
54
+ exports.waitForCheckoutComplete = waitForCheckoutComplete;
54
55
  const hasDidWallet = user => {
55
56
  const connected = user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
56
57
  return connected.some(x => x.provider === "wallet");
57
58
  };
58
- PaymentForm.defaultProps = {};
59
+ exports.hasDidWallet = hasDidWallet;
60
+ PaymentForm.defaultProps = {
61
+ onlyShowBtn: false
62
+ };
59
63
  function PaymentForm({
60
64
  checkoutSession,
61
65
  paymentMethods,
@@ -66,7 +70,8 @@ function PaymentForm({
66
70
  onError,
67
71
  // mode,
68
72
  action,
69
- currencyId
73
+ currencyId,
74
+ onlyShowBtn
70
75
  }) {
71
76
  const {
72
77
  t
@@ -379,6 +384,43 @@ function PaymentForm({
379
384
  stripePaying: false
380
385
  });
381
386
  };
387
+ if (onlyShowBtn) {
388
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
389
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
390
+ className: "cko-payment-submit-btn",
391
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Button, {
392
+ variant: "contained",
393
+ color: "primary",
394
+ size: "large",
395
+ className: "cko-submit-button",
396
+ onClick: () => {
397
+ if (state.submitting || state.paying) {
398
+ return;
399
+ }
400
+ onAction();
401
+ },
402
+ fullWidth: true,
403
+ disabled: state.stripePaying || !quantityInventoryStatus || !payable,
404
+ children: [(state.submitting || state.paying) && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {
405
+ size: 16,
406
+ sx: {
407
+ mr: 0.5,
408
+ color: "var(--foregrounds-fg-on-color, #fff)"
409
+ }
410
+ }), state.submitting || state.paying ? t("payment.checkout.processing") : buttonText]
411
+ })
412
+ }), state.customerLimited && /* @__PURE__ */(0, _jsxRuntime.jsx)(_confirm.default, {
413
+ onConfirm: () => window.open((0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`), "_self"),
414
+ onCancel: () => setState({
415
+ customerLimited: false
416
+ }),
417
+ confirm: t("payment.customer.pastDue.alert.confirm"),
418
+ title: t("payment.customer.pastDue.alert.title"),
419
+ message: t("payment.customer.pastDue.alert.description"),
420
+ color: "primary"
421
+ })]
422
+ });
423
+ }
382
424
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
383
425
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Fade, {
384
426
  in: true,
@@ -497,16 +539,26 @@ function PaymentForm({
497
539
  className: "cko-payment-submit",
498
540
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
499
541
  className: "cko-payment-submit-btn",
500
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_lab.LoadingButton, {
542
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Button, {
501
543
  variant: "contained",
502
544
  color: "primary",
503
545
  size: "large",
504
546
  className: "cko-submit-button",
505
- onClick: onAction,
547
+ onClick: () => {
548
+ if (state.submitting || state.paying) {
549
+ return;
550
+ }
551
+ onAction();
552
+ },
506
553
  fullWidth: true,
507
- disabled: state.submitting || state.paying || state.stripePaying || !quantityInventoryStatus || !payable,
508
- loading: state.submitting || state.paying,
509
- children: state.submitting || state.paying ? t("payment.checkout.processing") : buttonText
554
+ disabled: state.stripePaying || !quantityInventoryStatus || !payable,
555
+ children: [(state.submitting || state.paying) && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {
556
+ size: 16,
557
+ sx: {
558
+ mr: 0.5,
559
+ color: "var(--foregrounds-fg-on-color, #fff)"
560
+ }
561
+ }), state.submitting || state.paying ? t("payment.checkout.processing") : buttonText]
510
562
  })
511
563
  }), ["subscription", "setup"].includes(checkoutSession.mode) && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
512
564
  sx: {
@@ -9,11 +9,9 @@ var _context = require("@arcblock/ux/lib/Locale/context");
9
9
  var _material = require("@mui/material");
10
10
  var _ahooks = require("ahooks");
11
11
  var _react = require("react");
12
- var _switchButton = _interopRequireDefault(require("../components/switch-button"));
13
12
  var _util = require("../libs/util");
14
13
  var _payment = require("../contexts/payment");
15
14
  var _scroll = require("../hooks/scroll");
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
  function ProductDonation({
18
16
  item,
19
17
  settings,
@@ -28,13 +26,17 @@ function ProductDonation({
28
26
  setPayable
29
27
  } = (0, _payment.usePaymentContext)();
30
28
  (0, _scroll.usePreventWheel)();
31
- const preset = settings.amount.preset || settings.amount.presets?.[0] || "0";
29
+ const presets = settings?.amount?.presets || [];
30
+ const preset = settings?.amount?.preset || presets?.[0] || "0";
31
+ const supportPreset = presets.length > 0;
32
+ const supportCustom = !!settings?.amount?.custom;
32
33
  const [state, setState] = (0, _ahooks.useSetState)({
33
34
  selected: preset,
34
35
  input: "",
35
- custom: settings.amount.presets?.length === 0,
36
+ custom: !supportPreset,
36
37
  error: ""
37
38
  });
39
+ const customInputRef = (0, _react.useRef)(null);
38
40
  (0, _react.useEffect)(() => {
39
41
  if (settings.amount.preset) {
40
42
  setState({
@@ -56,7 +58,15 @@ function ProductDonation({
56
58
  });
57
59
  }
58
60
  }, [settings.amount.preset, settings.amount.presets]);
61
+ (0, _react.useEffect)(() => {
62
+ if (state.custom) {
63
+ setTimeout(() => {
64
+ customInputRef.current?.focus();
65
+ }, 0);
66
+ }
67
+ }, [state.custom]);
59
68
  const handleSelect = amount => {
69
+ setPayable(true);
60
70
  setState({
61
71
  selected: amount,
62
72
  custom: false,
@@ -103,16 +113,13 @@ function ProductDonation({
103
113
  amount: value
104
114
  });
105
115
  };
106
- const handleToggle = event => {
107
- if (event.target.checked) {
108
- setState({
109
- custom: true,
110
- input: state.selected,
111
- error: ""
112
- });
113
- } else {
114
- setPayable(true);
115
- handleSelect(preset);
116
+ const handleCustomSelect = () => {
117
+ setState({
118
+ custom: true,
119
+ error: ""
120
+ });
121
+ if (!state.input) {
122
+ setPayable(false);
116
123
  }
117
124
  };
118
125
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
@@ -120,76 +127,140 @@ function ProductDonation({
120
127
  flexDirection: "column",
121
128
  alignItems: "flex-start",
122
129
  gap: 1.5,
123
- children: [settings.amount.custom && preset !== "0" && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.FormControlLabel, {
124
- control: /* @__PURE__ */(0, _jsxRuntime.jsx)(_switchButton.default, {
125
- checked: state.custom,
126
- sx: {
127
- marginRight: 0.4
128
- },
129
- onChange: handleToggle
130
- }),
131
- label: state.custom ? t("payment.checkout.donation.select") : t("payment.checkout.donation.custom"),
132
- sx: {
133
- marginRight: 2,
134
- marginLeft: 0.5,
135
- color: "text.lighter"
136
- }
137
- }), !state.custom && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
138
- display: "flex",
139
- flexWrap: "wrap",
140
- alignItems: "center",
141
- gap: 1.5,
142
- children: settings.amount.presets && settings.amount.presets.length > 0 && settings.amount.presets.map(amount => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
143
- variant: "outlined",
144
- sx: {
145
- minWidth: 115,
146
- textAlign: "center",
147
- ...(state.selected === amount && !state.custom ? {
148
- borderColor: "primary.main"
149
- } : {})
150
- },
151
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CardActionArea, {
152
- onClick: () => handleSelect(amount),
153
- children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
154
- direction: "row",
155
- sx: {
156
- py: 1,
157
- px: 0.5
130
+ children: [supportPreset && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Grid, {
131
+ container: true,
132
+ spacing: 2,
133
+ children: [settings.amount.presets && settings.amount.presets.length > 0 && settings.amount.presets.map(amount => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Grid, {
134
+ item: true,
135
+ xs: 6,
136
+ sm: 3,
137
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
138
+ variant: "outlined",
139
+ sx: {
140
+ minWidth: 115,
141
+ textAlign: "center",
142
+ transition: "all 0.3s",
143
+ cursor: "pointer",
144
+ "&:hover": {
145
+ transform: "translateY(-4px)",
146
+ boxShadow: 3
158
147
  },
159
- spacing: 0.5,
160
- alignItems: "flex-end",
161
- justifyContent: "center",
162
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
163
- component: "strong",
164
- lineHeight: 1,
165
- variant: "h3",
148
+ height: "42px",
149
+ ...(state.selected === amount && !state.custom ? {
150
+ borderColor: "primary.main",
151
+ borderWidth: 1
152
+ } : {})
153
+ },
154
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CardActionArea, {
155
+ onClick: () => handleSelect(amount),
156
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
157
+ direction: "row",
166
158
  sx: {
167
- fontVariantNumeric: "tabular-nums",
168
- fontWeight: 400
159
+ py: 1.5,
160
+ px: 1.5
169
161
  },
170
- children: amount
171
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
172
- component: "small",
173
- lineHeight: 1,
174
- fontSize: 12,
175
- children: "ABT"
176
- }), " "]
162
+ spacing: 0.5,
163
+ alignItems: "center",
164
+ justifyContent: "center",
165
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
166
+ src: currency?.logo,
167
+ sx: {
168
+ width: 16,
169
+ height: 16,
170
+ mr: 0.5
171
+ },
172
+ alt: currency?.symbol
173
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
174
+ component: "strong",
175
+ lineHeight: 1,
176
+ variant: "h3",
177
+ sx: {
178
+ fontVariantNumeric: "tabular-nums",
179
+ fontWeight: 400
180
+ },
181
+ children: amount
182
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
183
+ lineHeight: 1,
184
+ fontSize: 14,
185
+ color: "text.secondary",
186
+ children: currency?.symbol
187
+ })]
188
+ })
177
189
  })
178
- })
179
- }, amount))
190
+ }, amount)
191
+ }, amount)), supportCustom && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Grid, {
192
+ item: true,
193
+ xs: 6,
194
+ sm: 3,
195
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
196
+ variant: "outlined",
197
+ sx: {
198
+ textAlign: "center",
199
+ transition: "all 0.3s",
200
+ cursor: "pointer",
201
+ "&:hover": {
202
+ transform: "translateY(-4px)",
203
+ boxShadow: 3
204
+ },
205
+ height: "42px",
206
+ ...(state.custom ? {
207
+ borderColor: "primary.main",
208
+ borderWidth: 1
209
+ } : {})
210
+ },
211
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CardActionArea, {
212
+ onClick: () => handleCustomSelect(),
213
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
214
+ direction: "row",
215
+ sx: {
216
+ py: 1.5,
217
+ px: 1.5
218
+ },
219
+ spacing: 0.5,
220
+ alignItems: "center",
221
+ justifyContent: "center",
222
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
223
+ variant: "h3",
224
+ lineHeight: 1,
225
+ sx: {
226
+ fontWeight: 400
227
+ },
228
+ children: t("common.custom")
229
+ })
230
+ })
231
+ })
232
+ }, "custom")
233
+ }, "custom")]
180
234
  }), state.custom && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TextField, {
181
- label: preset !== "0" ? null : t("payment.checkout.donation.custom"),
182
235
  type: "number",
183
236
  value: state.input,
184
237
  onChange: handleInput,
185
- inputProps: {
186
- min: settings.amount.minimum,
187
- max: settings.amount.maximum
188
- },
189
238
  margin: "none",
190
239
  fullWidth: true,
191
240
  error: !!state.error,
192
241
  helperText: state.error,
242
+ inputRef: customInputRef,
243
+ InputProps: {
244
+ endAdornment: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
245
+ direction: "row",
246
+ spacing: 0.5,
247
+ alignItems: "center",
248
+ sx: {
249
+ ml: 1
250
+ },
251
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
252
+ src: currency?.logo,
253
+ sx: {
254
+ width: 16,
255
+ height: 16
256
+ },
257
+ alt: currency?.symbol
258
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
259
+ children: currency?.symbol
260
+ })]
261
+ }),
262
+ autoComplete: "off"
263
+ },
193
264
  sx: {
194
265
  mt: preset !== "0" ? 0 : 1
195
266
  }
@@ -0,0 +1 @@
1
+ export default function DonationSkeleton(): import("react").JSX.Element;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = DonationSkeleton;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _material = require("@mui/material");
9
+ function DonationSkeleton() {
10
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Fade, {
11
+ in: true,
12
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
13
+ direction: "column",
14
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
15
+ variant: "text",
16
+ sx: {
17
+ fontSize: "2rem",
18
+ width: "40%"
19
+ }
20
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
21
+ sx: {
22
+ mt: 2
23
+ },
24
+ variant: "rounded",
25
+ height: 80
26
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {
27
+ sx: {
28
+ mt: {
29
+ xs: "16px",
30
+ md: "16px"
31
+ },
32
+ mb: {
33
+ xs: "16px",
34
+ md: "16px"
35
+ }
36
+ }
37
+ }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
38
+ direction: "row",
39
+ justifyContent: "space-between",
40
+ spacing: 2,
41
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
42
+ variant: "text",
43
+ sx: {
44
+ fontSize: "1.5rem",
45
+ width: "40%"
46
+ }
47
+ }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
48
+ display: "flex",
49
+ alignItems: "center",
50
+ gap: 2,
51
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
52
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
53
+ height: 60,
54
+ width: 80
55
+ })
56
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
57
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
58
+ height: 60,
59
+ width: 120
60
+ })
61
+ })]
62
+ })]
63
+ })]
64
+ })
65
+ });
66
+ }
@@ -52,6 +52,9 @@ function PaymentThemeProvider({
52
52
  fontSize: "14px",
53
53
  minHeight: "1.65em",
54
54
  lineHeight: "1.65em"
55
+ },
56
+ "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
57
+ borderWidth: "1px"
55
58
  }
56
59
  }
57
60
  }
@@ -126,6 +129,9 @@ function PaymentThemeProvider({
126
129
  },
127
130
  MuiPopover: {
128
131
  styleOverrides: {
132
+ root: {
133
+ zIndex: 1200
134
+ },
129
135
  paper: ({
130
136
  theme
131
137
  }) => ({
@@ -245,6 +251,13 @@ function PaymentThemeProvider({
245
251
  }
246
252
  }
247
253
  }
254
+ },
255
+ MuiDialog: {
256
+ styleOverrides: {
257
+ root: {
258
+ zIndex: 1200
259
+ }
260
+ }
248
261
  }
249
262
  }
250
263
  };
@@ -36,6 +36,8 @@ export type CheckoutProps = Partial<CheckoutCallbacks> & {
36
36
  action?: string;
37
37
  mode?: LiteralUnion<'standalone' | 'inline' | 'popup' | 'inline-minimal' | 'popup-minimal', string>;
38
38
  theme?: 'default' | 'inherit' | PaymentThemeOptions;
39
+ formType?: 'donation' | 'payment';
40
+ formRender?: Record<string, any>;
39
41
  };
40
42
  export type CheckoutCallbacks = {
41
43
  onPaid: (res: CheckoutContext) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.18.0",
3
+ "version": "1.18.2",
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.0",
95
+ "@blocklet/payment-types": "1.18.2",
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": "052c301e1f565558766c9346ba355f2fd072108e"
126
+ "gitHead": "577491d13f4b2e53e9a71be3b90298b5685f5e8a"
127
127
  }
@@ -39,6 +39,8 @@ import type { CheckoutProps, PaymentThemeOptions } from '../types';
39
39
  import CheckoutForm from './form';
40
40
  import { PaymentThemeProvider } from '../theme';
41
41
  import { usePaymentContext } from '../contexts/payment';
42
+ import Livemode from '../components/livemode';
43
+ import { useMobile } from '../hooks/mobile';
42
44
 
43
45
  export type DonateHistory = {
44
46
  supporters: TCheckoutSessionExpanded[];
@@ -329,9 +331,12 @@ function CheckoutDonateInner({
329
331
  }: DonateProps) {
330
332
  // eslint-disable-line
331
333
  const { state, setState, donation, supporters } = useDonation(settings, livemode, mode);
332
-
334
+ const customers = uniqBy((supporters?.data as DonateHistory)?.supporters || [], 'customer_did');
335
+ const { t } = useLocaleContext();
333
336
  const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
334
337
  const [popoverOpen, setPopoverOpen] = useState<boolean>(false);
338
+ const { isMobile } = useMobile();
339
+ const { connect } = usePaymentContext();
335
340
 
336
341
  const handlePaid = (...args: any[]) => {
337
342
  if (onPaid) {
@@ -488,29 +493,59 @@ function CheckoutDonateInner({
488
493
  }
489
494
  return defaultRender;
490
495
  };
496
+
491
497
  return (
492
498
  <>
493
499
  {renderInnerView()}
494
500
  {donation.data && (
495
501
  <Dialog
496
502
  open={state.open}
497
- title={settings.title}
503
+ title={
504
+ <Box display="flex" alignItems="center" gap={0.5}>
505
+ <Typography variant="h3" sx={{ maxWidth: 320, textOverflow: 'ellipsis', overflow: 'hidden' }}>
506
+ {settings.title}
507
+ </Typography>
508
+ {!donation.data.livemode && <Livemode sx={{ width: 'fit-content' }} />}
509
+ </Box>
510
+ }
498
511
  maxWidth="md"
499
- showCloseButton
512
+ toolbar={
513
+ isMobile ? null : (
514
+ <Box display="flex" alignItems="center" gap={1} sx={{ color: 'text.secondary' }}>
515
+ <AvatarGroup total={customers?.length} max={5}>
516
+ {customers.map((x: any) => (
517
+ <Avatar
518
+ key={x.id}
519
+ title={x.customer?.name}
520
+ src={getCustomerAvatar(
521
+ x.customer?.did,
522
+ x?.updated_at ? new Date(x.updated_at).toISOString() : '',
523
+ 18
524
+ )}
525
+ variant="circular"
526
+ sx={{ width: 18, height: 18 }}
527
+ />
528
+ ))}
529
+ </AvatarGroup>
530
+ {customers?.length > 0 && t('payment.checkout.donation.gaveTips', { count: customers?.length })}
531
+ </Box>
532
+ )
533
+ }
534
+ showCloseButton={false}
500
535
  disableEscapeKeyDown
501
536
  sx={{
502
537
  '.MuiDialogContent-root': {
503
- padding: {
504
- xs: 0,
505
- md: '0 16px 0',
506
- },
538
+ padding: '16px 24px',
507
539
  borderTop: '1px solid var(--stroke-border-base, #EFF1F5)',
508
- width: {
509
- xs: '100%',
510
- md: 900,
511
- },
540
+ width: '100%',
541
+ },
542
+ '.ux-dialog_header': {
543
+ gap: 5,
512
544
  },
513
545
  }}
546
+ PaperProps={{
547
+ style: { minHeight: 'auto', width: 680 },
548
+ }}
514
549
  onClose={(e: any, reason: string) => setState({ open: reason === 'backdropClick' })}>
515
550
  <Box sx={{ height: '100%', width: '100%' }}>
516
551
  <CheckoutForm
@@ -520,9 +555,27 @@ function CheckoutDonateInner({
520
555
  action={settings.appearance?.button?.text}
521
556
  mode="inline"
522
557
  theme={theme}
558
+ formType="donation"
523
559
  extraParams={{
524
560
  livemode,
525
561
  }}
562
+ formRender={{
563
+ cancel: (
564
+ <Button
565
+ variant="outlined"
566
+ size="large"
567
+ onClick={() => {
568
+ connect.close();
569
+ setState({ open: false });
570
+ }}>
571
+ {t('common.cancel')}
572
+ </Button>
573
+ ),
574
+ onCancel: () => {
575
+ connect.close();
576
+ setState({ open: false });
577
+ },
578
+ }}
526
579
  />
527
580
  </Box>
528
581
  </Dialog>