@drawbridge/components 0.1.48 → 0.1.50

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 (125) hide show
  1. package/dist/bridge/fields.js +0 -278
  2. package/dist/bridge/fields.mjs +1 -276
  3. package/dist/bridge/form-subdomain-shop-modal.js +274 -234
  4. package/dist/bridge/form-subdomain-shop-modal.mjs +275 -233
  5. package/dist/bridge/form-subdomain.js +0 -7
  6. package/dist/bridge/form-subdomain.mjs +2 -9
  7. package/dist/bridge/lib/age-gate.js +0 -12
  8. package/dist/bridge/lib/age-gate.mjs +0 -11
  9. package/dist/bridge/lib/checkout-kit.js +32 -2
  10. package/dist/bridge/lib/checkout-kit.mjs +32 -2
  11. package/dist/bridge/lib/entry.js +3 -3
  12. package/dist/bridge/lib/entry.mjs +2 -2
  13. package/dist/bridge/product-tile.js +6 -9
  14. package/dist/bridge/product-tile.mjs +6 -9
  15. package/dist/bridge/template-layout.js +123 -238
  16. package/dist/bridge/template-layout.mjs +124 -239
  17. package/dist/bridge/template-modal.js +73 -28
  18. package/dist/bridge/template-modal.mjs +74 -29
  19. package/dist/dashboard/buttons-subscription.js +1 -1
  20. package/dist/dashboard/buttons-subscription.mjs +1 -1
  21. package/dist/dashboard/campaign-form.js +2 -7
  22. package/dist/dashboard/campaign-form.mjs +2 -7
  23. package/dist/dashboard/card-order.js +4 -22
  24. package/dist/dashboard/card-order.mjs +4 -22
  25. package/dist/dashboard/document-blocks.js +17 -4
  26. package/dist/dashboard/document-blocks.mjs +17 -4
  27. package/dist/dashboard/form-admin-provider.js +17 -71
  28. package/dist/dashboard/form-admin-provider.mjs +17 -71
  29. package/dist/dashboard/form-file-upload.js +2 -3
  30. package/dist/dashboard/form-file-upload.mjs +3 -4
  31. package/dist/dashboard/form-organization-campaign-advertisements.js +6 -47
  32. package/dist/dashboard/form-organization-campaign-advertisements.mjs +6 -47
  33. package/dist/dashboard/form-organization-campaign-agreement.js +121 -83
  34. package/dist/dashboard/form-organization-campaign-agreement.mjs +121 -83
  35. package/dist/dashboard/form-organization-campaign.js +0 -82
  36. package/dist/dashboard/form-organization-campaign.mjs +0 -81
  37. package/dist/dashboard/form-organization-connection.js +6 -48
  38. package/dist/dashboard/form-organization-connection.mjs +7 -48
  39. package/dist/dashboard/form-organization-workflow.js +1 -72
  40. package/dist/dashboard/form-organization-workflow.mjs +1 -69
  41. package/dist/dashboard/form-otc.js +5 -4
  42. package/dist/dashboard/form-otc.mjs +5 -4
  43. package/dist/dashboard/form-stripe.js +5 -12
  44. package/dist/dashboard/form-stripe.mjs +5 -12
  45. package/dist/dashboard/input-fields.js +158 -11
  46. package/dist/dashboard/input-fields.mjs +158 -11
  47. package/dist/dashboard/input-file.js +4 -21
  48. package/dist/dashboard/input-file.mjs +4 -21
  49. package/dist/dashboard/lib/connection-controls.js +2 -5
  50. package/dist/dashboard/lib/connection-controls.mjs +1 -3
  51. package/dist/dashboard/lib/form-page.js +1 -1
  52. package/dist/dashboard/lib/form-page.mjs +1 -1
  53. package/dist/dashboard/lib/uppy.js +1 -10
  54. package/dist/dashboard/lib/uppy.mjs +2 -11
  55. package/dist/dashboard/order-sections.js +6 -456
  56. package/dist/dashboard/order-sections.mjs +7 -453
  57. package/dist/dashboard/provider-ui.js +7 -9
  58. package/dist/dashboard/provider-ui.mjs +7 -9
  59. package/dist/dashboard/template-ui.js +12 -4
  60. package/dist/dashboard/template-ui.mjs +12 -4
  61. package/dist/input-checkbox.js +10 -28
  62. package/dist/input-checkbox.mjs +10 -28
  63. package/dist/product.js +24 -96
  64. package/dist/product.mjs +25 -97
  65. package/dist/shared/lib/helpers.js +6 -54
  66. package/dist/shared/lib/helpers.mjs +8 -53
  67. package/package.json +4 -74
  68. package/types/bridge/fields.d.ts +2 -14
  69. package/types/bridge/form-subdomain-shop-modal.d.ts +3 -27
  70. package/types/bridge/lib/age-gate.d.ts +0 -5
  71. package/types/bridge/lib/checkout-kit.d.ts +10 -2
  72. package/types/bridge/lib/entry.d.ts +3 -3
  73. package/types/dashboard/card-order.d.ts +0 -6
  74. package/types/dashboard/document-blocks.d.ts +3 -2
  75. package/types/dashboard/form-admin-provider.d.ts +2 -9
  76. package/types/dashboard/form-file-upload.d.ts +1 -2
  77. package/types/dashboard/form-organization-campaign-advertisements.d.ts +0 -3
  78. package/types/dashboard/form-organization-campaign-agreement.d.ts +5 -2
  79. package/types/dashboard/form-organization-campaign.d.ts +0 -3
  80. package/types/dashboard/form-organization-connection.d.ts +0 -11
  81. package/types/dashboard/form-otc.d.ts +1 -5
  82. package/types/dashboard/form-stripe.d.ts +2 -3
  83. package/types/dashboard/input-file.d.ts +0 -2
  84. package/types/dashboard/order-sections.d.ts +1 -24
  85. package/types/input-checkbox.d.ts +0 -2
  86. package/types/shared/lib/helpers.d.ts +0 -4
  87. package/dist/bridge/cart-drawer.js +0 -152
  88. package/dist/bridge/cart-drawer.mjs +0 -123
  89. package/dist/bridge/form-subdomain-checkout.js +0 -687
  90. package/dist/bridge/form-subdomain-checkout.mjs +0 -665
  91. package/dist/bridge/lib/cart.js +0 -79
  92. package/dist/bridge/lib/cart.mjs +0 -48
  93. package/dist/dashboard/embed-stripe.js +0 -145
  94. package/dist/dashboard/embed-stripe.mjs +0 -116
  95. package/dist/dashboard/form-organization-campaign-field-birthday.js +0 -193
  96. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +0 -164
  97. package/dist/dashboard/form-organization-campaign-field-rating.js +0 -246
  98. package/dist/dashboard/form-organization-campaign-field-rating.mjs +0 -217
  99. package/dist/dashboard/form-organization-product.js +0 -1461
  100. package/dist/dashboard/form-organization-product.mjs +0 -1425
  101. package/dist/dashboard/input-gallery.js +0 -201
  102. package/dist/dashboard/input-gallery.mjs +0 -172
  103. package/dist/dashboard/lib/products.js +0 -169
  104. package/dist/dashboard/lib/products.mjs +0 -135
  105. package/dist/dashboard/lib/settings-paths.js +0 -35
  106. package/dist/dashboard/lib/settings-paths.mjs +0 -11
  107. package/dist/dashboard/shipping-rates.js +0 -404
  108. package/dist/dashboard/shipping-rates.mjs +0 -371
  109. package/dist/dashboard/template-buyer.js +0 -301
  110. package/dist/dashboard/template-buyer.mjs +0 -267
  111. package/dist/shared/order-summary.js +0 -139
  112. package/dist/shared/order-summary.mjs +0 -110
  113. package/types/bridge/cart-drawer.d.ts +0 -31
  114. package/types/bridge/form-subdomain-checkout.d.ts +0 -20
  115. package/types/bridge/lib/cart.d.ts +0 -44
  116. package/types/dashboard/embed-stripe.d.ts +0 -25
  117. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +0 -31
  118. package/types/dashboard/form-organization-campaign-field-rating.d.ts +0 -33
  119. package/types/dashboard/form-organization-product.d.ts +0 -24
  120. package/types/dashboard/input-gallery.d.ts +0 -14
  121. package/types/dashboard/lib/products.d.ts +0 -14
  122. package/types/dashboard/lib/settings-paths.d.ts +0 -5
  123. package/types/dashboard/shipping-rates.d.ts +0 -26
  124. package/types/dashboard/template-buyer.d.ts +0 -50
  125. package/types/shared/order-summary.d.ts +0 -19
@@ -1,665 +0,0 @@
1
- "use client";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
4
- import { loadStripe } from "@stripe/stripe-js";
5
- import {
6
- BillingAddressElement,
7
- CheckoutElementsProvider,
8
- ExpressCheckoutElement,
9
- PaymentElement,
10
- ShippingAddressElement,
11
- useCheckoutElements
12
- } from "@stripe/react-stripe-js/checkout";
13
- import { money as priceOf } from "../shared/lib/helpers.mjs";
14
- import { request } from "@drawbridge/drawbridge-utils/fetch";
15
- import { FormSubdomainHeader } from "./form-subdomain-header.mjs";
16
- import { continueRequest, lineNote } from "./lib/cart.mjs";
17
- import InputGroup from "../input-group.mjs";
18
- import InputSelect from "../input-select.mjs";
19
- import InputText from "../input-text.mjs";
20
- import InputRadio from "../dashboard/input-radio.mjs";
21
- import Button from "../shared/button.mjs";
22
- import ErrorLine from "../shared/error.mjs";
23
- import Loader from "../icons/loader.mjs";
24
- import OrderSummary from "../shared/order-summary.mjs";
25
- import ChevronDown from "../icons/chevron-down.mjs";
26
- import ChevronUp from "../icons/chevron-up.mjs";
27
- const stripes = /* @__PURE__ */ new Map();
28
- const stripeFor = ({ account, publishable }) => {
29
- const key = publishable + ":" + account;
30
- if (!stripes.has(key)) stripes.set(key, loadStripe(publishable, { stripeAccount: account }));
31
- return stripes.get(key);
32
- };
33
- const countryName = (code) => {
34
- try {
35
- return new Intl.DisplayNames(["en"], { type: "region" }).of(code) || code;
36
- } catch {
37
- return code;
38
- }
39
- };
40
- const visitorCountry = () => {
41
- try {
42
- return new Intl.Locale(window.navigator.language).region || null;
43
- } catch {
44
- return null;
45
- }
46
- };
47
- const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
48
- const delivery = (estimate) => {
49
- var _a, _b;
50
- return ((_a = estimate == null ? void 0 : estimate.minimum) == null ? void 0 : _a.value) && ((_b = estimate == null ? void 0 : estimate.maximum) == null ? void 0 : _b.value) ? estimate.minimum.value + "\u2013" + estimate.maximum.value + " business days" : null;
51
- };
52
- const Step = ({ children, done, onEdit, open, style, summary, title }) => /* @__PURE__ */ jsxs(
53
- "div",
54
- {
55
- ...{
56
- className: "py-6 space-y-4 border-t border-current" + (!open && !done ? " opacity-40" : "")
57
- },
58
- children: [
59
- /* @__PURE__ */ jsx(
60
- FormSubdomainHeader,
61
- {
62
- ...{
63
- button: !open && done && /* @__PURE__ */ jsx(
64
- Button,
65
- {
66
- ...{
67
- inline: true,
68
- onClick: onEdit,
69
- size: "small",
70
- variant: "link"
71
- },
72
- children: "Edit"
73
- }
74
- ),
75
- style,
76
- title
77
- }
78
- }
79
- ),
80
- /* @__PURE__ */ jsx(
81
- "div",
82
- {
83
- ...{
84
- className: open ? "space-y-4" : "hidden"
85
- },
86
- children
87
- }
88
- ),
89
- !open && done && /* @__PURE__ */ jsx(
90
- "div",
91
- {
92
- ...{
93
- className: "text-sm opacity-60 space-y-0.5"
94
- },
95
- children: summary
96
- }
97
- )
98
- ]
99
- }
100
- );
101
- const Steps = ({ back, button, cart, countries, country, cut, email, onContinue, onCountry, onEmail, onPaid, preview, shipping, style }) => {
102
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
103
- const state = useCheckoutElements();
104
- const steps = useMemo(() => shipping ? ["details", "shipping", "payment"] : ["details", "payment"], [shipping]);
105
- const [step, setStep] = useState(steps[0]);
106
- const [address, setAddress] = useState(null);
107
- const [opened, setOpened] = useState(false);
108
- const [error, setError] = useState(null);
109
- const [paying, setPaying] = useState(false);
110
- const go = useCallback((next2) => {
111
- window.history.pushState({ checkout: next2 }, "");
112
- setStep(next2);
113
- }, []);
114
- useEffect(() => {
115
- const onPop = () => setStep((current) => steps[Math.max(steps.indexOf(current) - 1, 0)]);
116
- window.addEventListener("popstate", onPop);
117
- return () => window.removeEventListener("popstate", onPop);
118
- }, [steps]);
119
- const checkout = state.type === "success" ? state.checkout : null;
120
- const options = (checkout == null ? void 0 : checkout.shippingOptions) || [];
121
- const chosen = ((_b = (_a = checkout == null ? void 0 : checkout.shipping) == null ? void 0 : _a.shippingOption) == null ? void 0 : _b.id) || null;
122
- useEffect(() => {
123
- if (checkout && options.length && !chosen) checkout.updateShippingOption(options[0].id);
124
- }, [checkout, chosen, options]);
125
- const [billing, setBilling] = useState(false);
126
- const taxStatus = (_c = checkout == null ? void 0 : checkout.tax) == null ? void 0 : _c.status;
127
- useEffect(() => {
128
- if (taxStatus === "requires_billing_address") setBilling(true);
129
- }, [taxStatus]);
130
- if (state.type === "error") return /* @__PURE__ */ jsx(ErrorLine, { ...{ error: (_d = state.error) == null ? void 0 : _d.message, style } });
131
- if (!checkout) {
132
- return /* @__PURE__ */ jsx(
133
- Loader,
134
- {
135
- ...{
136
- className: "w-5 h-5 animate-spin"
137
- }
138
- }
139
- );
140
- }
141
- ;
142
- const code = (_f = (_e = cart == null ? void 0 : cart.lines) == null ? void 0 : _e[0]) == null ? void 0 : _f.currency;
143
- const money = (value) => priceOf({ code, value });
144
- const reached = (name) => steps.indexOf(step) > steps.indexOf(name);
145
- const next = () => go(steps[steps.indexOf(step) + 1]);
146
- const detailsDone = EMAIL.test(email || "") && (!shipping || Boolean(address == null ? void 0 : address.complete));
147
- const taxed = ((_g = checkout.tax) == null ? void 0 : _g.status) === "ready" && ((_i = (_h = checkout.total) == null ? void 0 : _h.taxExclusive) == null ? void 0 : _i.minorUnitsAmount) > 0;
148
- const rate = (_j = checkout.shipping) == null ? void 0 : _j.shippingOption;
149
- const Chevron = opened ? ChevronUp : ChevronDown;
150
- const contact = async () => {
151
- var _a2;
152
- setError(null);
153
- const result = await checkout.updateEmail(email);
154
- if ((result == null ? void 0 : result.type) === "error") {
155
- setError((_a2 = result.error) == null ? void 0 : _a2.message);
156
- return;
157
- }
158
- ;
159
- onContinue(email);
160
- next();
161
- };
162
- const done = (result) => {
163
- var _a2;
164
- if ((result == null ? void 0 : result.type) === "error") {
165
- setError((_a2 = result.error) == null ? void 0 : _a2.message);
166
- return;
167
- }
168
- ;
169
- onPaid();
170
- };
171
- const pay = async () => {
172
- setPaying(true);
173
- setError(null);
174
- try {
175
- done(await checkout.confirm({ redirect: "if_required" }));
176
- } finally {
177
- setPaying(false);
178
- }
179
- };
180
- const unitOf = (item) => {
181
- var _a2, _b2, _c2;
182
- const name = item.variantTitle ? item.productTitle + " - " + item.variantTitle : item.productTitle;
183
- return ((_c2 = (_b2 = (_a2 = checkout.lineItems) == null ? void 0 : _a2.find((stripeLine) => stripeLine.name === name)) == null ? void 0 : _b2.unitAmount) == null ? void 0 : _c2.amount) || money(item.price);
184
- };
185
- const line = ((_k = cart == null ? void 0 : cart.lines) == null ? void 0 : _k.length) ? cart.lines.map((item) => ({
186
- id: item.id,
187
- image: item.image,
188
- name: item.productTitle,
189
- note: lineNote(item, cut),
190
- summary: [item.variantTitle, item.quantity + " \xD7 " + unitOf(item)].filter(Boolean).join(" \xB7 ")
191
- })) : [];
192
- return /* @__PURE__ */ jsxs("div", { children: [
193
- /* @__PURE__ */ jsx(
194
- FormSubdomainHeader,
195
- {
196
- ...{
197
- back: {
198
- onClick: () => step === steps[0] ? back() : window.history.back()
199
- },
200
- button,
201
- style,
202
- title: "Checkout"
203
- }
204
- }
205
- ),
206
- /* @__PURE__ */ jsxs(
207
- "div",
208
- {
209
- ...{
210
- className: "pt-6"
211
- },
212
- children: [
213
- /* @__PURE__ */ jsxs(
214
- "div",
215
- {
216
- ...{
217
- className: "pb-6"
218
- },
219
- children: [
220
- /* @__PURE__ */ jsx(
221
- Button,
222
- {
223
- ...{
224
- "aria-expanded": opened,
225
- onClick: () => setOpened(!opened),
226
- variant: "link"
227
- },
228
- children: /* @__PURE__ */ jsxs(
229
- "span",
230
- {
231
- ...{
232
- className: "flex items-center justify-between gap-3 w-full"
233
- },
234
- children: [
235
- /* @__PURE__ */ jsx("span", { children: "Summary" }),
236
- /* @__PURE__ */ jsxs(
237
- "span",
238
- {
239
- ...{
240
- className: "flex items-center gap-2"
241
- },
242
- children: [
243
- /* @__PURE__ */ jsx("span", { children: (_m = (_l = checkout.total) == null ? void 0 : _l.total) == null ? void 0 : _m.amount }),
244
- /* @__PURE__ */ jsx(
245
- Chevron,
246
- {
247
- ...{
248
- className: "w-5 h-5"
249
- }
250
- }
251
- )
252
- ]
253
- }
254
- )
255
- ]
256
- }
257
- )
258
- }
259
- ),
260
- (opened || (cut == null ? void 0 : cut.length) > 0) && /* @__PURE__ */ jsx(
261
- "div",
262
- {
263
- ...{
264
- className: "pt-4"
265
- },
266
- children: /* @__PURE__ */ jsx(
267
- OrderSummary,
268
- {
269
- ...{
270
- lines: line,
271
- rows: [
272
- ["Subtotal", (_o = (_n = checkout.total) == null ? void 0 : _n.subtotal) == null ? void 0 : _o.amount],
273
- ...shipping ? [["Shipping", rate ? rate.minorUnitsAmount ? rate.amount : "Free" : null]] : [],
274
- ["Tax", taxed ? checkout.total.taxExclusive.amount : null],
275
- ["Total", (_q = (_p = checkout.total) == null ? void 0 : _p.total) == null ? void 0 : _q.amount]
276
- ]
277
- }
278
- }
279
- )
280
- }
281
- )
282
- ]
283
- }
284
- ),
285
- !preview && /* @__PURE__ */ jsx(
286
- "div",
287
- {
288
- ...{
289
- className: "pb-6"
290
- },
291
- children: /* @__PURE__ */ jsx(
292
- ExpressCheckoutElement,
293
- {
294
- ...{
295
- onConfirm: async (event) => done(await checkout.confirm({ expressCheckoutConfirmEvent: event }))
296
- }
297
- }
298
- )
299
- }
300
- ),
301
- /* @__PURE__ */ jsxs(
302
- Step,
303
- {
304
- ...{
305
- done: reached("details"),
306
- onEdit: () => setStep("details"),
307
- open: step === "details",
308
- style,
309
- summary: /* @__PURE__ */ jsxs(Fragment, { children: [
310
- /* @__PURE__ */ jsx("p", { children: email }),
311
- shipping && (address == null ? void 0 : address.value) && /* @__PURE__ */ jsxs(Fragment, { children: [
312
- /* @__PURE__ */ jsx("p", { children: address.value.name }),
313
- /* @__PURE__ */ jsx("p", { children: (_r = address.value.address) == null ? void 0 : _r.line1 }),
314
- /* @__PURE__ */ jsx("p", { children: [(_s = address.value.address) == null ? void 0 : _s.city, (_t = address.value.address) == null ? void 0 : _t.state, (_u = address.value.address) == null ? void 0 : _u.postal_code].filter(Boolean).join(", ") }),
315
- /* @__PURE__ */ jsx("p", { children: countryName(country) })
316
- ] })
317
- ] }),
318
- title: shipping ? "Contact and address" : "Contact"
319
- },
320
- children: [
321
- /* @__PURE__ */ jsx(
322
- InputGroup,
323
- {
324
- ...{
325
- input: /* @__PURE__ */ jsx(
326
- InputText,
327
- {
328
- ...{
329
- autoComplete: "email",
330
- onChange: onEmail,
331
- style,
332
- type: "email",
333
- value: email || ""
334
- }
335
- }
336
- ),
337
- label: "Email",
338
- style
339
- }
340
- }
341
- ),
342
- shipping && countries.length > 1 && /* @__PURE__ */ jsx(
343
- InputGroup,
344
- {
345
- ...{
346
- input: /* @__PURE__ */ jsx(
347
- InputSelect,
348
- {
349
- ...{
350
- onChange: onCountry,
351
- options: countries.map((value) => ({ label: countryName(value), value })),
352
- style,
353
- value: country
354
- }
355
- }
356
- ),
357
- label: "Country",
358
- style
359
- }
360
- }
361
- ),
362
- shipping && /* @__PURE__ */ jsx(
363
- ShippingAddressElement,
364
- {
365
- ...{
366
- onChange: setAddress
367
- }
368
- }
369
- ),
370
- /* @__PURE__ */ jsx(
371
- Button,
372
- {
373
- ...{
374
- disabled: !detailsDone,
375
- onClick: contact,
376
- style
377
- },
378
- children: "Continue"
379
- }
380
- )
381
- ]
382
- }
383
- ),
384
- shipping && /* @__PURE__ */ jsxs(
385
- Step,
386
- {
387
- ...{
388
- done: reached("shipping"),
389
- onEdit: () => setStep("shipping"),
390
- open: step === "shipping",
391
- style,
392
- summary: rate && /* @__PURE__ */ jsx("p", { children: rate.displayName + " \xB7 " + (rate.minorUnitsAmount ? rate.amount : "Free") }),
393
- title: "Shipping"
394
- },
395
- children: [
396
- /* @__PURE__ */ jsx(
397
- "div",
398
- {
399
- ...{
400
- className: "space-y-3"
401
- },
402
- children: options.map((option) => /* @__PURE__ */ jsx(
403
- InputRadio,
404
- {
405
- ...{
406
- checked: option.id === chosen,
407
- label: /* @__PURE__ */ jsxs(
408
- "span",
409
- {
410
- ...{
411
- className: "flex items-center justify-between gap-3 w-full"
412
- },
413
- children: [
414
- /* @__PURE__ */ jsxs(
415
- "span",
416
- {
417
- ...{
418
- className: "flex flex-col min-w-0"
419
- },
420
- children: [
421
- /* @__PURE__ */ jsx(
422
- "span",
423
- {
424
- ...{
425
- className: "truncate"
426
- },
427
- children: option.displayName
428
- }
429
- ),
430
- delivery(option.deliveryEstimate) && /* @__PURE__ */ jsx(
431
- "span",
432
- {
433
- ...{
434
- className: "text-xs opacity-60 truncate"
435
- },
436
- children: delivery(option.deliveryEstimate)
437
- }
438
- )
439
- ]
440
- }
441
- ),
442
- /* @__PURE__ */ jsx(
443
- "span",
444
- {
445
- ...{
446
- className: "shrink-0"
447
- },
448
- children: option.minorUnitsAmount ? option.amount : "Free"
449
- }
450
- )
451
- ]
452
- }
453
- ),
454
- onChange: () => checkout.updateShippingOption(option.id),
455
- value: option.id
456
- }
457
- },
458
- option.id
459
- ))
460
- }
461
- ),
462
- /* @__PURE__ */ jsx(
463
- Button,
464
- {
465
- ...{
466
- disabled: !chosen,
467
- onClick: next,
468
- style
469
- },
470
- children: "Continue"
471
- }
472
- )
473
- ]
474
- }
475
- ),
476
- /* @__PURE__ */ jsxs(
477
- Step,
478
- {
479
- ...{
480
- open: step === "payment",
481
- style,
482
- title: "Payment"
483
- },
484
- children: [
485
- (billing || taxStatus === "requires_billing_address") && /* @__PURE__ */ jsx(BillingAddressElement, {}),
486
- /* @__PURE__ */ jsx(PaymentElement, {}),
487
- /* @__PURE__ */ jsx(
488
- ErrorLine,
489
- {
490
- ...{
491
- error,
492
- style
493
- }
494
- }
495
- ),
496
- /* @__PURE__ */ jsx(
497
- Button,
498
- {
499
- ...{
500
- // @story checkout/pay-on-page
501
- // On a preview link every step works and Pay stays off.
502
- disabled: preview || !checkout.canConfirm,
503
- loading: paying,
504
- onClick: pay,
505
- style
506
- },
507
- children: "Pay " + (((_w = (_v = checkout.total) == null ? void 0 : _v.total) == null ? void 0 : _w.amount) || "")
508
- }
509
- )
510
- ]
511
- }
512
- )
513
- ]
514
- }
515
- )
516
- ] });
517
- };
518
- const FormSubdomainCheckout = ({ back, button, cart: start, onCart, onPaid, params, preview, style }) => {
519
- var _a;
520
- const [country, setCountry] = useState(null);
521
- const [email, setEmail] = useState("");
522
- const [session, setSession] = useState(null);
523
- const [error, setError] = useState(null);
524
- const cartChanged = useRef(onCart);
525
- useEffect(() => {
526
- cartChanged.current = onCart;
527
- }, [onCart]);
528
- useEffect(() => {
529
- let current = true;
530
- setError(null);
531
- request({
532
- body: {
533
- cartId: start == null ? void 0 : start.id,
534
- country: country || visitorCountry()
535
- },
536
- endpoint: "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart/checkout" + (preview && (params == null ? void 0 : params.token) ? "?drwbrdg_pre=" + encodeURIComponent(params.token) : ""),
537
- method: "POST"
538
- }).then(({ result }) => {
539
- var _a2;
540
- if (!current) return;
541
- setSession(result);
542
- (_a2 = cartChanged.current) == null ? void 0 : _a2.call(cartChanged, result.cart);
543
- }).catch((thrown) => {
544
- if (current) setError((thrown == null ? void 0 : thrown.message) || "Checkout is not available right now");
545
- });
546
- return () => {
547
- current = false;
548
- };
549
- }, [country, params == null ? void 0 : params.slug, params == null ? void 0 : params.subdomain, params == null ? void 0 : params.token, preview, start == null ? void 0 : start.id]);
550
- const onContinue = (value) => {
551
- const keep = continueRequest({ cartId: start == null ? void 0 : start.id, email: value, params, preview });
552
- if (keep) request(keep).catch(() => {
553
- });
554
- };
555
- const stripe = useMemo(() => (session == null ? void 0 : session.publishable) && (session == null ? void 0 : session.account) ? stripeFor(session) : null, [session]);
556
- const appearance = useMemo(() => {
557
- var _a2, _b, _c, _d;
558
- return {
559
- variables: {
560
- ...((_b = (_a2 = style == null ? void 0 : style.text) == null ? void 0 : _a2.color) == null ? void 0 : _b.rgb) && {
561
- colorText: style.text.color.rgb
562
- },
563
- ...((_d = (_c = style == null ? void 0 : style.background) == null ? void 0 : _c.color) == null ? void 0 : _d.rgb) && {
564
- colorBackground: style.background.color.rgb
565
- }
566
- }
567
- };
568
- }, [style]);
569
- if (error) {
570
- return /* @__PURE__ */ jsxs(
571
- "div",
572
- {
573
- ...{
574
- className: "space-y-6"
575
- },
576
- children: [
577
- /* @__PURE__ */ jsx(
578
- FormSubdomainHeader,
579
- {
580
- ...{
581
- back: {
582
- onClick: back
583
- },
584
- button,
585
- style,
586
- title: "Checkout"
587
- }
588
- }
589
- ),
590
- /* @__PURE__ */ jsx(
591
- ErrorLine,
592
- {
593
- ...{
594
- error,
595
- style
596
- }
597
- }
598
- )
599
- ]
600
- }
601
- );
602
- }
603
- ;
604
- if (!session || !stripe) {
605
- return /* @__PURE__ */ jsx(
606
- FormSubdomainHeader,
607
- {
608
- ...{
609
- back: {
610
- onClick: back
611
- },
612
- button,
613
- style,
614
- title: "Checkout"
615
- }
616
- }
617
- );
618
- }
619
- ;
620
- return /* @__PURE__ */ jsx(
621
- CheckoutElementsProvider,
622
- {
623
- ...{
624
- options: {
625
- clientSecret: session.clientSecret,
626
- ...email && {
627
- defaultValues: {
628
- email
629
- }
630
- },
631
- elementsOptions: {
632
- appearance
633
- }
634
- },
635
- stripe
636
- },
637
- children: /* @__PURE__ */ jsx(
638
- Steps,
639
- {
640
- ...{
641
- back,
642
- button,
643
- cart: session.cart,
644
- countries: session.countries || [],
645
- country: session.country,
646
- cut: ((_a = session.cart) == null ? void 0 : _a.cut) || [],
647
- email,
648
- onContinue,
649
- onCountry: setCountry,
650
- onEmail: setEmail,
651
- onPaid,
652
- preview,
653
- shipping: Boolean(session.shipping),
654
- style
655
- }
656
- }
657
- )
658
- },
659
- session.clientSecret
660
- );
661
- };
662
- var form_subdomain_checkout_default = FormSubdomainCheckout;
663
- export {
664
- form_subdomain_checkout_default as default
665
- };