@drawbridge/components 0.1.13 → 0.1.14

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 (236) hide show
  1. package/components/styles.css +364 -2
  2. package/dist/advertisement.js +3 -1
  3. package/dist/advertisement.mjs +3 -1
  4. package/dist/bridge/advertisements.js +2 -0
  5. package/dist/bridge/advertisements.mjs +2 -0
  6. package/dist/bridge/countdown.js +2 -1
  7. package/dist/bridge/countdown.mjs +2 -1
  8. package/dist/bridge/form-subdomain-embed.js +18 -20
  9. package/dist/bridge/form-subdomain-embed.mjs +18 -20
  10. package/dist/bridge/form-subdomain-header.js +24 -1
  11. package/dist/bridge/form-subdomain-header.mjs +24 -1
  12. package/dist/bridge/form-subdomain-missions.js +538 -0
  13. package/dist/bridge/form-subdomain-missions.mjs +502 -0
  14. package/dist/bridge/form-subdomain.js +530 -220
  15. package/dist/bridge/form-subdomain.mjs +533 -222
  16. package/dist/bridge/lib/entry.js +59 -0
  17. package/dist/bridge/lib/entry.mjs +29 -0
  18. package/dist/bridge/lib/location.js +38 -0
  19. package/dist/bridge/lib/location.mjs +13 -0
  20. package/dist/bridge/lib/order.js +71 -0
  21. package/dist/bridge/lib/order.mjs +44 -0
  22. package/dist/bridge/lib/url.js +9 -0
  23. package/dist/bridge/lib/url.mjs +7 -0
  24. package/dist/bridge/share-button.js +5 -3
  25. package/dist/bridge/share-button.mjs +5 -3
  26. package/dist/bridge/subdomain-content.js +7 -6
  27. package/dist/bridge/subdomain-content.mjs +7 -6
  28. package/dist/bridge/template-layout.js +59 -21
  29. package/dist/bridge/template-layout.mjs +59 -21
  30. package/dist/bridge/template-modal.js +42 -76
  31. package/dist/bridge/template-modal.mjs +39 -73
  32. package/dist/bridge/template-preview.js +208 -0
  33. package/dist/bridge/template-preview.mjs +173 -0
  34. package/dist/bridge/template-subdomain-gallery.js +6 -2
  35. package/dist/bridge/template-subdomain-gallery.mjs +6 -2
  36. package/dist/bridge/template-subdomain-link.js +6 -1
  37. package/dist/bridge/template-subdomain-link.mjs +6 -1
  38. package/dist/bridge/template-subdomain.js +20 -15
  39. package/dist/bridge/template-subdomain.mjs +20 -15
  40. package/dist/dashboard/accordion.js +74 -39
  41. package/dist/dashboard/accordion.mjs +74 -39
  42. package/dist/dashboard/avatar.js +109 -3
  43. package/dist/dashboard/avatar.mjs +106 -4
  44. package/dist/dashboard/buttons-subscription.js +384 -0
  45. package/dist/dashboard/buttons-subscription.mjs +349 -0
  46. package/dist/dashboard/card-campaign-switch.js +265 -0
  47. package/dist/dashboard/card-campaign-switch.mjs +231 -0
  48. package/dist/dashboard/card-order.js +28 -11
  49. package/dist/dashboard/card-order.mjs +28 -11
  50. package/dist/dashboard/card-section.js +26 -2
  51. package/dist/dashboard/card-section.mjs +26 -2
  52. package/dist/dashboard/card-tile.js +6 -7
  53. package/dist/dashboard/card-tile.mjs +6 -7
  54. package/dist/dashboard/connection-workflows.js +196 -0
  55. package/dist/dashboard/connection-workflows.mjs +162 -0
  56. package/dist/dashboard/device.js +95 -0
  57. package/dist/dashboard/device.mjs +72 -0
  58. package/dist/dashboard/form-admin-campaign.js +19 -50
  59. package/dist/dashboard/form-admin-campaign.mjs +20 -51
  60. package/dist/dashboard/form-ai.js +9 -6
  61. package/dist/dashboard/form-ai.mjs +9 -6
  62. package/dist/dashboard/form-auth.js +35 -25
  63. package/dist/dashboard/form-auth.mjs +36 -26
  64. package/dist/dashboard/form-file.js +10 -1
  65. package/dist/dashboard/form-file.mjs +10 -1
  66. package/dist/dashboard/form-filters-analytics.js +14 -1
  67. package/dist/dashboard/form-filters-analytics.mjs +15 -2
  68. package/dist/dashboard/form-organization-campaign-advertisement.js +15 -1
  69. package/dist/dashboard/form-organization-campaign-advertisement.mjs +16 -2
  70. package/dist/dashboard/form-organization-campaign-agreement.js +215 -164
  71. package/dist/dashboard/form-organization-campaign-agreement.mjs +215 -164
  72. package/dist/dashboard/form-organization-campaign-field-email.js +0 -34
  73. package/dist/dashboard/form-organization-campaign-field-email.mjs +0 -34
  74. package/dist/dashboard/form-organization-campaign-field-list.js +466 -0
  75. package/dist/dashboard/form-organization-campaign-field-list.mjs +437 -0
  76. package/dist/dashboard/form-organization-campaign-field-phone.js +0 -34
  77. package/dist/dashboard/form-organization-campaign-field-phone.mjs +0 -34
  78. package/dist/dashboard/form-organization-campaign-field-remove.js +66 -0
  79. package/dist/dashboard/form-organization-campaign-field-remove.mjs +33 -0
  80. package/dist/dashboard/form-organization-campaign-integration-age.js +6 -12
  81. package/dist/dashboard/form-organization-campaign-integration-age.mjs +6 -12
  82. package/dist/dashboard/form-organization-campaign-integration-enable.js +52 -24
  83. package/dist/dashboard/form-organization-campaign-integration-enable.mjs +54 -26
  84. package/dist/dashboard/form-organization-campaign-integration-geocode.js +6 -12
  85. package/dist/dashboard/form-organization-campaign-integration-geocode.mjs +6 -12
  86. package/dist/dashboard/form-organization-campaign-integration-gtm.js +6 -12
  87. package/dist/dashboard/form-organization-campaign-integration-gtm.mjs +6 -12
  88. package/dist/dashboard/form-organization-campaign-link.js +7 -1
  89. package/dist/dashboard/form-organization-campaign-link.mjs +7 -1
  90. package/dist/dashboard/form-organization-campaign-mission.js +291 -0
  91. package/dist/dashboard/form-organization-campaign-mission.mjs +258 -0
  92. package/dist/dashboard/form-organization-campaign-page-embed.js +13 -2
  93. package/dist/dashboard/form-organization-campaign-page-embed.mjs +12 -1
  94. package/dist/dashboard/form-organization-campaign-page.js +20 -11
  95. package/dist/dashboard/form-organization-campaign-page.mjs +20 -11
  96. package/dist/dashboard/form-organization-campaign-prize-edit.js +12 -1
  97. package/dist/dashboard/form-organization-campaign-prize-edit.mjs +12 -1
  98. package/dist/dashboard/form-organization-campaign-section.js +223 -0
  99. package/dist/dashboard/form-organization-campaign-section.mjs +194 -0
  100. package/dist/dashboard/form-organization-campaign.js +114 -469
  101. package/dist/dashboard/form-organization-campaign.mjs +113 -467
  102. package/dist/dashboard/form-organization-export.js +4 -7
  103. package/dist/dashboard/form-organization-export.mjs +4 -7
  104. package/dist/dashboard/form-organization-identity.js +46 -51
  105. package/dist/dashboard/form-organization-identity.mjs +46 -51
  106. package/dist/dashboard/form-organization-workflow.js +518 -686
  107. package/dist/dashboard/form-organization-workflow.mjs +517 -682
  108. package/dist/dashboard/form-organization.js +82 -110
  109. package/dist/dashboard/form-organization.mjs +81 -109
  110. package/dist/dashboard/form-otc.js +4 -5
  111. package/dist/dashboard/form-otc.mjs +4 -5
  112. package/dist/dashboard/form-payment-methods.js +20 -9
  113. package/dist/dashboard/form-payment-methods.mjs +20 -9
  114. package/dist/dashboard/form-stripe.js +30 -0
  115. package/dist/dashboard/form-stripe.mjs +26 -0
  116. package/dist/dashboard/input-array.js +4 -2
  117. package/dist/dashboard/input-array.mjs +4 -2
  118. package/dist/dashboard/input-combobox.js +7 -3
  119. package/dist/dashboard/input-combobox.mjs +7 -3
  120. package/dist/dashboard/input-date.js +7 -0
  121. package/dist/dashboard/input-date.mjs +7 -0
  122. package/dist/dashboard/input-fields.js +80 -20
  123. package/dist/dashboard/input-fields.mjs +80 -20
  124. package/dist/dashboard/input-file.js +21 -1
  125. package/dist/dashboard/input-file.mjs +21 -1
  126. package/dist/dashboard/input-font.js +10 -1
  127. package/dist/dashboard/input-font.mjs +10 -1
  128. package/dist/dashboard/lib/item-list.js +57 -0
  129. package/dist/dashboard/lib/item-list.mjs +33 -0
  130. package/dist/dashboard/lib/menu.js +50 -0
  131. package/dist/dashboard/lib/menu.mjs +26 -0
  132. package/dist/dashboard/locked.js +82 -0
  133. package/dist/dashboard/locked.mjs +53 -0
  134. package/dist/dashboard/menu.js +72 -19
  135. package/dist/dashboard/menu.mjs +72 -19
  136. package/dist/dashboard/note-ai.js +69 -0
  137. package/dist/dashboard/note-ai.mjs +36 -0
  138. package/dist/dashboard/preview.js +419 -0
  139. package/dist/dashboard/preview.mjs +384 -0
  140. package/dist/dashboard/steps.js +39 -13
  141. package/dist/dashboard/steps.mjs +37 -12
  142. package/dist/dashboard/table-contacts.js +136 -0
  143. package/dist/dashboard/table-contacts.mjs +103 -0
  144. package/dist/dashboard/template-not-found.js +4 -2
  145. package/dist/dashboard/template-not-found.mjs +4 -2
  146. package/dist/dashboard/template-socket.js +20 -7
  147. package/dist/dashboard/template-socket.mjs +20 -7
  148. package/dist/icons/desktop.js +46 -0
  149. package/dist/icons/desktop.mjs +27 -0
  150. package/dist/icons/phone.js +46 -0
  151. package/dist/icons/phone.mjs +27 -0
  152. package/dist/icons/puzzle-piece.js +46 -0
  153. package/dist/icons/puzzle-piece.mjs +27 -0
  154. package/dist/icons/tablet.js +46 -0
  155. package/dist/icons/tablet.mjs +27 -0
  156. package/dist/icons/users.js +46 -0
  157. package/dist/icons/users.mjs +27 -0
  158. package/dist/input-checkbox.js +1 -0
  159. package/dist/input-checkbox.mjs +1 -0
  160. package/dist/input-code.js +101 -0
  161. package/dist/input-code.mjs +78 -0
  162. package/dist/input-text.js +2 -1
  163. package/dist/input-text.mjs +2 -1
  164. package/dist/shared/input-checkbox-list.js +0 -1
  165. package/dist/shared/input-checkbox-list.mjs +0 -1
  166. package/dist/shared/input-switch.js +6 -1
  167. package/dist/shared/input-switch.mjs +6 -1
  168. package/dist/shared/lib/campaign.js +117 -0
  169. package/dist/shared/lib/campaign.mjs +91 -0
  170. package/dist/shared/lib/helpers.js +14 -2
  171. package/dist/shared/lib/helpers.mjs +13 -2
  172. package/package.json +133 -13
  173. package/types/bridge/form-subdomain-header.d.ts +2 -0
  174. package/types/bridge/form-subdomain-missions.d.ts +36 -0
  175. package/types/bridge/form-subdomain.d.ts +23 -1
  176. package/types/bridge/lib/entry.d.ts +26 -0
  177. package/types/bridge/lib/location.d.ts +13 -0
  178. package/types/bridge/lib/order.d.ts +30 -0
  179. package/types/bridge/lib/url.d.ts +19 -0
  180. package/types/bridge/template-modal.d.ts +1 -1
  181. package/types/bridge/template-preview.d.ts +10 -0
  182. package/types/bridge/template-subdomain-link.d.ts +2 -0
  183. package/types/dashboard/accordion.d.ts +2 -0
  184. package/types/dashboard/avatar.d.ts +18 -2
  185. package/types/dashboard/buttons-subscription.d.ts +22 -0
  186. package/types/dashboard/card-campaign-switch.d.ts +32 -0
  187. package/types/dashboard/card-order.d.ts +11 -0
  188. package/types/dashboard/card-section.d.ts +2 -0
  189. package/types/dashboard/connection-workflows.d.ts +33 -0
  190. package/types/dashboard/device.d.ts +12 -0
  191. package/types/dashboard/form-admin-campaign.d.ts +3 -2
  192. package/types/dashboard/form-ai.d.ts +2 -2
  193. package/types/dashboard/form-organization-campaign-agreement.d.ts +18 -12
  194. package/types/dashboard/form-organization-campaign-field-email.d.ts +1 -2
  195. package/types/dashboard/form-organization-campaign-field-list.d.ts +36 -0
  196. package/types/dashboard/form-organization-campaign-field-phone.d.ts +1 -2
  197. package/types/dashboard/form-organization-campaign-field-remove.d.ts +22 -0
  198. package/types/dashboard/form-organization-campaign-field-select.d.ts +2 -1
  199. package/types/dashboard/form-organization-campaign-field-textarea.d.ts +2 -1
  200. package/types/dashboard/form-organization-campaign-integration-age.d.ts +3 -3
  201. package/types/dashboard/form-organization-campaign-integration-enable.d.ts +3 -3
  202. package/types/dashboard/form-organization-campaign-mission.d.ts +40 -0
  203. package/types/dashboard/form-organization-campaign-section.d.ts +27 -0
  204. package/types/dashboard/form-organization-campaign.d.ts +27 -17
  205. package/types/dashboard/form-organization-identity.d.ts +2 -0
  206. package/types/dashboard/form-organization-workflow.d.ts +43 -47
  207. package/types/dashboard/form-organization.d.ts +7 -2
  208. package/types/dashboard/form-stripe.d.ts +3 -0
  209. package/types/dashboard/input-combobox.d.ts +2 -0
  210. package/types/dashboard/input-date.d.ts +2 -0
  211. package/types/dashboard/input-fields.d.ts +3 -2
  212. package/types/dashboard/input-file.d.ts +4 -0
  213. package/types/dashboard/lib/item-list.d.ts +14 -0
  214. package/types/dashboard/lib/menu.d.ts +17 -0
  215. package/types/dashboard/locked.d.ts +10 -0
  216. package/types/dashboard/menu.d.ts +10 -2
  217. package/types/dashboard/note-ai.d.ts +15 -0
  218. package/types/dashboard/preview.d.ts +33 -0
  219. package/types/dashboard/steps.d.ts +19 -4
  220. package/types/dashboard/table-cell-title.d.ts +2 -2
  221. package/types/dashboard/table-contacts.d.ts +2 -0
  222. package/types/icons/desktop.d.ts +5 -0
  223. package/types/icons/phone.d.ts +5 -0
  224. package/types/icons/puzzle-piece.d.ts +5 -0
  225. package/types/icons/tablet.d.ts +5 -0
  226. package/types/icons/users.d.ts +5 -0
  227. package/types/input-code.d.ts +23 -0
  228. package/types/shared/input-switch.d.ts +2 -0
  229. package/types/shared/lib/campaign.d.ts +35 -0
  230. package/types/shared/lib/helpers.d.ts +3 -0
  231. package/dist/dashboard/card-integration.js +0 -187
  232. package/dist/dashboard/card-integration.mjs +0 -158
  233. package/dist/dashboard/iframe.js +0 -159
  234. package/dist/dashboard/iframe.mjs +0 -130
  235. package/types/dashboard/card-integration.d.ts +0 -24
  236. package/types/dashboard/iframe.d.ts +0 -18
@@ -1,20 +1,28 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { Fragment, useCallback, useEffect, useMemo, useState } from "react";
3
+ import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
4
4
  import { useSearchParams } from "next/navigation";
5
+ import Image from "next/image";
5
6
  import { request } from "@drawbridge/drawbridge-utils/fetch";
7
+ import { formatCurrency } from "@drawbridge/drawbridge-utils";
8
+ import { cdnSrc } from "@drawbridge/drawbridge-utils/cdn";
9
+ import { ordersItems } from "@drawbridge/drawbridge-utils/fields-validate";
6
10
  import { captureException } from "@drawbridge/drawbridge-telemetry/nextjs";
7
- import { useForm, Controller } from "react-hook-form";
11
+ import { useForm, useWatch, Controller } from "react-hook-form";
8
12
  import yup, { resolver } from "./lib/yup.mjs";
9
13
  import { ageFor, ageGateSchema } from "./lib/age-gate.mjs";
10
14
  import { useGoogleReCaptcha } from "react-google-recaptcha-v3";
11
15
  import { assertRecaptcha } from "./lib/recaptcha.mjs";
12
16
  import { submissionEndpoint } from "./lib/url.mjs";
17
+ import { agreementWording, panelMissions } from "./lib/entry.mjs";
18
+ import { LOCATION_TIMEOUT, locationCopy, locationStatus } from "./lib/location.mjs";
19
+ import { isLastList, itemCount, limitMessage, orderTotal, sectionsOf } from "./lib/order.mjs";
13
20
  import Form from "../shared/form.mjs";
14
21
  import Button from "../shared/button.mjs";
15
22
  import Fieldset from "../shared/fieldset.mjs";
16
- import { components, validate } from "./fields.mjs";
23
+ import { components, errors, validate } from "./fields.mjs";
17
24
  import InputGroup from "../input-group.mjs";
25
+ import InputNumber from "../input-number.mjs";
18
26
  import Error from "../shared/error.mjs";
19
27
  import InputText from "../input-text.mjs";
20
28
  import { FormSubdomainHeader } from "./form-subdomain-header.mjs";
@@ -22,33 +30,44 @@ import Loader from "../icons/loader.mjs";
22
30
  import Warning from "../icons/warning.mjs";
23
31
  import InputCheckbox from "../input-checkbox.mjs";
24
32
  import Advertisements from "./advertisements.mjs";
33
+ import FormSubdomainMissions from "./form-subdomain-missions.mjs";
25
34
  import Link from "next/link";
26
35
  const appendPreview = (endpoint, token) => {
27
36
  if (!token) return endpoint;
28
37
  const separator = endpoint.includes("?") ? "&" : "?";
29
38
  return endpoint + separator + "drwbrdg_pre=" + encodeURIComponent(token);
30
39
  };
40
+ const scrollToCentre = (node) => {
41
+ let box = node == null ? void 0 : node.parentElement;
42
+ while (box && !(box.scrollHeight > box.clientHeight && /auto|scroll/.test(getComputedStyle(box).overflowY))) box = box.parentElement;
43
+ if (!box) return;
44
+ box.scrollTop += node.getBoundingClientRect().top - box.getBoundingClientRect().top - (box.clientHeight - node.offsetHeight) / 2;
45
+ };
31
46
  const FormSubdomainSubmission = ({
32
47
  affiliate,
33
48
  button,
34
49
  checkout,
50
+ giveaway,
35
51
  id,
36
52
  lead,
37
53
  message,
54
+ panel,
38
55
  preview,
56
+ repeat,
39
57
  slug,
40
58
  style,
41
59
  subdomain,
42
60
  title,
43
61
  tracking
44
62
  }) => {
45
- var _a;
46
- const [loading, setLoading] = useState(Boolean(id));
47
- const [data, setData] = useState();
63
+ var _a, _b;
64
+ const [loading, setLoading] = useState(Boolean(id) && !panel);
65
+ const [fetched, setFetched] = useState();
48
66
  const [error, setError] = useState();
67
+ const data = panel || fetched;
49
68
  const searchParams = useSearchParams();
50
69
  const token = searchParams.get("drwbrdg_pre");
51
- const endpoint = submissionEndpoint({ affiliate, id, slug, subdomain, token });
70
+ const endpoint = panel ? null : submissionEndpoint({ affiliate, id, slug, subdomain, token });
52
71
  const submission = useCallback(
53
72
  async () => {
54
73
  try {
@@ -57,7 +76,7 @@ const FormSubdomainSubmission = ({
57
76
  endpoint,
58
77
  method: "GET"
59
78
  });
60
- setData(response.result);
79
+ setFetched(response.result);
61
80
  setLoading(false);
62
81
  } catch ({ message: message2 }) {
63
82
  setError(message2);
@@ -106,6 +125,43 @@ const FormSubdomainSubmission = ({
106
125
  }
107
126
  );
108
127
  }
128
+ const advertisements = ((_a = data == null ? void 0 : data.advertisements) == null ? void 0 : _a.length) > 0 && /* @__PURE__ */ jsx(
129
+ Advertisements,
130
+ {
131
+ ...{
132
+ affiliate: data == null ? void 0 : data.affiliate,
133
+ campaign: data == null ? void 0 : data.campaign,
134
+ items: (data == null ? void 0 : data.advertisements) || [],
135
+ lead,
136
+ checkout,
137
+ organization: data == null ? void 0 : data.organization,
138
+ page: data == null ? void 0 : data.page,
139
+ preview,
140
+ slug,
141
+ style,
142
+ subdomain,
143
+ tracking
144
+ }
145
+ }
146
+ );
147
+ if (Boolean(giveaway) && ((_b = data == null ? void 0 : data.missions) == null ? void 0 : _b.length) > 0) return /* @__PURE__ */ jsx(
148
+ FormSubdomainMissions,
149
+ {
150
+ ...{
151
+ advertisements,
152
+ button,
153
+ contact: data == null ? void 0 : data.contact,
154
+ message,
155
+ missions: panelMissions(data.missions, repeat),
156
+ shareLink: data == null ? void 0 : data.shareLink,
157
+ slug,
158
+ style,
159
+ subdomain,
160
+ title,
161
+ token: data == null ? void 0 : data.token
162
+ }
163
+ }
164
+ );
109
165
  return /* @__PURE__ */ jsxs(
110
166
  "div",
111
167
  {
@@ -127,25 +183,7 @@ const FormSubdomainSubmission = ({
127
183
  }
128
184
  }
129
185
  ),
130
- ((_a = data == null ? void 0 : data.advertisements) == null ? void 0 : _a.length) > 0 && /* @__PURE__ */ jsx(
131
- Advertisements,
132
- {
133
- ...{
134
- affiliate: data == null ? void 0 : data.affiliate,
135
- campaign: data == null ? void 0 : data.campaign,
136
- items: (data == null ? void 0 : data.advertisements) || [],
137
- lead,
138
- checkout,
139
- organization: data == null ? void 0 : data.organization,
140
- page: data == null ? void 0 : data.page,
141
- preview,
142
- slug,
143
- style,
144
- subdomain,
145
- tracking
146
- }
147
- }
148
- )
186
+ advertisements
149
187
  ]
150
188
  }
151
189
  );
@@ -252,53 +290,88 @@ const FormSubdomainGeocode = ({
252
290
  style,
253
291
  values
254
292
  }) => {
255
- const [error, setError] = useState(disabled ? "Campaign is not currently active" : null);
293
+ const [state, setState] = useState(disabled ? { message: "Campaign is not currently active", status: "inactive" } : { status: "checking" });
294
+ const [attempt, setAttempt] = useState(0);
256
295
  const searchParams = useSearchParams();
257
296
  const token = searchParams.get("drwbrdg_pre");
297
+ const next = useRef(callback);
298
+ next.current = callback;
258
299
  useEffect(
259
300
  () => {
260
- if (navigator.geolocation) {
261
- navigator.geolocation.getCurrentPosition(
262
- async (position) => {
263
- try {
264
- const response = await request({
265
- body: {
266
- coordinates: [
267
- position.coords.longitude,
268
- position.coords.latitude
269
- ],
270
- preview
271
- },
272
- cache: "no-store",
273
- endpoint: appendPreview("/subdomain/" + (values == null ? void 0 : values.subdomain) + "/page/" + (values == null ? void 0 : values.slug) + "/location", token),
274
- method: "POST"
275
- });
276
- callback(response);
277
- } catch ({ message }) {
278
- setError(message);
279
- }
280
- },
281
- () => {
282
- setError("Location services are not enabled.");
283
- }
284
- );
285
- } else {
286
- setError("Location data is not supported with your current browser and or device.");
301
+ var _a, _b;
302
+ if (disabled) return;
303
+ if (!navigator.geolocation) {
304
+ setState({ status: "unsupported" });
305
+ return;
287
306
  }
307
+ let live = true;
308
+ setState({ status: "checking" });
309
+ (_b = (_a = navigator.permissions) == null ? void 0 : _a.query) == null ? void 0 : _b.call(_a, { name: "geolocation" }).then((permission) => live && (permission == null ? void 0 : permission.state) === "prompt" && setState((current) => current.status === "checking" ? { status: "asking" } : current)).catch(() => {
310
+ });
311
+ navigator.geolocation.getCurrentPosition(
312
+ async (position) => {
313
+ try {
314
+ const response = await request({
315
+ body: {
316
+ coordinates: [
317
+ position.coords.longitude,
318
+ position.coords.latitude
319
+ ],
320
+ preview
321
+ },
322
+ cache: "no-store",
323
+ endpoint: appendPreview("/subdomain/" + (values == null ? void 0 : values.subdomain) + "/page/" + (values == null ? void 0 : values.slug) + "/location", token),
324
+ method: "POST"
325
+ });
326
+ if (live) next.current(response);
327
+ } catch ({ message }) {
328
+ if (live) setState({ message, status: "outside" });
329
+ }
330
+ },
331
+ (error) => live && setState({ status: locationStatus(error) }),
332
+ {
333
+ timeout: LOCATION_TIMEOUT
334
+ }
335
+ );
336
+ return () => {
337
+ live = false;
338
+ };
288
339
  },
289
- [callback, preview, token, values]
340
+ [attempt, disabled, preview, token, values == null ? void 0 : values.slug, values == null ? void 0 : values.subdomain]
290
341
  );
291
- if (error) {
292
- return /* @__PURE__ */ jsx(
293
- FormSubdomainMessage,
342
+ if (["denied", "inactive", "missing", "outside", "unsupported"].includes(state.status)) {
343
+ const retry = ["denied", "missing"].includes(state.status);
344
+ return /* @__PURE__ */ jsxs(
345
+ "div",
294
346
  {
295
347
  ...{
296
- button,
297
- message: error,
298
- style,
299
- svg: Warning,
300
- title: "Error"
301
- }
348
+ className: "space-y-6"
349
+ },
350
+ children: [
351
+ /* @__PURE__ */ jsx(
352
+ FormSubdomainMessage,
353
+ {
354
+ ...{
355
+ button,
356
+ message: state.message || locationCopy[state.status],
357
+ style,
358
+ svg: Warning,
359
+ title: "Error"
360
+ }
361
+ }
362
+ ),
363
+ retry && /* @__PURE__ */ jsx(
364
+ Button,
365
+ {
366
+ ...{
367
+ onClick: () => setAttempt((value) => value + 1),
368
+ style,
369
+ type: "button"
370
+ },
371
+ children: "Try again"
372
+ }
373
+ )
374
+ ]
302
375
  }
303
376
  );
304
377
  }
@@ -327,20 +400,32 @@ const FormSubdomainGeocode = ({
327
400
  }
328
401
  }
329
402
  ),
330
- /* @__PURE__ */ jsx(
403
+ /* @__PURE__ */ jsxs(
331
404
  "div",
332
405
  {
333
406
  ...{
334
- className: "flex items-center justify-center p-6"
407
+ className: "flex flex-col items-center justify-center gap-4 p-6"
335
408
  },
336
- children: /* @__PURE__ */ jsx(
337
- Loader,
338
- {
339
- ...{
340
- className: "w-6 h-6 animate-spin"
409
+ children: [
410
+ /* @__PURE__ */ jsx(
411
+ Loader,
412
+ {
413
+ ...{
414
+ className: "w-6 h-6 animate-spin"
415
+ }
341
416
  }
342
- }
343
- )
417
+ ),
418
+ state.status === "asking" && /* @__PURE__ */ jsx(
419
+ "p",
420
+ {
421
+ ...{
422
+ className: "text-center",
423
+ role: "status"
424
+ },
425
+ children: locationCopy.asking
426
+ }
427
+ )
428
+ ]
344
429
  }
345
430
  )
346
431
  ]
@@ -544,50 +629,200 @@ const FormSubdomainAge = ({
544
629
  }
545
630
  );
546
631
  };
547
- const FormSubdomainInformation = ({
632
+ const drawnAs = {
633
+ note: "textarea",
634
+ pickup: "select"
635
+ };
636
+ const FormSubdomainItemList = ({
637
+ currency,
638
+ field,
639
+ onChange,
640
+ prices,
641
+ style,
642
+ value
643
+ }) => {
644
+ var _a;
645
+ return /* @__PURE__ */ jsxs(
646
+ "div",
647
+ {
648
+ ...{
649
+ className: "space-y-2"
650
+ },
651
+ children: [
652
+ /* @__PURE__ */ jsx(
653
+ "p",
654
+ {
655
+ ...{
656
+ className: "text-xs uppercase tracking-wide opacity-60"
657
+ },
658
+ children: field == null ? void 0 : field.label
659
+ }
660
+ ),
661
+ /* @__PURE__ */ jsx(
662
+ "div",
663
+ {
664
+ ...{
665
+ className: "space-y-4"
666
+ },
667
+ children: (((_a = field == null ? void 0 : field.settings) == null ? void 0 : _a.items) || []).map((item) => {
668
+ var _a2, _b;
669
+ const quantity = Number(value == null ? void 0 : value[item.id]) || 0;
670
+ const src = cdnSrc(item.image, "200x200", (_a2 = item.image) == null ? void 0 : _a2.updatedAt);
671
+ return /* @__PURE__ */ jsx(
672
+ InputGroup,
673
+ {
674
+ ...{
675
+ error: limitMessage(item, quantity),
676
+ input: /* @__PURE__ */ jsxs(
677
+ "div",
678
+ {
679
+ ...{
680
+ className: "flex items-center space-x-3"
681
+ },
682
+ children: [
683
+ src && /* @__PURE__ */ jsx(
684
+ "div",
685
+ {
686
+ ...{
687
+ className: "relative w-14 h-14 rounded overflow-hidden shrink-0"
688
+ },
689
+ children: /* @__PURE__ */ jsx(
690
+ Image,
691
+ {
692
+ ...{
693
+ // The image's own description, else its file name, as every image slot.
694
+ alt: item.description || ((_b = item.image) == null ? void 0 : _b.filename) || "",
695
+ className: "object-cover",
696
+ fill: true,
697
+ sizes: "56px",
698
+ src,
699
+ unoptimized: true
700
+ }
701
+ }
702
+ )
703
+ }
704
+ ),
705
+ /* @__PURE__ */ jsxs(
706
+ "div",
707
+ {
708
+ ...{
709
+ className: "flex-1 space-y-0.5 min-w-0"
710
+ },
711
+ children: [
712
+ /* @__PURE__ */ jsx(
713
+ "p",
714
+ {
715
+ ...{
716
+ className: "text-sm font-medium leading-tight line-clamp-2"
717
+ },
718
+ children: item.name
719
+ }
720
+ ),
721
+ prices && typeof item.price === "number" && /* @__PURE__ */ jsx(
722
+ "p",
723
+ {
724
+ ...{
725
+ className: "text-xs opacity-60"
726
+ },
727
+ children: formatCurrency({
728
+ code: currency.toUpperCase(),
729
+ display: "parts",
730
+ value: item.price
731
+ })
732
+ }
733
+ )
734
+ ]
735
+ }
736
+ ),
737
+ /* @__PURE__ */ jsx(
738
+ InputNumber,
739
+ {
740
+ ...{
741
+ // The item's limit is a Number field's attributes, spread as
742
+ // FieldNumber spreads them (bridge/fields.js).
743
+ min: 0,
744
+ ...item.attributes,
745
+ "aria-label": "Quantity of " + item.name,
746
+ inline: true,
747
+ layout: "split",
748
+ onChange: (next) => onChange({
749
+ ...value,
750
+ [item.id]: next
751
+ }),
752
+ small: true,
753
+ style,
754
+ value: quantity
755
+ }
756
+ }
757
+ )
758
+ ]
759
+ }
760
+ ),
761
+ style
762
+ }
763
+ },
764
+ item.id
765
+ );
766
+ })
767
+ }
768
+ )
769
+ ]
770
+ }
771
+ );
772
+ };
773
+ const FormSubdomainSection = ({
774
+ back,
548
775
  button,
549
776
  callback = () => {
550
777
  },
551
778
  disabled,
779
+ focus,
780
+ initial,
781
+ last,
552
782
  preview,
783
+ section,
784
+ slugs = [],
553
785
  style,
554
786
  values
555
787
  }) => {
556
788
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
557
- const fields = [
558
- ...((_a = values == null ? void 0 : values.fields) == null ? void 0 : _a.lead) || [],
559
- ...((_b = values == null ? void 0 : values.fields) == null ? void 0 : _b.additional) || []
560
- ];
561
- const slugs = fields.map((field) => field == null ? void 0 : field.slug);
562
- const smsConsent = Boolean((_d = (_c = values == null ? void 0 : values.agreements) == null ? void 0 : _c.sms) == null ? void 0 : _d.enabled) || slugs.includes("phone");
563
- const marketingConsent = Boolean((_f = (_e = values == null ? void 0 : values.agreements) == null ? void 0 : _e.marketing) == null ? void 0 : _f.enabled);
789
+ const fields = (section == null ? void 0 : section.fields) || [];
790
+ const lists = fields.filter((field) => (field == null ? void 0 : field.slug) === "list");
791
+ const prices = ((_a = section == null ? void 0 : section.settings) == null ? void 0 : _a.prices) !== false;
792
+ const currency = ((_b = section == null ? void 0 : section.settings) == null ? void 0 : _b.currency) || "usd";
793
+ const smsConsent = Boolean(last) && (Boolean((_d = (_c = values == null ? void 0 : values.agreements) == null ? void 0 : _c.sms) == null ? void 0 : _d.enabled) || slugs.includes("phone"));
794
+ const marketingConsent = Boolean(last) && Boolean((_f = (_e = values == null ? void 0 : values.agreements) == null ? void 0 : _e.marketing) == null ? void 0 : _f.enabled);
795
+ const termsConsent = Boolean(last) && Boolean((_h = (_g = values == null ? void 0 : values.agreements) == null ? void 0 : _g.terms) == null ? void 0 : _h.enabled);
564
796
  const schema = useMemo(
565
797
  () => {
566
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
567
- const memoFields = [
568
- ...((_a2 = values == null ? void 0 : values.fields) == null ? void 0 : _a2.lead) || [],
569
- ...((_b2 = values == null ? void 0 : values.fields) == null ? void 0 : _b2.additional) || []
570
- ];
571
- const memoSlugs = memoFields.map((field) => field == null ? void 0 : field.slug);
798
+ var _a2;
799
+ const memoFields = (section == null ? void 0 : section.fields) || [];
800
+ const memoLists = memoFields.filter((field) => (field == null ? void 0 : field.slug) === "list");
572
801
  const shape = {
573
802
  fields: yup.object(
574
803
  memoFields.reduce(
575
804
  (accumulator, field) => {
576
- accumulator[field.id] = validate[field == null ? void 0 : field.slug](field, yup);
805
+ accumulator[field.id] = validate[drawnAs[field == null ? void 0 : field.slug] || (field == null ? void 0 : field.slug)](field, yup);
577
806
  return accumulator;
578
807
  },
579
808
  {}
580
809
  )
581
810
  )
582
811
  };
812
+ if (memoLists.length > 0) {
813
+ shape.items = yup.mixed().test("items", errors.items, function() {
814
+ var _a3;
815
+ return ordersItems(memoLists, (_a3 = this.parent) == null ? void 0 : _a3.fields);
816
+ });
817
+ }
583
818
  const agreements = {};
584
- if ((_d2 = (_c2 = values == null ? void 0 : values.agreements) == null ? void 0 : _c2.terms) == null ? void 0 : _d2.enabled) {
585
- agreements.terms = validate.agreement((_e2 = values == null ? void 0 : values.agreements) == null ? void 0 : _e2.terms, yup);
819
+ if (termsConsent) {
820
+ agreements.terms = validate.agreement((_a2 = values == null ? void 0 : values.agreements) == null ? void 0 : _a2.terms, yup);
586
821
  }
587
- if (Boolean((_g2 = (_f2 = values == null ? void 0 : values.agreements) == null ? void 0 : _f2.marketing) == null ? void 0 : _g2.enabled)) {
822
+ if (marketingConsent) {
588
823
  agreements.marketing = yup.bool();
589
824
  }
590
- if (Boolean((_i2 = (_h2 = values == null ? void 0 : values.agreements) == null ? void 0 : _h2.sms) == null ? void 0 : _i2.enabled) || memoSlugs.includes("phone")) {
825
+ if (smsConsent) {
591
826
  agreements.sms = yup.bool();
592
827
  }
593
828
  if (Object.keys(agreements).length > 0) {
@@ -595,11 +830,15 @@ const FormSubdomainInformation = ({
595
830
  }
596
831
  return yup.object(shape);
597
832
  },
598
- [values]
833
+ [marketingConsent, section, smsConsent, termsConsent, values]
599
834
  );
600
- const { control, handleSubmit, formState } = useForm({
601
- resolver: resolver(schema),
602
- values: {}
835
+ const { control, getValues, handleSubmit, formState } = useForm({
836
+ defaultValues: initial || {},
837
+ resolver: resolver(schema)
838
+ });
839
+ const answers = useWatch({
840
+ control,
841
+ name: "fields"
603
842
  });
604
843
  const checkbox = ({
605
844
  fallback,
@@ -633,6 +872,54 @@ const FormSubdomainInformation = ({
633
872
  }
634
873
  );
635
874
  };
875
+ const count = itemCount(lists, answers);
876
+ const itemsError = (_j = (_i = formState == null ? void 0 : formState.errors) == null ? void 0 : _i.items) == null ? void 0 : _j.message;
877
+ const totalBlock = (prices || itemsError) && /* @__PURE__ */ jsxs(
878
+ "div",
879
+ {
880
+ ...{
881
+ className: "space-y-4"
882
+ },
883
+ children: [
884
+ prices && /* @__PURE__ */ jsxs(
885
+ "div",
886
+ {
887
+ ...{
888
+ className: "flex items-center justify-between text-sm"
889
+ },
890
+ children: [
891
+ /* @__PURE__ */ jsx("span", { children: "ESTIMATED TOTAL \xB7 " + count + " " + (count === 1 ? "ITEM" : "ITEMS") }),
892
+ /* @__PURE__ */ jsx("span", { children: formatCurrency({
893
+ code: currency.toUpperCase(),
894
+ display: "parts",
895
+ value: orderTotal(lists, answers)
896
+ }) })
897
+ ]
898
+ }
899
+ ),
900
+ itemsError && /* @__PURE__ */ jsx(
901
+ Error,
902
+ {
903
+ ...{
904
+ error: itemsError,
905
+ style
906
+ }
907
+ }
908
+ )
909
+ ]
910
+ }
911
+ );
912
+ const consent = [
913
+ termsConsent && ["terms"],
914
+ marketingConsent && ["marketing", agreementWording.marketing],
915
+ smsConsent && ["sms", agreementWording.sms]
916
+ ].filter(Boolean);
917
+ const faded = (key) => focus && key !== focus ? "opacity-25" : "";
918
+ const focused = useRef(null);
919
+ useEffect(
920
+ () => scrollToCentre(focused.current),
921
+ [focus]
922
+ );
636
923
  return /* @__PURE__ */ jsxs(
637
924
  Form,
638
925
  {
@@ -642,22 +929,45 @@ const FormSubdomainInformation = ({
642
929
  },
643
930
  children: [
644
931
  /* @__PURE__ */ jsx(
645
- FormSubdomainHeader,
932
+ "div",
646
933
  {
647
934
  ...{
648
- button,
649
- style,
650
- title: "Your information"
651
- }
935
+ className: faded()
936
+ },
937
+ children: /* @__PURE__ */ jsx(
938
+ FormSubdomainHeader,
939
+ {
940
+ ...{
941
+ // Back keeps what this step holds so far, answered or not.
942
+ ...back && {
943
+ back: {
944
+ onClick: () => back(getValues())
945
+ }
946
+ },
947
+ button,
948
+ description: section == null ? void 0 : section.description,
949
+ style,
950
+ title: section == null ? void 0 : section.title
951
+ }
952
+ }
953
+ )
652
954
  }
653
955
  ),
654
956
  Boolean(preview) && /* @__PURE__ */ jsx(
655
- Error,
957
+ "div",
656
958
  {
657
959
  ...{
658
- error: "Preview mode: data not collected",
659
- style
660
- }
960
+ className: faded()
961
+ },
962
+ children: /* @__PURE__ */ jsx(
963
+ Error,
964
+ {
965
+ ...{
966
+ error: "Preview mode: data not collected",
967
+ style
968
+ }
969
+ }
970
+ )
661
971
  }
662
972
  ),
663
973
  /* @__PURE__ */ jsxs(
@@ -672,134 +982,111 @@ const FormSubdomainInformation = ({
672
982
  "div",
673
983
  {
674
984
  ...{
675
- className: "space-y-4"
676
- },
677
- children: fields.map((field) => /* @__PURE__ */ jsx(
678
- Controller,
679
- {
680
- ...{
681
- control,
682
- name: "fields." + field.id,
683
- render: ({ field: { onChange, value } }) => {
684
- var _a2, _b2;
685
- return components[field == null ? void 0 : field.slug]({
686
- error: (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.fields) == null ? void 0 : _b2[field == null ? void 0 : field.id],
687
- field,
688
- onChange,
689
- style,
690
- value
691
- });
692
- }
693
- }
694
- },
695
- field == null ? void 0 : field.id
696
- ))
697
- }
698
- ),
699
- (Boolean((_h = (_g = values == null ? void 0 : values.agreements) == null ? void 0 : _g.terms) == null ? void 0 : _h.enabled) || marketingConsent || smsConsent) && /* @__PURE__ */ jsxs(
700
- "div",
701
- {
702
- ...{
703
- className: "space-y-4"
985
+ className: (lists.length > 0 ? "space-y-6 " : "space-y-4 ") + faded()
704
986
  },
705
- children: [
706
- Boolean((_j = (_i = values == null ? void 0 : values.agreements) == null ? void 0 : _i.terms) == null ? void 0 : _j.enabled) && /* @__PURE__ */ jsx(
987
+ children: fields.map((field) => /* @__PURE__ */ jsxs(Fragment, { children: [
988
+ /* @__PURE__ */ jsx(
707
989
  Controller,
708
990
  {
709
991
  ...{
710
992
  control,
711
- name: "agreements.terms",
712
- render: ({ field: { value, onChange } }) => {
713
- var _a2, _b2, _c2;
714
- return /* @__PURE__ */ jsx(
715
- InputGroup,
993
+ name: "fields." + field.id,
994
+ render: ({ field: { onChange, value } }) => {
995
+ var _a2, _b2;
996
+ return (field == null ? void 0 : field.slug) === "list" ? /* @__PURE__ */ jsx(
997
+ FormSubdomainItemList,
716
998
  {
717
999
  ...{
718
- error: (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.agreements) == null ? void 0 : _b2.terms) == null ? void 0 : _c2.message,
719
- input: checkbox({
720
- key: "terms",
721
- onChange,
722
- value
723
- }),
724
- style
1000
+ currency,
1001
+ field,
1002
+ onChange,
1003
+ prices,
1004
+ style,
1005
+ value
725
1006
  }
726
1007
  }
727
- );
1008
+ ) : components[drawnAs[field == null ? void 0 : field.slug] || (field == null ? void 0 : field.slug)]({
1009
+ error: (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.fields) == null ? void 0 : _b2[field == null ? void 0 : field.id],
1010
+ field,
1011
+ onChange,
1012
+ style,
1013
+ value
1014
+ });
728
1015
  }
729
1016
  }
730
1017
  }
731
1018
  ),
732
- marketingConsent && /* @__PURE__ */ jsx(
733
- Controller,
734
- {
735
- ...{
736
- control,
737
- name: "agreements.marketing",
738
- render: ({ field: { value, onChange } }) => {
739
- var _a2, _b2, _c2;
740
- return /* @__PURE__ */ jsx(
741
- InputGroup,
742
- {
743
- ...{
744
- error: (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.agreements) == null ? void 0 : _b2.marketing) == null ? void 0 : _c2.message,
745
- input: checkbox({
746
- fallback: "I agree to receive marketing emails about this campaign. Unsubscribe any time.",
747
- key: "marketing",
748
- onChange,
749
- value
750
- }),
751
- style
752
- }
753
- }
754
- );
755
- }
1019
+ isLastList(fields, field == null ? void 0 : field.id) && totalBlock
1020
+ ] }, field == null ? void 0 : field.id))
1021
+ }
1022
+ ),
1023
+ consent.length > 0 && /* @__PURE__ */ jsx(
1024
+ "div",
1025
+ {
1026
+ ...{
1027
+ className: "space-y-4"
1028
+ },
1029
+ children: consent.map(([key, fallback]) => /* @__PURE__ */ jsx(
1030
+ "div",
1031
+ {
1032
+ ...{
1033
+ className: faded(key),
1034
+ ...key === focus && {
1035
+ ref: focused
756
1036
  }
757
- }
758
- ),
759
- smsConsent && /* @__PURE__ */ jsx(
760
- Controller,
761
- {
762
- ...{
763
- control,
764
- name: "agreements.sms",
765
- render: ({ field: { value, onChange } }) => {
766
- var _a2, _b2, _c2;
767
- return /* @__PURE__ */ jsx(
768
- InputGroup,
769
- {
770
- ...{
771
- error: (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.agreements) == null ? void 0 : _b2.sms) == null ? void 0 : _c2.message,
772
- input: checkbox({
773
- // The default wording carrier reviewers look
774
- // for: explicit texts, rates, and STOP.
775
- fallback: "I agree to receive text messages about this campaign. Message and data rates may apply. Reply STOP to opt out.",
776
- key: "sms",
777
- onChange,
778
- value
779
- }),
780
- style
1037
+ },
1038
+ children: /* @__PURE__ */ jsx(
1039
+ Controller,
1040
+ {
1041
+ ...{
1042
+ control,
1043
+ name: "agreements." + key,
1044
+ render: ({ field: { value, onChange } }) => {
1045
+ var _a2, _b2, _c2;
1046
+ return /* @__PURE__ */ jsx(
1047
+ InputGroup,
1048
+ {
1049
+ ...{
1050
+ error: (_c2 = (_b2 = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2.agreements) == null ? void 0 : _b2[key]) == null ? void 0 : _c2.message,
1051
+ input: checkbox({
1052
+ fallback,
1053
+ key,
1054
+ onChange,
1055
+ value
1056
+ }),
1057
+ style
1058
+ }
781
1059
  }
782
- }
783
- );
1060
+ );
1061
+ }
784
1062
  }
785
1063
  }
786
- }
787
- )
788
- ]
1064
+ )
1065
+ },
1066
+ key
1067
+ ))
789
1068
  }
790
1069
  )
791
1070
  ]
792
1071
  }
793
1072
  ),
794
1073
  /* @__PURE__ */ jsx(
795
- FormSubdomainButton,
1074
+ "div",
796
1075
  {
797
1076
  ...{
798
- disabled,
799
- style,
800
- submitting: formState == null ? void 0 : formState.isSubmitting,
801
- text: "Submit"
802
- }
1077
+ className: faded()
1078
+ },
1079
+ children: /* @__PURE__ */ jsx(
1080
+ FormSubdomainButton,
1081
+ {
1082
+ ...{
1083
+ disabled,
1084
+ style,
1085
+ submitting: formState == null ? void 0 : formState.isSubmitting,
1086
+ text: last ? "Submit" : "Next"
1087
+ }
1088
+ }
1089
+ )
803
1090
  }
804
1091
  )
805
1092
  ]
@@ -811,6 +1098,7 @@ const FormSubdomain = ({
811
1098
  button,
812
1099
  disabled,
813
1100
  fields,
1101
+ focus,
814
1102
  integrations,
815
1103
  onCheckout,
816
1104
  onError = () => {
@@ -819,6 +1107,7 @@ const FormSubdomain = ({
819
1107
  },
820
1108
  params,
821
1109
  preview,
1110
+ step: start = 0,
822
1111
  style,
823
1112
  tracking
824
1113
  }) => {
@@ -827,7 +1116,17 @@ const FormSubdomain = ({
827
1116
  const searchParams = useSearchParams();
828
1117
  const token = searchParams.get("drwbrdg_pre");
829
1118
  const [data, setData] = useState({});
830
- const [step, setStep] = useState(0);
1119
+ const [step, setStep] = useState(start);
1120
+ const sections = sectionsOf(fields);
1121
+ const slugs = sections.flatMap((section) => ((section == null ? void 0 : section.fields) || []).map((field) => field == null ? void 0 : field.slug));
1122
+ const merge = (object = {}) => ({
1123
+ ...data,
1124
+ ...object,
1125
+ fields: {
1126
+ ...data.fields,
1127
+ ...object.fields
1128
+ }
1129
+ });
831
1130
  const onSubmit = useCallback(
832
1131
  async (values) => {
833
1132
  var _a2, _b2;
@@ -844,7 +1143,6 @@ const FormSubdomain = ({
844
1143
  const response = await request({
845
1144
  body: {
846
1145
  ...values,
847
- entries: 1,
848
1146
  preview,
849
1147
  recaptcha,
850
1148
  tracking: (_b2 = tracking == null ? void 0 : tracking.context) == null ? void 0 : _b2.call(tracking)
@@ -929,26 +1227,40 @@ const FormSubdomain = ({
929
1227
  "form-subdomain-age"
930
1228
  )
931
1229
  ] : [],
932
- /* @__PURE__ */ jsx(
933
- FormSubdomainInformation,
1230
+ ...sections.map((section, index) => /* @__PURE__ */ jsx(
1231
+ FormSubdomainSection,
934
1232
  {
935
1233
  ...{
1234
+ // Back moves between sections; it never returns into the location or age step.
1235
+ back: index > 0 ? (object) => {
1236
+ setData(merge(object));
1237
+ setStep(step - 1);
1238
+ } : null,
936
1239
  button,
937
- callback: async (object) => await onSubmit({
938
- ...data,
939
- ...object
940
- }),
1240
+ callback: async (object) => {
1241
+ const merged = merge(object);
1242
+ if (index < sections.length - 1) {
1243
+ setData(merged);
1244
+ setStep(step + 1);
1245
+ return;
1246
+ }
1247
+ await onSubmit(merged);
1248
+ },
941
1249
  disabled,
1250
+ focus,
1251
+ initial: data,
1252
+ last: index === sections.length - 1,
942
1253
  preview,
1254
+ section,
1255
+ slugs,
943
1256
  style,
944
1257
  values: {
945
- agreements,
946
- fields
1258
+ agreements
947
1259
  }
948
1260
  }
949
1261
  },
950
- "form-subdomain-information"
951
- )
1262
+ "form-subdomain-section-" + section.id
1263
+ ))
952
1264
  ];
953
1265
  return /* @__PURE__ */ jsx(
954
1266
  "div",
@@ -970,7 +1282,6 @@ const FormSubdomain = ({
970
1282
  };
971
1283
  var form_subdomain_default = FormSubdomain;
972
1284
  export {
973
- FormSubdomainHeader,
974
1285
  FormSubdomainMessage,
975
1286
  FormSubdomainSubmission,
976
1287
  form_subdomain_default as default