@scopetickets/checkout 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -54,7 +54,7 @@ import {
54
54
  userTypeNames,
55
55
  withSelectedDay,
56
56
  withSelectedTime
57
- } from "./chunk-4BOPQURW.js";
57
+ } from "./chunk-GJZKPJB5.js";
58
58
 
59
59
  // src/island/CarrySlot.tsx
60
60
  import { createContext, useContext, useLayoutEffect, useRef } from "react";
@@ -237,8 +237,22 @@ import {
237
237
  } from "react";
238
238
 
239
239
  // src/island/island-geometry.ts
240
- function pinEdge(align) {
241
- return align === "center" ? null : align;
240
+ var AXES = {
241
+ "top-left": { block: "top", inline: "left" },
242
+ top: { block: "top", inline: "center" },
243
+ "top-right": { block: "top", inline: "right" },
244
+ left: { block: "center", inline: "left" },
245
+ center: { block: "center", inline: "center" },
246
+ right: { block: "center", inline: "right" },
247
+ "bottom-left": { block: "bottom", inline: "left" },
248
+ bottom: { block: "bottom", inline: "center" },
249
+ "bottom-right": { block: "bottom", inline: "right" }
250
+ };
251
+ function alignmentAxes(align) {
252
+ return AXES[align];
253
+ }
254
+ function pinEdge(block) {
255
+ return block === "center" ? null : block;
242
256
  }
243
257
  var SPACE = {
244
258
  /** `$0.25` — the hairline step. */
@@ -330,12 +344,24 @@ function toLocal(rect, container, align, scale = 1) {
330
344
  height: rect.height / s
331
345
  };
332
346
  }
333
- var NO_GROWTH = Object.freeze({ surface: 0, bay: 0, gutter: 0 });
334
- function anchorTravel(growth, anchor) {
335
- return anchor === "CHROME" ? 0 : growth.surface - growth.bay - growth.gutter;
347
+ var NO_GROWTH = Object.freeze({ surface: 0, clip: 0, gutter: 0 });
348
+ function anchorTravel(growth, anchor, align) {
349
+ if (anchor === "CHROME") return 0;
350
+ switch (align) {
351
+ case "top":
352
+ return 0;
353
+ case "bottom":
354
+ return growth.clip - growth.gutter;
355
+ case "center":
356
+ return (growth.clip - growth.gutter) / 2;
357
+ default: {
358
+ const exhaustive = align;
359
+ return exhaustive;
360
+ }
361
+ }
336
362
  }
337
363
  function forSurfaceGrowth(rect, growth, anchor, align) {
338
- const travel = anchorTravel(growth, anchor);
364
+ const travel = anchorTravel(growth, anchor, align);
339
365
  switch (align) {
340
366
  case "top":
341
367
  return { ...rect, offset: rect.offset + travel };
@@ -343,6 +369,10 @@ function forSurfaceGrowth(rect, growth, anchor, align) {
343
369
  return { ...rect, offset: rect.offset + growth.surface - travel };
344
370
  case "center":
345
371
  return { ...rect, offset: rect.offset + travel - growth.surface / 2 };
372
+ default: {
373
+ const exhaustive = align;
374
+ return exhaustive;
375
+ }
346
376
  }
347
377
  }
348
378
  function carryTransform(from, to, align) {
@@ -473,6 +503,7 @@ var IslandSurface = forwardRef(function IslandSurface2({
473
503
  rowHeight,
474
504
  edge,
475
505
  align,
506
+ placement,
476
507
  journeyFullscreen,
477
508
  popAxis = "both",
478
509
  press,
@@ -482,6 +513,7 @@ var IslandSurface = forwardRef(function IslandSurface2({
482
513
  height,
483
514
  label,
484
515
  footprint,
516
+ footprintEdge,
485
517
  clipRef,
486
518
  bay,
487
519
  bayHeight,
@@ -491,6 +523,8 @@ var IslandSurface = forwardRef(function IslandSurface2({
491
523
  shield,
492
524
  sealed = false
493
525
  }, ref) {
526
+ const axes = alignmentAxes(align);
527
+ const pinned = placement === "screen";
494
528
  const style = {
495
529
  "--scopetickets-island-radius": `${radius}px`,
496
530
  "--scopetickets-island-padding-block": `${padding.block}px`,
@@ -530,13 +564,19 @@ var IslandSurface = forwardRef(function IslandSurface2({
530
564
  };
531
565
  return (
532
566
  // The reservation, and nothing else: it holds the island's collapsed footprint open
533
- // in the host page's flow and gives the frame something to be positioned against.
567
+ // in the host page's flow — or, placed on the screen, pinned to it — and gives the
568
+ // frame something to be positioned against.
534
569
  /* @__PURE__ */ jsxs3(
535
570
  "div",
536
571
  {
537
572
  "data-scopetickets-island-anchor": true,
573
+ "data-placement": pinned ? "screen" : void 0,
574
+ "data-align-block": pinned ? axes.block : void 0,
538
575
  className: "scopetickets-island-anchor",
539
- style: { "--scopetickets-island-anchor-height": `${footprint}px` },
576
+ style: {
577
+ "--scopetickets-island-anchor-height": `${footprint}px`,
578
+ ...pinned ? { "--scopetickets-island-anchor-inset": `${footprintEdge}px` } : {}
579
+ },
540
580
  children: [
541
581
  shield,
542
582
  /* @__PURE__ */ jsx5(
@@ -545,7 +585,8 @@ var IslandSurface = forwardRef(function IslandSurface2({
545
585
  ref,
546
586
  "data-scopetickets-island": true,
547
587
  "data-mode": modeAttribute(mode),
548
- "data-align": align,
588
+ "data-align-block": axes.block,
589
+ "data-align-inline": axes.inline,
549
590
  "data-journey": journeyFullscreen ? "fullscreen" : void 0,
550
591
  "data-pop-axis": popAxis === "block" ? "block" : void 0,
551
592
  "data-press": press ?? void 0,
@@ -597,6 +638,7 @@ var layoutScale = (element) => {
597
638
  };
598
639
  var startAtRest = (contentKey) => atRest(initialSlots(contentKey));
599
640
  var COLLAPSED_FOOTPRINT = footprintHeight("compact");
641
+ var COLLAPSED_EDGE = frameFor("compact").edge;
600
642
  function IslandHost({
601
643
  presentation,
602
644
  contentKey,
@@ -604,6 +646,7 @@ function IslandHost({
604
646
  label,
605
647
  mode,
606
648
  align = "bottom",
649
+ placement = "page",
607
650
  journeyFullscreen,
608
651
  chrome,
609
652
  bay,
@@ -616,6 +659,7 @@ function IslandHost({
616
659
  }) {
617
660
  const [state, dispatch] = useReducer(reduceTransition, contentKey, startAtRest);
618
661
  const frame = frameFor(presentation);
662
+ const { block } = alignmentAxes(align);
619
663
  const [press, setPress] = useState2(null);
620
664
  const ledRef = useRef3("none");
621
665
  const letGo = useRef3(null);
@@ -700,7 +744,6 @@ function IslandHost({
700
744
  );
701
745
  const clipRef = useRef3(null);
702
746
  const layerRef = useRef3(null);
703
- const baySectionRef = useRef3(null);
704
747
  const bayRef = useRef3(null);
705
748
  const [bayContent, setBayContent] = useState2(0);
706
749
  const measureBay = useCallback2(() => {
@@ -802,14 +845,16 @@ function IslandHost({
802
845
  const scale = layoutScale(layer);
803
846
  const arrivingPlane = activePlaneRef.current;
804
847
  const bayTarget = bayShown ? bayRef.current?.offsetHeight ?? 0 : 0;
805
- const baySection = baySectionRef.current;
806
- const bayNow = baySection === null ? 0 : asRect(baySection).height / scale;
848
+ const clipNow = clipRef.current === null ? 0 : asRect(clipRef.current).height / scale;
807
849
  const gutter = gutterTravel();
808
- const growth = arrivingPlane === null ? NO_GROWTH : {
809
- surface: surfaceHeight(arrivingPlane.getBoundingClientRect().height / scale + gutter) + bayTarget - container.height / scale,
810
- bay: bayTarget - bayNow,
811
- gutter
812
- };
850
+ const growth = arrivingPlane === null ? NO_GROWTH : (() => {
851
+ const planeTarget = arrivingPlane.getBoundingClientRect().height / scale + gutter;
852
+ return {
853
+ surface: planeTarget + bayTarget - container.height / scale,
854
+ clip: planeTarget - clipNow,
855
+ gutter
856
+ };
857
+ })();
813
858
  const found = [];
814
859
  for (const [name, entry] of registry.current) {
815
860
  const leavingEntry = entry[leaving] ?? entry[CHROME];
@@ -818,14 +863,14 @@ function IslandHost({
818
863
  const from = leavingEntry?.element;
819
864
  const arriving = arrivingEntry;
820
865
  if (!from || !arriving?.element) continue;
821
- const fromRect = toLocal(asRect(from), container, align, scale);
866
+ const fromRect = toLocal(asRect(from), container, block, scale);
822
867
  const toRect = forSurfaceGrowth(
823
- toLocal(asRect(arriving.element), container, align, scale),
868
+ toLocal(asRect(arriving.element), container, block, scale),
824
869
  growth,
825
870
  entry[active] === void 0 ? "CHROME" : "PLANE",
826
- align
871
+ block
827
872
  );
828
- const transform = carryTransform(fromRect, toRect, align);
873
+ const transform = carryTransform(fromRect, toRect, block);
829
874
  const moving = !isStationary(transform);
830
875
  if (arriving.carryWhen === "resized" && !isResized(transform)) continue;
831
876
  const fromLeaving = moving && drawsFromLeaving(fromRect, toRect);
@@ -842,7 +887,7 @@ function IslandHost({
842
887
  lift: toCssLift(transform),
843
888
  grow: toCssGrow(fromRect, raster),
844
889
  rest: toCssGrow(toRect, raster),
845
- lead: carryLead(fromRect, toRect, align)
890
+ lead: carryLead(fromRect, toRect, block)
846
891
  } : {}
847
892
  });
848
893
  }
@@ -850,7 +895,7 @@ function IslandHost({
850
895
  });
851
896
  if (next.length === 0) return;
852
897
  dispatch({ type: "CARRIES_MEASURED", carries: next });
853
- }, [active, state.phase, atFinalWidth, gutterTravel, align, bayShown]);
898
+ }, [active, state.phase, atFinalWidth, gutterTravel, block, bayShown]);
854
899
  useEffect2(() => {
855
900
  if (state.phase !== "PLACED") return void 0;
856
901
  const frame2 = requestAnimationFrame(() => dispatch({ type: "PAINTED" }));
@@ -901,17 +946,18 @@ function IslandHost({
901
946
  rowHeight: frame.rowHeight,
902
947
  edge: frame.edge,
903
948
  align,
949
+ placement,
904
950
  journeyFullscreen,
905
951
  popAxis,
906
952
  press: transitioning ? null : press,
907
953
  gesture,
908
954
  footprint: COLLAPSED_FOOTPRINT,
955
+ footprintEdge: COLLAPSED_EDGE,
909
956
  transitioning,
910
957
  height: height === null ? null : height + bayHeight,
911
958
  bay: bay === void 0 ? void 0 : /* @__PURE__ */ jsx6(
912
959
  "section",
913
960
  {
914
- ref: baySectionRef,
915
961
  className: "scopetickets-island-surface__bay",
916
962
  "aria-label": bayLabel,
917
963
  "aria-hidden": !bayVisible,
@@ -947,7 +993,7 @@ function IslandHost({
947
993
  // Against whatever does not move while the card grows — an edge, or
948
994
  // the centre line where the island is pinned to neither. See
949
995
  // `toCssInset`, which used to be `[align]` and could not stay that.
950
- ...toCssInset(carry.to.offset, carry.box.height, align),
996
+ ...toCssInset(carry.to.offset, carry.box.height, block),
951
997
  width: `${carry.box.width}px`,
952
998
  height: `${carry.box.height}px`,
953
999
  transform: painted ? void 0 : carry.slide
@@ -1050,6 +1096,7 @@ function CheckoutIsland({
1050
1096
  headerTrail,
1051
1097
  mode,
1052
1098
  align,
1099
+ placement,
1053
1100
  journeyFullscreen
1054
1101
  }) {
1055
1102
  const flies = !(variant === "hold" || variant === "cart");
@@ -1085,6 +1132,7 @@ function CheckoutIsland({
1085
1132
  label: "Your order",
1086
1133
  mode,
1087
1134
  align,
1135
+ placement,
1088
1136
  journeyFullscreen,
1089
1137
  chrome,
1090
1138
  bay,
@@ -1418,6 +1466,30 @@ var ScopeClient = class {
1418
1466
  signal
1419
1467
  });
1420
1468
  }
1469
+ /**
1470
+ * Tickets for any number of events or whole series in one request, each row naming the
1471
+ * events it sells for in `EventKeys`.
1472
+ *
1473
+ * THE ROUTE TO READ TICKETS FROM. `Events/{key}/Tickets` omits a timeslot at
1474
+ * `Remaining: 0` rather than reporting it sold out, so a sold-out session never reaches
1475
+ * the picker at all.
1476
+ *
1477
+ * A MISSPELT PARAMETER IS NOT REFUSED: the platform answers `200 {"Tickets":[]}`, which
1478
+ * reads exactly like an event that sells nothing.
1479
+ */
1480
+ async getTicketInformation(query, signal) {
1481
+ const params = new URLSearchParams();
1482
+ for (const key of query.events ?? []) params.append("events", key);
1483
+ for (const key of query.series ?? []) params.append("series", key);
1484
+ if (query.includeTimeslots) params.set("include_timeslots", "true");
1485
+ if (query.includeQuestions) params.set("include_questions", "true");
1486
+ const response = await this.fetch(
1487
+ `/api/v2/TicketInformation?${params}`,
1488
+ { signal }
1489
+ );
1490
+ return response.Tickets ?? [];
1491
+ }
1492
+ /** @deprecated Use getTicketInformation(), which also reports sold-out timeslots */
1421
1493
  async getEventTickets(eventKey, signal) {
1422
1494
  const response = await this.fetch(
1423
1495
  `/api/v2/Events/${eventKey}/Tickets?include_timeslots=true`,
@@ -2490,8 +2562,8 @@ function e164(dialCode, phone) {
2490
2562
  if (country === null) return null;
2491
2563
  const national = nationalDigits(phone, country);
2492
2564
  if (!isValidPhone(phone, country)) return null;
2493
- const composed = `${country.dialCode}${national}`;
2494
- return isE164(composed) ? composed : null;
2565
+ const composed2 = `${country.dialCode}${national}`;
2566
+ return isE164(composed2) ? composed2 : null;
2495
2567
  }
2496
2568
  function normalizeE164(value) {
2497
2569
  const { dialCode, national } = splitPhoneNumber(value);
@@ -3203,8 +3275,8 @@ var PURCHASE_STEPS = [
3203
3275
  name: "More Information",
3204
3276
  islandState: "details",
3205
3277
  preflightStepId: "questionnaire",
3206
- blurb: "The event\u2019s own questions \u2014 the last thing the order can still be missing. Needs the cart, which is the only source of the integer EventId the questions endpoint takes, and by here the cart is four steps old.",
3207
- excusedWhen: "The event asks nothing. A failed LOOKUP is NOT this \u2014 it resolves to a notice, because proceeding would let the buyer reach payment and be rejected server-side with nothing on screen to fix.",
3278
+ blurb: "The event\u2019s own questions \u2014 the last thing the order can still be missing. They come from the tickets and from the event\u2019s questionnaire, or its series\u2019, which is read with the cart; the answers go to every cart item once, before any charge.",
3279
+ excusedWhen: "Nothing asks \u2014 not the ticket, the event or its series. A failed LOOKUP is NOT this \u2014 it resolves to a notice, because proceeding would let the buyer reach payment and be rejected server-side with nothing on screen to fix.",
3208
3280
  collapsed: pill("Add Details")
3209
3281
  },
3210
3282
  {
@@ -4248,136 +4320,182 @@ function useCheckoutClient(appKey, source) {
4248
4320
  });
4249
4321
  }, [appKey, orgKey, environment]);
4250
4322
  }
4323
+ function readRun(info, environment) {
4324
+ const eventKeyByDay = {};
4325
+ for (const event of info.Events) eventKeyByDay[dayOf(event.Date)] = event.Key;
4326
+ const theme = info.Series?.Theme ?? info.Events[0]?.Theme;
4327
+ const artwork = runArtwork(info.Series, info.Events, ENVIRONMENT_URLS[environment].artworkUrl);
4328
+ if (artwork === void 0 && theme !== void 0 && typeof console !== "undefined") {
4329
+ console.warn(
4330
+ "[ScopeTicketsCheckout] no cart artwork resolved from this run\u2019s Theme. Expected a url in `Theme.Backgrounds[0]`. The Theme as it arrived:",
4331
+ theme
4332
+ );
4333
+ }
4334
+ return {
4335
+ info,
4336
+ events: info.Events.map((event) => ({
4337
+ eventKey: event.Key,
4338
+ name: event.Name,
4339
+ day: dayOf(event.Date)
4340
+ })),
4341
+ eventKeyByDay,
4342
+ /*
4343
+ * THE VENUE'S CLOCK, from the venue. `Venue.TimeZone` is an IANA zone and every event
4344
+ * carries its venue — `nowTime` was `00:00` for a turn, which is not a clock at all:
4345
+ * it says every slot today is still to come, which is exactly the question the time
4346
+ * picker asks it.
4347
+ */
4348
+ timeZone: info.Events[0]?.Venue?.TimeZone ?? null,
4349
+ artwork
4350
+ };
4351
+ }
4352
+ function composed({ run, wanted, today, nowTime, tickets, error }, loading) {
4353
+ const { info } = run;
4354
+ const slots = tickets.flatMap((ticket) => ticket.HasTimeslot ? ticket.Timeslots ?? [] : []);
4355
+ const slotsByDay = wanted !== null && slots.length > 0 ? { [wanted]: slots.map(toTimeslot) } : {};
4356
+ const questions = tickets.flatMap((ticket) => ticket.Questions ?? []);
4357
+ const productCurrency = tickets.map((ticket) => ticket.Currency).find((currency) => currency !== null && currency !== void 0);
4358
+ const assignments = [
4359
+ ...info.UserTypes ?? [],
4360
+ ...info.Events.flatMap((event) => event.UserTypes ?? []),
4361
+ ...tickets.flatMap((ticket) => ticket.UserTypes ?? [])
4362
+ ];
4363
+ const organisation = info.Events[0]?.Organisation;
4364
+ return {
4365
+ schedule: {
4366
+ series: { events: [...run.events] },
4367
+ today,
4368
+ nowTime,
4369
+ slotsByDay
4370
+ },
4371
+ userTypes: groupUserTypes(assignments),
4372
+ userTypeNames: userTypeNames(assignments),
4373
+ /*
4374
+ * THE QUESTIONS RIDE ON THE TICKETS, so they arrive with the slots and cost no
4375
+ * request of their own. `getQuestionnaireQuestions` wants a cart's event id, which
4376
+ * does not exist yet at the step that has to know whether to ask.
4377
+ */
4378
+ questions: [...new Map(questions.map((q) => [q.QuestionId, q])).values()],
4379
+ /*
4380
+ * WHOSE EVENT IT IS. There is no follow endpoint and there does not need to be:
4381
+ * the organisation is on every event, and it is who a buyer would want to hear
4382
+ * from again.
4383
+ *
4384
+ * NOT THE VENUE, though the event names one. A venue hosts whatever is booked
4385
+ * into it — following one subscribes a buyer to every unrelated thing that happens
4386
+ * in a building, which is not what "stay up to date" offered them. The organiser
4387
+ * is the party whose next event resembles this one.
4388
+ */
4389
+ follow: [
4390
+ organisation === void 0 ? null : { key: organisation.Key, name: organisation.Name, kind: "Organiser" }
4391
+ ].filter((entity) => entity !== null),
4392
+ /*
4393
+ * `Backgrounds[0]`, made absolute against the CDN, the run's before a night's — see
4394
+ * `runArtwork`. The platform answers with site-root paths, so the origin is the
4395
+ * whole of the work: without it every thumbnail points at the customer's own domain.
4396
+ */
4397
+ artwork: run.artwork,
4398
+ eventKeyByDay: run.eventKeyByDay,
4399
+ hasTimeslots: tickets.some((ticket) => ticket.HasTimeslot),
4400
+ limits: ticketLimits(tickets),
4401
+ /* Most specific first — a product's own, then its event's, then the run's. */
4402
+ currency: productCurrency ?? info.Events[0]?.Currency ?? info.Series?.Currency ?? void 0,
4403
+ loading,
4404
+ error: loading ? null : error
4405
+ };
4406
+ }
4251
4407
  function useCheckoutData(subjectKey, isSeries, client, enabled, day, environment = "production") {
4252
- const [data, setData] = useState5(NOTHING);
4408
+ const [run, setRun] = useState5({ status: "IDLE" });
4409
+ const [sessions, setSessions] = useState5({ status: "IDLE" });
4253
4410
  useEffect4(() => {
4254
4411
  if (!enabled || client === null) return;
4255
4412
  const abort = new AbortController();
4256
- setData((was) => ({ ...was, loading: true, error: null }));
4257
- const load = async () => {
4258
- const info = isSeries ? await client.getSeriesInfo(subjectKey, abort.signal) : await client.getEventInfo(subjectKey, abort.signal);
4259
- const eventKeyByDay = {};
4260
- for (const event of info.Events) eventKeyByDay[dayOf(event.Date)] = event.Key;
4261
- const events = info.Events.map((event) => ({
4262
- eventKey: event.Key,
4263
- name: event.Name,
4264
- day: dayOf(event.Date)
4265
- }));
4266
- const timeZone = info.Events[0]?.Venue?.TimeZone ?? null;
4267
- const now = /* @__PURE__ */ new Date();
4268
- const today = dayInZone(now, timeZone);
4269
- const wanted = day !== void 0 && day in eventKeyByDay ? day : soonestRelevantDay({ events }, today);
4270
- const forDay = wanted === null ? void 0 : eventKeyByDay[wanted];
4271
- const slotsByDay = {};
4272
- const questions = [];
4273
- let list = [];
4274
- let ticketsError = null;
4275
- if (forDay !== void 0) {
4276
- try {
4277
- list = await client.getEventTickets(forDay, abort.signal);
4278
- } catch (cause) {
4279
- ticketsError = cause instanceof Error ? cause : new Error(String(cause));
4280
- }
4281
- }
4282
- const tickets = wanted === null ? [] : [[wanted, list]];
4283
- let hasTimeslots = false;
4284
- let productCurrency;
4285
- for (const [on, forThatDay] of tickets) {
4286
- const slots = forThatDay.flatMap(
4287
- (ticket) => ticket.HasTimeslot ? ticket.Timeslots ?? [] : []
4288
- );
4289
- if (forThatDay.some((ticket) => ticket.HasTimeslot)) hasTimeslots = true;
4290
- if (slots.length > 0) slotsByDay[on] = slots.map(toTimeslot);
4291
- for (const ticket of forThatDay) {
4292
- questions.push(...ticket.Questions ?? []);
4293
- productCurrency ??= ticket.Currency ?? void 0;
4294
- }
4295
- }
4296
- const assignments = [
4297
- ...info.UserTypes ?? [],
4298
- ...info.Events.flatMap((event) => event.UserTypes ?? []),
4299
- ...list.flatMap((ticket) => ticket.UserTypes ?? [])
4300
- ];
4301
- const organisation = info.Events[0]?.Organisation;
4302
- const theme = info.Series?.Theme ?? info.Events[0]?.Theme;
4303
- const artwork = runArtwork(
4304
- info.Series,
4305
- info.Events,
4306
- ENVIRONMENT_URLS[environment].artworkUrl
4307
- );
4308
- if (artwork === void 0 && theme !== void 0 && typeof console !== "undefined") {
4413
+ setRun({ status: "LOADING" });
4414
+ const load = async () => readRun(
4415
+ isSeries ? await client.getSeriesInfo(subjectKey, abort.signal) : await client.getEventInfo(subjectKey, abort.signal),
4416
+ environment
4417
+ );
4418
+ load().then((loaded2) => {
4419
+ if (!abort.signal.aborted) setRun({ status: "LOADED", run: loaded2 });
4420
+ }).catch((cause) => {
4421
+ if (abort.signal.aborted) return;
4422
+ if (typeof console !== "undefined") {
4309
4423
  console.warn(
4310
- "[ScopeTicketsCheckout] no cart artwork resolved from this run\u2019s Theme. Expected a url in `Theme.Backgrounds[0]`. The Theme as it arrived:",
4311
- theme
4424
+ `[ScopeTicketsCheckout] could not load ${isSeries ? "series" : "event"} '${subjectKey}' from ${environment} (${ENVIRONMENT_URLS[environment].apiUrl}). If the key is right, check \`source.environment\` \u2014 it defaults to production.`,
4425
+ cause
4312
4426
  );
4313
4427
  }
4314
- return {
4315
- schedule: {
4316
- series: { events },
4317
- today,
4318
- nowTime: timeOfDayInZone(now, timeZone),
4319
- slotsByDay
4320
- },
4321
- userTypes: groupUserTypes(assignments),
4322
- userTypeNames: userTypeNames(assignments),
4323
- /*
4324
- * THE QUESTIONS RIDE ON THE TICKETS, so they arrive with the slots and cost no
4325
- * request of their own. `getQuestionnaireQuestions` wants a cart's event id, which
4326
- * does not exist yet at the step that has to know whether to ask.
4327
- */
4328
- questions: [...new Map(questions.map((q) => [q.QuestionId, q])).values()],
4329
- /*
4330
- * WHOSE EVENT IT IS. There is no follow endpoint and there does not need to be:
4331
- * the organisation is on every event, and it is who a buyer would want to hear
4332
- * from again.
4333
- *
4334
- * NOT THE VENUE, though the event names one. A venue hosts whatever is booked
4335
- * into it — following one subscribes a buyer to every unrelated thing that happens
4336
- * in a building, which is not what "stay up to date" offered them. The organiser
4337
- * is the party whose next event resembles this one.
4338
- */
4339
- follow: [
4340
- organisation === void 0 ? null : { key: organisation.Key, name: organisation.Name, kind: "Organiser" }
4341
- ].filter((entity) => entity !== null),
4342
- /*
4343
- * `Backgrounds[0]`, made absolute against the CDN, the run's before a night's — see
4344
- * `runArtwork`. The platform answers with site-root paths, so the origin is the
4345
- * whole of the work: without it every thumbnail points at the customer's own domain.
4346
- */
4347
- artwork,
4348
- eventKeyByDay,
4349
- hasTimeslots,
4350
- limits: ticketLimits(list),
4351
- ticketsError,
4352
- /* Most specific first — a product's own, then its event's, then the run's. */
4353
- currency: productCurrency ?? info.Events[0]?.Currency ?? info.Series?.Currency ?? void 0
4354
- };
4428
+ setRun({
4429
+ status: "ERROR",
4430
+ error: cause instanceof Error ? cause : new Error(String(cause))
4431
+ });
4432
+ });
4433
+ return () => abort.abort();
4434
+ }, [client, subjectKey, isSeries, enabled, environment]);
4435
+ const loaded = run.status === "LOADED" ? run.run : void 0;
4436
+ const wanted = useMemo3(() => {
4437
+ if (loaded === void 0) return null;
4438
+ if (day !== void 0 && day in loaded.eventKeyByDay) return day;
4439
+ return soonestRelevantDay({ events: loaded.events }, dayInZone(/* @__PURE__ */ new Date(), loaded.timeZone));
4440
+ }, [loaded, day]);
4441
+ useEffect4(() => {
4442
+ if (!enabled || client === null || loaded === void 0) return;
4443
+ const abort = new AbortController();
4444
+ const now = /* @__PURE__ */ new Date();
4445
+ const asked = {
4446
+ run: loaded,
4447
+ wanted,
4448
+ today: dayInZone(now, loaded.timeZone),
4449
+ nowTime: timeOfDayInZone(now, loaded.timeZone)
4355
4450
  };
4356
- load().then(({ ticketsError, ...loaded }) => {
4451
+ const eventKey = wanted === null ? void 0 : loaded.eventKeyByDay[wanted];
4452
+ if (eventKey === void 0) {
4453
+ setSessions({ status: "SETTLED", day: { ...asked, tickets: [], error: null } });
4454
+ return;
4455
+ }
4456
+ setSessions((was) => ({
4457
+ status: "LOADING",
4458
+ previous: was.status === "SETTLED" ? was.day : was.status === "LOADING" ? was.previous : void 0
4459
+ }));
4460
+ client.getTicketInformation(
4461
+ { events: [eventKey], includeTimeslots: true, includeQuestions: true },
4462
+ abort.signal
4463
+ ).then((tickets) => {
4357
4464
  if (abort.signal.aborted) return;
4358
- if (ticketsError !== null && typeof console !== "undefined") {
4359
- console.warn(
4360
- "[ScopeTicketsCheckout] could not load tickets for this day; sessions, questions and user types will be missing.",
4361
- ticketsError
4362
- );
4363
- }
4364
- setData({ ...loaded, loading: false, error: ticketsError });
4465
+ setSessions({ status: "SETTLED", day: { ...asked, tickets, error: null } });
4365
4466
  }).catch((cause) => {
4366
4467
  if (abort.signal.aborted) return;
4468
+ const error = cause instanceof Error ? cause : new Error(String(cause));
4367
4469
  if (typeof console !== "undefined") {
4368
4470
  console.warn(
4369
- `[ScopeTicketsCheckout] could not load ${isSeries ? "series" : "event"} '${subjectKey}' from ${environment} (${ENVIRONMENT_URLS[environment].apiUrl}). If the key is right, check \`source.environment\` \u2014 it defaults to production.`,
4370
- cause
4471
+ "[ScopeTicketsCheckout] could not load tickets for this day; sessions, questions and user types will be missing.",
4472
+ error
4371
4473
  );
4372
4474
  }
4373
- setData({
4374
- ...NOTHING,
4375
- error: cause instanceof Error ? cause : new Error(String(cause))
4376
- });
4475
+ setSessions({ status: "SETTLED", day: { ...asked, tickets: [], error } });
4377
4476
  });
4378
4477
  return () => abort.abort();
4379
- }, [client, subjectKey, isSeries, enabled, day, environment]);
4380
- return enabled ? data : NOTHING;
4478
+ }, [client, enabled, loaded, wanted]);
4479
+ return useMemo3(() => {
4480
+ if (!enabled) return NOTHING;
4481
+ switch (run.status) {
4482
+ case "IDLE":
4483
+ return NOTHING;
4484
+ case "LOADING":
4485
+ return { ...NOTHING, loading: true };
4486
+ case "ERROR":
4487
+ return { ...NOTHING, error: run.error };
4488
+ case "LOADED": {
4489
+ const shown = sessions.status === "SETTLED" ? sessions.day : sessions.status === "LOADING" ? sessions.previous : void 0;
4490
+ if (shown === void 0 || shown.run !== run.run) return { ...NOTHING, loading: true };
4491
+ return composed(shown, sessions.status === "LOADING");
4492
+ }
4493
+ default: {
4494
+ const exhaustive = run;
4495
+ return exhaustive;
4496
+ }
4497
+ }
4498
+ }, [enabled, run, sessions]);
4381
4499
  }
4382
4500
 
4383
4501
  // src/data/useAccountGateway.ts
@@ -5578,6 +5696,171 @@ function productForSession(tickets, session) {
5578
5696
  return sells.find((ticket) => ticket.Available) ?? sells[0];
5579
5697
  }
5580
5698
 
5699
+ // src/domain/questionnaire.ts
5700
+ var AGREED = "true";
5701
+ var NOT_AGREED = "false";
5702
+ function questionType(type) {
5703
+ switch (type.trim().toLowerCase()) {
5704
+ case "text":
5705
+ return "TEXT";
5706
+ case "boolean":
5707
+ return "AGREEMENT";
5708
+ case "integer":
5709
+ return "INTEGER";
5710
+ default:
5711
+ return null;
5712
+ }
5713
+ }
5714
+ function questionKind(question) {
5715
+ const type = questionType(question.Type);
5716
+ switch (type) {
5717
+ case "TEXT":
5718
+ return "TEXT";
5719
+ case "AGREEMENT":
5720
+ return "AGREEMENT";
5721
+ case "INTEGER":
5722
+ return "INTEGER";
5723
+ // Unknown types are asked as text rather than dropped.
5724
+ case null:
5725
+ return "TEXT";
5726
+ default: {
5727
+ const exhaustive = type;
5728
+ return exhaustive;
5729
+ }
5730
+ }
5731
+ }
5732
+ function questionAnswered(kind, value) {
5733
+ switch (kind) {
5734
+ case "TEXT":
5735
+ return (value ?? "").trim().length > 0;
5736
+ case "AGREEMENT":
5737
+ return value === AGREED;
5738
+ case "INTEGER":
5739
+ return wholeNumber(value) !== null;
5740
+ default: {
5741
+ const exhaustive = kind;
5742
+ return exhaustive;
5743
+ }
5744
+ }
5745
+ }
5746
+ function wholeNumber(value) {
5747
+ const text = (value ?? "").trim();
5748
+ if (!/^[+-]?\d{1,10}$/.test(text)) return null;
5749
+ const parsed = Number(text);
5750
+ return parsed >= -2147483648 && parsed <= 2147483647 ? text : null;
5751
+ }
5752
+ function questionsAnswered(questions, answers) {
5753
+ return questions.every(
5754
+ (question) => questionAnswered(questionKind(question), answers[String(question.QuestionId)])
5755
+ );
5756
+ }
5757
+ var MAX_ANSWER_LENGTH = 200;
5758
+ var QUESTION_KEY = /^\d{1,12}$/;
5759
+ function hostAnswers(raw) {
5760
+ if (raw === null || typeof raw !== "object") return {};
5761
+ const kept = {};
5762
+ for (const [key, value] of Object.entries(raw)) {
5763
+ if (!QUESTION_KEY.test(key) || typeof value !== "string") continue;
5764
+ const answer = value.trim();
5765
+ if (answer.length > MAX_ANSWER_LENGTH) continue;
5766
+ kept[key] = answer;
5767
+ }
5768
+ return kept;
5769
+ }
5770
+ function responsesFor(items, questions, answers) {
5771
+ const values = [];
5772
+ for (const question of questions) {
5773
+ const value = answers[String(question.QuestionId)];
5774
+ const kind = questionKind(question);
5775
+ switch (kind) {
5776
+ case "TEXT": {
5777
+ const text = (value ?? "").trim();
5778
+ if (text.length > 0 && text.length <= MAX_ANSWER_LENGTH) {
5779
+ values.push({ QuestionId: question.QuestionId, Value: text });
5780
+ }
5781
+ break;
5782
+ }
5783
+ case "AGREEMENT":
5784
+ if (value === AGREED || value === NOT_AGREED) {
5785
+ values.push({ QuestionId: question.QuestionId, Value: value });
5786
+ }
5787
+ break;
5788
+ case "INTEGER": {
5789
+ const number = wholeNumber(value);
5790
+ if (number !== null) values.push({ QuestionId: question.QuestionId, Value: number });
5791
+ break;
5792
+ }
5793
+ default: {
5794
+ const exhaustive = kind;
5795
+ return exhaustive;
5796
+ }
5797
+ }
5798
+ }
5799
+ if (values.length === 0) return [];
5800
+ return items.map((item) => ({
5801
+ ItemKey: item.Key,
5802
+ Values: values.map((entry) => ({ ...entry }))
5803
+ }));
5804
+ }
5805
+ function answersLocked(save) {
5806
+ switch (save.status) {
5807
+ case "IDLE":
5808
+ return false;
5809
+ case "SAVING":
5810
+ case "SAVED":
5811
+ return true;
5812
+ case "FAILED":
5813
+ return save.partly;
5814
+ default: {
5815
+ const exhaustive = save;
5816
+ return exhaustive;
5817
+ }
5818
+ }
5819
+ }
5820
+ var MAX_QUESTION_TEXT = 1e3;
5821
+ var MAX_QUESTION_TYPE = 40;
5822
+ function guardQuestions(raw) {
5823
+ if (!Array.isArray(raw)) return [];
5824
+ return raw.flatMap((entry) => {
5825
+ if (entry === null || typeof entry !== "object") return [];
5826
+ const { QuestionId, Question, Type } = entry;
5827
+ if (typeof QuestionId !== "number" || !Number.isSafeInteger(QuestionId)) return [];
5828
+ if (typeof Question !== "string" || Question.trim() === "") return [];
5829
+ if (Question.length > MAX_QUESTION_TEXT) return [];
5830
+ if (typeof Type !== "string" || Type.length > MAX_QUESTION_TYPE) return [];
5831
+ return [{ QuestionId, Question, Type }];
5832
+ });
5833
+ }
5834
+ function mergeQuestions(eventQuestions, ticketQuestions) {
5835
+ const seen = /* @__PURE__ */ new Set();
5836
+ const merged = [];
5837
+ for (const question of [...eventQuestions, ...ticketQuestions]) {
5838
+ if (seen.has(question.QuestionId)) continue;
5839
+ seen.add(question.QuestionId);
5840
+ merged.push(question);
5841
+ }
5842
+ return merged;
5843
+ }
5844
+ function questionsInHand(ticketQuestions, load, hasCart) {
5845
+ if (!hasCart) return { status: "READY", questions: guardQuestions(ticketQuestions) };
5846
+ switch (load.status) {
5847
+ case "IDLE":
5848
+ case "LOADING":
5849
+ return { status: "PENDING" };
5850
+ case "LOADED":
5851
+ return {
5852
+ status: "READY",
5853
+ questions: mergeQuestions(load.questions, guardQuestions(ticketQuestions))
5854
+ };
5855
+ case "FAILED":
5856
+ return { status: "FAILED" };
5857
+ default: {
5858
+ const exhaustive = load;
5859
+ return exhaustive;
5860
+ }
5861
+ }
5862
+ }
5863
+
5581
5864
  // src/domain/promo.ts
5582
5865
  function promoSaved(cart, currency) {
5583
5866
  if (currency === void 0) return null;
@@ -5605,8 +5888,23 @@ var IDLE = {
5605
5888
  items: [],
5606
5889
  currency: void 0,
5607
5890
  productName: void 0,
5608
- payment: void 0
5891
+ payment: void 0,
5892
+ answers: { status: "IDLE" },
5893
+ eventQuestions: { status: "IDLE" }
5609
5894
  };
5895
+ async function eventQuestionsFor(client, cart) {
5896
+ if (client === null) return { status: "IDLE" };
5897
+ if (typeof cart.EventId !== "number")
5898
+ return { status: "FAILED", reason: "The cart names no event" };
5899
+ try {
5900
+ return {
5901
+ status: "LOADED",
5902
+ questions: guardQuestions(await client.getQuestionnaireQuestions(cart.EventId))
5903
+ };
5904
+ } catch (cause) {
5905
+ return { status: "FAILED", reason: cause instanceof Error ? cause.message : String(cause) };
5906
+ }
5907
+ }
5610
5908
  var POLL_MS = 2e3;
5611
5909
  function toQuote(cart, currency) {
5612
5910
  if (currency === void 0) return void 0;
@@ -5689,7 +5987,7 @@ function useCheckoutOrder(client, request, currency, open, adopt, userTypeNames2
5689
5987
  const cart = withExpiry(await client.createCart(mark), opening);
5690
5988
  held.current = opening;
5691
5989
  asking = `reading the tickets on '${mark}'`;
5692
- const tickets = await client.getEventTickets(mark);
5990
+ const tickets = await client.getTicketInformation({ events: [mark], includeTimeslots: true });
5693
5991
  const asked = safeParse(timeslot, null) ?? void 0;
5694
5992
  const session = sessionFor(tickets, asked);
5695
5993
  const product = productForSession(tickets, session);
@@ -5739,9 +6037,18 @@ function useCheckoutOrder(client, request, currency, open, adopt, userTypeNames2
5739
6037
  productName: product.Name
5740
6038
  };
5741
6039
  };
5742
- load().then(({ cart, items, fill, currency: filled2, productName }) => {
6040
+ load().then(async ({ cart, items, fill, currency: filled2, productName }) => {
6041
+ const eventQuestions = await eventQuestionsFor(client, cart);
5743
6042
  if (!live) return;
5744
- setState((was) => ({ ...was, cart, items, fill, currency: filled2, productName }));
6043
+ setState((was) => ({
6044
+ ...was,
6045
+ cart,
6046
+ items,
6047
+ fill,
6048
+ currency: filled2,
6049
+ productName,
6050
+ eventQuestions
6051
+ }));
5745
6052
  }).catch((cause) => {
5746
6053
  if (!live) return;
5747
6054
  opened.current = null;
@@ -5814,6 +6121,44 @@ function useCheckoutOrder(client, request, currency, open, adopt, userTypeNames2
5814
6121
  },
5815
6122
  [client, state.cart?.Key]
5816
6123
  );
6124
+ const savedAnswers = useRef12(null);
6125
+ const saveAnswers = useCallback11(
6126
+ async (questions, answers) => {
6127
+ const cartKey = state.cart?.Key;
6128
+ if (client === null || cartKey === void 0) return false;
6129
+ const was = savedAnswers.current;
6130
+ const landed = was !== null && was.cartKey === cartKey && was.items.size > 0 ? was : null;
6131
+ const requests = landed === null ? responsesFor(state.items, questions, answers) : state.items.map((item) => ({
6132
+ ItemKey: item.Key,
6133
+ Values: landed.values.map((value) => ({ ...value }))
6134
+ }));
6135
+ if (requests.length === 0) return true;
6136
+ const saved = landed?.items ?? /* @__PURE__ */ new Set();
6137
+ savedAnswers.current = { cartKey, values: requests[0]?.Values ?? [], items: saved };
6138
+ const unsent = requests.filter((request2) => !saved.has(request2.ItemKey));
6139
+ if (unsent.length === 0) return true;
6140
+ setState((held2) => ({ ...held2, answers: { status: "SAVING" } }));
6141
+ for (const request2 of unsent) {
6142
+ try {
6143
+ await client.submitQuestionnaireResponses(cartKey, request2);
6144
+ saved.add(request2.ItemKey);
6145
+ } catch (cause) {
6146
+ setState((held2) => ({
6147
+ ...held2,
6148
+ answers: {
6149
+ status: "FAILED",
6150
+ reason: cause instanceof Error ? cause.message : String(cause),
6151
+ partly: saved.size > 0
6152
+ }
6153
+ }));
6154
+ return false;
6155
+ }
6156
+ }
6157
+ setState((held2) => ({ ...held2, answers: { status: "SAVED" } }));
6158
+ return true;
6159
+ },
6160
+ [client, state.cart?.Key, state.items]
6161
+ );
5817
6162
  const [promo, setPromo] = useState13({ status: "IDLE" });
5818
6163
  const writePromo = useCallback11(
5819
6164
  async (write) => {
@@ -5895,6 +6240,14 @@ function useCheckoutOrder(client, request, currency, open, adopt, userTypeNames2
5895
6240
  setWatching(false);
5896
6241
  setState((was) => was.payment === void 0 ? was : { ...was, payment: void 0 });
5897
6242
  }, []);
6243
+ const retryEventQuestions = useCallback11(() => {
6244
+ const cart = state.cart;
6245
+ if (cart === null) return;
6246
+ setState((was) => ({ ...was, eventQuestions: { status: "LOADING" } }));
6247
+ void eventQuestionsFor(client, cart).then(
6248
+ (eventQuestions) => setState((was) => was.cart?.Key === cart.Key ? { ...was, eventQuestions } : was)
6249
+ );
6250
+ }, [client, state.cart]);
5898
6251
  const restart = useCallback11(() => {
5899
6252
  opened.current = null;
5900
6253
  held.current = null;
@@ -5912,6 +6265,7 @@ function useCheckoutOrder(client, request, currency, open, adopt, userTypeNames2
5912
6265
  quote: state.cart === null ? void 0 : toQuote(state.cart, filled ?? currency),
5913
6266
  hold: state.cart === null ? void 0 : toHold(state.cart, Date.now(), held.current),
5914
6267
  saveBuyer,
6268
+ saveAnswers,
5915
6269
  promo,
5916
6270
  applyPromo,
5917
6271
  removePromo,
@@ -5920,7 +6274,8 @@ function useCheckoutOrder(client, request, currency, open, adopt, userTypeNames2
5920
6274
  paidWithoutFinalizing,
5921
6275
  retryPayment,
5922
6276
  chargeAttempted,
5923
- restart
6277
+ restart,
6278
+ retryEventQuestions
5924
6279
  };
5925
6280
  }
5926
6281
 
@@ -6120,6 +6475,7 @@ function TextField({
6120
6475
  placeholder,
6121
6476
  maxLength,
6122
6477
  autoFocus = false,
6478
+ readOnly = false,
6123
6479
  id,
6124
6480
  name
6125
6481
  }) {
@@ -6168,6 +6524,7 @@ function TextField({
6168
6524
  value,
6169
6525
  placeholder,
6170
6526
  maxLength,
6527
+ readOnly,
6171
6528
  onChange: (event) => {
6172
6529
  const typed = event.target.value;
6173
6530
  const before = typed.slice(0, event.target.selectionStart ?? typed.length);
@@ -6772,6 +7129,21 @@ var NOTICES = {
6772
7129
  */
6773
7130
  actions: [secondary("CLOSE", "Close")]
6774
7131
  },
7132
+ QUESTIONS_NOT_LOADED: {
7133
+ id: "QUESTIONS_NOT_LOADED",
7134
+ severity: "FAILURE",
7135
+ title: "We Could Not Load the Questions",
7136
+ subtitle: "This event asks a few questions before checkout, and they did not reach us just now.",
7137
+ actions: [confirm("RETRY", "Try Again"), secondary("CLOSE", "Close")]
7138
+ },
7139
+ ANSWERS_NOT_SAVED: {
7140
+ id: "ANSWERS_NOT_SAVED",
7141
+ severity: "FAILURE",
7142
+ title: "We Could Not Save Your Answers",
7143
+ // Every path to a charge saves the answers first, so nothing has been charged.
7144
+ subtitle: "Your answers did not reach us just now. Nothing has been charged.",
7145
+ actions: [confirm("RETRY", "Try Again"), secondary("CLOSE", "Close")]
7146
+ },
6775
7147
  /*
6776
7148
  * THE COUNTERPART OF THE CHARGE PROMISE, and the reason both of these say it. Before a
6777
7149
  * payment the reassurance a buyer needs is that no money moved; after one it is the
@@ -6938,6 +7310,12 @@ function raiseForSignIn(signIn2, funnel) {
6938
7310
  function raiseForFeedback(submission) {
6939
7311
  return submission.status === "FAILED" ? NOTICES.FEEDBACK_NOT_SENT : null;
6940
7312
  }
7313
+ function raiseForQuestions(load) {
7314
+ return load.status === "FAILED" ? NOTICES.QUESTIONS_NOT_LOADED : null;
7315
+ }
7316
+ function raiseForAnswers(answers) {
7317
+ return answers.status === "FAILED" ? NOTICES.ANSWERS_NOT_SAVED : null;
7318
+ }
6941
7319
  function noticeTelemetry(severity) {
6942
7320
  return severity === "WARNING" ? "BREADCRUMB" : "EXCEPTION";
6943
7321
  }
@@ -8085,6 +8463,7 @@ var SIGN_IN_FUNNEL_CARD = {
8085
8463
  * still running, unlike the design.
8086
8464
  */
8087
8465
  };
8466
+ var DETAILS_SAVED_SUBTITLE = "Your answers are saved with this order and can no longer be changed.";
8088
8467
 
8089
8468
  // src/island/island-hero.tsx
8090
8469
  var HERO_TRANSITION_KEY = "checkout:hero";
@@ -8226,7 +8605,7 @@ async function read(client, subject, day) {
8226
8605
  if (client === null || subject === void 0) return NOTHING2;
8227
8606
  const eventKey = await eventKeyFor(client, subject, day);
8228
8607
  if (eventKey === null) return NOTHING2;
8229
- const tickets = await client.getEventTickets(eventKey);
8608
+ const tickets = await client.getTicketInformation({ events: [eventKey], includeQuestions: true });
8230
8609
  return {
8231
8610
  sellsSessions: tickets.some((ticket) => ticket.HasTimeslot),
8232
8611
  asksQuestions: tickets.some((ticket) => (ticket.Questions ?? []).length > 0)
@@ -8255,6 +8634,7 @@ function RestingIsland({
8255
8634
  initialPresentation = "card",
8256
8635
  mode = "system",
8257
8636
  align = "bottom",
8637
+ placement = "page",
8258
8638
  simulate = false,
8259
8639
  onCheckOut
8260
8640
  }) {
@@ -8350,6 +8730,7 @@ function RestingIsland({
8350
8730
  {
8351
8731
  mode,
8352
8732
  align,
8733
+ placement,
8353
8734
  contentKey: `IDLE:NOTICE:${notice.id}`,
8354
8735
  avatar: /* @__PURE__ */ jsx27(
8355
8736
  Avatar2,
@@ -8371,6 +8752,7 @@ function RestingIsland({
8371
8752
  {
8372
8753
  mode,
8373
8754
  align,
8755
+ placement,
8374
8756
  contentKey: "IDLE:FUNNEL",
8375
8757
  avatar: hero,
8376
8758
  ...funnelViewProps(funnel.state, {
@@ -8388,6 +8770,7 @@ function RestingIsland({
8388
8770
  {
8389
8771
  mode,
8390
8772
  align,
8773
+ placement,
8391
8774
  expanded,
8392
8775
  contentKey: "IDLE:CART",
8393
8776
  onToggle: toggle,
@@ -8418,6 +8801,7 @@ function RestingIsland({
8418
8801
  {
8419
8802
  mode,
8420
8803
  align,
8804
+ placement,
8421
8805
  expanded,
8422
8806
  contentKey: `IDLE:${prompt.card}`,
8423
8807
  onToggle: toggle,
@@ -9096,7 +9480,8 @@ function BookingIsland({
9096
9480
  walletBadge,
9097
9481
  initialPresentation = "card",
9098
9482
  mode = "system",
9099
- align = "bottom"
9483
+ align = "bottom",
9484
+ placement = "page"
9100
9485
  }) {
9101
9486
  const [expanded, setExpanded] = useState21(initialPresentation === "card");
9102
9487
  const [screen, setScreen] = useState21({ kind: "BOOKING" });
@@ -9175,7 +9560,7 @@ function BookingIsland({
9175
9560
  },
9176
9561
  [booking, commitHolder, retryable]
9177
9562
  );
9178
- const common = { mode, align, expanded, onToggle: onDismiss };
9563
+ const common = { mode, align, placement, expanded, onToggle: onDismiss };
9179
9564
  if (notice !== null) {
9180
9565
  return /* @__PURE__ */ jsx33(
9181
9566
  CheckoutIsland,
@@ -9962,7 +10347,8 @@ function ScopeTicketsCheckout({
9962
10347
  buyerAvatar: buyerAvatarValue(auth.session.auth),
9963
10348
  buyerAvatarAssets: avatarAssetsFor(defaultProfilePhotos(props.source?.environment)),
9964
10349
  mode: props.mode,
9965
- align: props.align
10350
+ align: props.align,
10351
+ placement: props.placement
9966
10352
  }
9967
10353
  ) : (
9968
10354
  /* Nothing to sell, so nothing to check out: the account card, and no cart face. */
@@ -9996,8 +10382,10 @@ function PurchaseIsland({
9996
10382
  simulate = false,
9997
10383
  onCommit,
9998
10384
  initialPresentation = "card",
10385
+ openingLabel,
9999
10386
  mode = "system",
10000
10387
  align = "bottom",
10388
+ placement = "page",
10001
10389
  opensAt,
10002
10390
  onPlaced
10003
10391
  }) {
@@ -10061,7 +10449,16 @@ function PurchaseIsland({
10061
10449
  [userTypes, fetched.userTypes, partyAsking]
10062
10450
  );
10063
10451
  const standing = useMemo11(() => foldIntent(intent, collected), [intent, collected]);
10452
+ const [walkQuestionnaire, setWalkQuestionnaire] = useState23({ hasCart: false, load: { status: "IDLE" } });
10453
+ const walkQuestions = useMemo11(
10454
+ () => questionsInHand(fetched.questions, walkQuestionnaire.load, walkQuestionnaire.hasCart),
10455
+ [fetched.questions, walkQuestionnaire]
10456
+ );
10064
10457
  const orderedBuyer = useMemo11(() => orderBuyer(standing, session.auth), [standing, session.auth]);
10458
+ const answersInHand = useMemo11(
10459
+ () => ({ ...hostAnswers(intent?.answers), ...collected.answers }),
10460
+ [intent?.answers, collected.answers]
10461
+ );
10065
10462
  const situation = useMemo11(
10066
10463
  () => ({
10067
10464
  name: "The host composes what it holds",
@@ -10082,12 +10479,13 @@ function PurchaseIsland({
10082
10479
  */
10083
10480
  excused: [
10084
10481
  ...excusedByIntent(
10085
- /*
10086
- * WHAT THE EVENT ACTUALLY ASKS, where the platform said. `asksQuestions` is a
10087
- * host's claim; the tickets carry the questions, so a run that asks none excuses
10088
- * the step without anybody having to remember to say so.
10089
- */
10090
- fetched.questions.length > 0 ? { ...intent, asksQuestions: true } : intent
10482
+ // Unknown or failed questions keep the step.
10483
+ walkQuestions.status !== "READY" || walkQuestions.questions.length > 0 ? {
10484
+ ...intent,
10485
+ asksQuestions: true,
10486
+ // Host answers skip the step only if they cover every question.
10487
+ answers: walkQuestions.status === "READY" && !questionsAnswered(walkQuestions.questions, hostAnswers(intent.answers)) ? void 0 : intent.answers
10488
+ } : intent
10091
10489
  ),
10092
10490
  /*
10093
10491
  * AND A RUN THAT SELLS NO SESSIONS IS NOT ASKED FOR ONE. `HasTimeslot` is the
@@ -10108,7 +10506,7 @@ function PurchaseIsland({
10108
10506
  savedPaymentMethod: intent.paymentMethodKey !== void 0,
10109
10507
  devicePasskey: false
10110
10508
  }),
10111
- [intent, fetched.questions.length, fetched.hasTimeslots, photos.length]
10509
+ [intent, walkQuestions, fetched.hasTimeslots, photos.length]
10112
10510
  );
10113
10511
  const [accountChosen, setAccountChosen] = useState23(false);
10114
10512
  const [passwordRevealed, setPasswordRevealed] = useState23(false);
@@ -10214,6 +10612,19 @@ function PurchaseIsland({
10214
10612
  */
10215
10613
  userTypeNames2
10216
10614
  );
10615
+ const questionnaire = useMemo11(
10616
+ () => questionsInHand(fetched.questions, order.eventQuestions, order.cart !== null),
10617
+ [fetched.questions, order.eventQuestions, order.cart]
10618
+ );
10619
+ const answersReady = questionnaire.status === "READY" && questionsAnswered(questionnaire.questions, answersInHand);
10620
+ const answersSaved = answersLocked(order.answers);
10621
+ useEffect18(() => {
10622
+ setWalkQuestionnaire({ hasCart: order.cart !== null, load: order.eventQuestions });
10623
+ }, [order.cart, order.eventQuestions]);
10624
+ const saveForCharge = useCallback18(
10625
+ () => questionnaire.status !== "READY" || !answersReady ? Promise.resolve(false) : order.saveAnswers(questionnaire.questions, answersInHand).then((saved) => saved && order.saveBuyer(buyerDetails(orderedBuyer))),
10626
+ [order, questionnaire, answersReady, answersInHand, orderedBuyer]
10627
+ );
10217
10628
  useEffect18(() => {
10218
10629
  if (order.fill.status !== "FAILED" || typeof console === "undefined") return;
10219
10630
  console.warn(
@@ -10287,6 +10698,11 @@ function PurchaseIsland({
10287
10698
  const index = Math.min(Math.max(from, floor), last);
10288
10699
  const walked = walk.stops[index]?.step ?? "REVIEW";
10289
10700
  const stepId = detour ?? (outcome?.kind === "FAILED" ? "PAYMENT_FAILED" : walked);
10701
+ useEffect18(() => {
10702
+ if (questionnaire.status !== "READY" || answersReady || floor > 0) return;
10703
+ const details = walk.stops.findIndex((stop) => stop.step === "DETAILS");
10704
+ if (details !== -1 && from > details) setAt("DETAILS");
10705
+ }, [questionnaire.status, answersReady, floor, walk.stops, from]);
10290
10706
  const passkeyRegistration = usePasskeyRegistration(accounts, stepId === "PASSKEY");
10291
10707
  const step = purchaseStep(stepId);
10292
10708
  const ratedTicket = outcome?.kind === "PLACED" ? outcome.attendeeTicketKey : void 0;
@@ -10348,7 +10764,7 @@ function PurchaseIsland({
10348
10764
  setRevolutCart(key);
10349
10765
  setSavedRevolutCart(null);
10350
10766
  }
10351
- void order.saveBuyer(buyerDetails(orderedBuyer)).then((saved) => {
10767
+ void saveForCharge().then((saved) => {
10352
10768
  if (!saved || selectionRequest.current !== request) return;
10353
10769
  if (wallet) setSavedWalletCart(key);
10354
10770
  else setSavedRevolutCart(key);
@@ -10367,7 +10783,7 @@ function PurchaseIsland({
10367
10783
  const funnel = useAuthFunnel(signIns, auth);
10368
10784
  useSessionGuard(client, auth);
10369
10785
  const raised = useMemo11(
10370
- () => raiseFor(order.fill) ?? raiseForAccount(accountFlow.progress, accountFlow.outcome) ?? raiseForSignIn(signIn2.state, funnel.state) ?? /*
10786
+ () => raiseFor(order.fill) ?? raiseForQuestions(order.eventQuestions) ?? raiseForAnswers(order.answers) ?? raiseForAccount(accountFlow.progress, accountFlow.outcome) ?? raiseForSignIn(signIn2.state, funnel.state) ?? /*
10371
10787
  * THE RATING LAST, because it is the least of them. Everything above is about the
10372
10788
  * order or the way into an account; a rating that did not send is news about a
10373
10789
  * courtesy, and a buyer holding both should be told about the one that matters.
@@ -10375,6 +10791,8 @@ function PurchaseIsland({
10375
10791
  raiseForFeedback(feedback.submission),
10376
10792
  [
10377
10793
  order.fill,
10794
+ order.eventQuestions,
10795
+ order.answers,
10378
10796
  accountFlow.progress,
10379
10797
  accountFlow.outcome,
10380
10798
  signIn2.state,
@@ -10394,6 +10812,15 @@ function PurchaseIsland({
10394
10812
  if (raised?.id === "SIGN_IN_NOT_COMPLETED") signIn2.retry();
10395
10813
  if (raised?.id === "SIGN_IN_UNREACHABLE") funnel.open(standing.buyer?.email ?? "");
10396
10814
  if (raised?.id === "FEEDBACK_NOT_SENT") feedback.retry();
10815
+ if (raised?.id === "QUESTIONS_NOT_LOADED") order.retryEventQuestions();
10816
+ if (raised?.id === "ANSWERS_NOT_SAVED") {
10817
+ const key = order.cart?.Key;
10818
+ void saveForCharge().then((saved) => {
10819
+ if (!saved || key === void 0) return;
10820
+ setSavedRevolutCart(key);
10821
+ setSavedWalletCart(key);
10822
+ });
10823
+ }
10397
10824
  if (raised?.id === "ACCOUNT_NOT_CREATED") {
10398
10825
  accountFlow.create(
10399
10826
  {
@@ -10417,7 +10844,9 @@ function PurchaseIsland({
10417
10844
  collected.firstName,
10418
10845
  collected.lastName,
10419
10846
  collected.phone,
10420
- walk.stops
10847
+ walk.stops,
10848
+ saveForCharge,
10849
+ order
10421
10850
  ]
10422
10851
  );
10423
10852
  const forward = useCallback18(() => {
@@ -10593,7 +11022,7 @@ function PurchaseIsland({
10593
11022
  }
10594
11023
  if (action.pays === true) {
10595
11024
  return () => {
10596
- void order.saveBuyer(buyerDetails(orderedBuyer)).then((saved) => {
11025
+ void saveForCharge().then((saved) => {
10597
11026
  if (!saved) return;
10598
11027
  setSubmitSignal((was) => was + 1);
10599
11028
  });
@@ -10613,7 +11042,7 @@ function PurchaseIsland({
10613
11042
  detour,
10614
11043
  forward,
10615
11044
  order,
10616
- orderedBuyer,
11045
+ saveForCharge,
10617
11046
  walletCharging,
10618
11047
  /* The funnel's prefill is the address TYPED, not the order's — see its press below. */
10619
11048
  standing.buyer?.email,
@@ -10853,16 +11282,16 @@ function PurchaseIsland({
10853
11282
  };
10854
11283
  useEffect18(() => {
10855
11284
  const key = order.cart?.Key;
10856
- if (stepId !== "REVIEW" || key === void 0 || revolutCart === key) return;
11285
+ if (stepId !== "REVIEW" || key === void 0 || revolutCart === key || !answersReady) return;
10857
11286
  setRevolutCart(key);
10858
11287
  setWalletCart(key);
10859
11288
  const request = ++selectionRequest.current;
10860
- void order.saveBuyer(buyerDetails(orderedBuyer)).then((saved) => {
11289
+ void saveForCharge().then((saved) => {
10861
11290
  if (!saved || selectionRequest.current !== request) return;
10862
11291
  setSavedRevolutCart(key);
10863
11292
  setSavedWalletCart(key);
10864
11293
  });
10865
- }, [stepId, order.cart?.Key, revolutCart]);
11294
+ }, [stepId, order.cart?.Key, revolutCart, answersReady]);
10866
11295
  const [cardStatus, setCardStatus] = useState23(null);
10867
11296
  const checkoutSessionId = useMemo11(() => crypto.randomUUID(), [order.cart?.Key]);
10868
11297
  const payEntries = frameMounted ? /* @__PURE__ */ jsxs25(Fragment3, { children: [
@@ -11000,6 +11429,7 @@ function PurchaseIsland({
11000
11429
  {
11001
11430
  mode,
11002
11431
  align,
11432
+ placement,
11003
11433
  contentKey: `NOTICE:${notice.id}`,
11004
11434
  avatar: /* @__PURE__ */ jsx35(
11005
11435
  Avatar4,
@@ -11021,6 +11451,7 @@ function PurchaseIsland({
11021
11451
  {
11022
11452
  mode,
11023
11453
  align,
11454
+ placement,
11024
11455
  contentKey: "CART",
11025
11456
  bay,
11026
11457
  bayVisible: false,
@@ -11056,6 +11487,7 @@ function PurchaseIsland({
11056
11487
  {
11057
11488
  mode,
11058
11489
  align,
11490
+ placement,
11059
11491
  contentKey: "FUNNEL",
11060
11492
  avatar: /* @__PURE__ */ jsx35(
11061
11493
  Avatar4,
@@ -11080,6 +11512,7 @@ function PurchaseIsland({
11080
11512
  {
11081
11513
  mode,
11082
11514
  align,
11515
+ placement,
11083
11516
  contentKey: "HOLD_TIMED_OUT",
11084
11517
  avatar: /* @__PURE__ */ jsx35(
11085
11518
  Avatar4,
@@ -11135,7 +11568,8 @@ function PurchaseIsland({
11135
11568
  schedule: drawnSchedule,
11136
11569
  onPartyRefused: setPartyRefused,
11137
11570
  partyRefused,
11138
- questions: fetched.questions,
11571
+ questions: questionnaire.status === "READY" ? questionnaire.questions : [],
11572
+ answersLocked: answersSaved,
11139
11573
  follow: fetched.follow,
11140
11574
  buyerEmail: standing.buyer?.email,
11141
11575
  scheduleDay: chosenDay,
@@ -11215,7 +11649,7 @@ function PurchaseIsland({
11215
11649
  stepId === "NAME" ? isCompleteName(
11216
11650
  standing.buyer?.firstName ?? "",
11217
11651
  standing.buyer?.lastName ?? ""
11218
- ) : stepId === "EMAIL" ? isValidEmail(collected.email) : stepId === "PHONE" ? e164(collected.phone.dialCode, collected.phone.national) !== null : input === null || answered
11652
+ ) : stepId === "EMAIL" ? isValidEmail(collected.email) : stepId === "PHONE" ? e164(collected.phone.dialCode, collected.phone.national) !== null : stepId === "DETAILS" ? questionnaire.status === "READY" && questionsAnswered(questionnaire.questions, collected.answers) : input === null || answered
11219
11653
  )
11220
11654
  )
11221
11655
  )
@@ -11246,7 +11680,7 @@ function PurchaseIsland({
11246
11680
  * checkout this is. A card with no hold has the room for it; one with a hold has
11247
11681
  * something more useful to say in the only line it has.
11248
11682
  */
11249
- stepId === "REVIEW" || stepId === "PAYMENT" ? drawnHold === void 0 ? POWERED_BY : CART_VIEW.remaining(formatHold(drawnHold)) : copy?.subtitle
11683
+ stepId === "REVIEW" || stepId === "PAYMENT" ? drawnHold === void 0 ? POWERED_BY : CART_VIEW.remaining(formatHold(drawnHold)) : stepId === "DETAILS" && answersSaved ? DETAILS_SAVED_SUBTITLE : copy?.subtitle
11250
11684
  );
11251
11685
  const lines = drawnQuote === void 0 ? null : quoteLines(drawnQuote);
11252
11686
  const title = paidRecovery ? "Payment Received" : stepId === "ACCOUNT_CREATED" ? accountCreatedTitle(accountFirstName) : stepId === "REVIEW" && lines !== null ? `Pay ${lines.headline}` : (
@@ -11391,6 +11825,7 @@ function PurchaseIsland({
11391
11825
  {
11392
11826
  mode,
11393
11827
  align,
11828
+ placement,
11394
11829
  expanded,
11395
11830
  journeyFullscreen: journeyInline && journeyFullscreen,
11396
11831
  contentKey: `${detour === null ? "" : "detour:"}${stepId}:${prompt?.kind === "CARD" ? prompt.card : ""}`,
@@ -11444,7 +11879,7 @@ function PurchaseIsland({
11444
11879
  ),
11445
11880
  pillCopy: { title: lines?.headline, subtitle: lines?.qualifier ?? void 0 },
11446
11881
  input,
11447
- actionLabel: detour === null && index === 0 ? OPENING_LABEL : step.collapsed.kind === "PILL" ? step.collapsed.actionLabel : step.name,
11882
+ actionLabel: detour === null && index === 0 ? openingLabel?.trim() || OPENING_LABEL : step.collapsed.kind === "PILL" ? step.collapsed.actionLabel : step.name,
11448
11883
  actions: toIslandActions(planeActions),
11449
11884
  bayActions: toIslandActions(bayActions)
11450
11885
  }
@@ -11463,6 +11898,7 @@ function stepInput(stepId, context) {
11463
11898
  onPartyRefused,
11464
11899
  partyRefused,
11465
11900
  questions,
11901
+ answersLocked: answersLocked2,
11466
11902
  follow,
11467
11903
  buyerEmail,
11468
11904
  buyerName: buyerName2,
@@ -11531,23 +11967,62 @@ function stepInput(stepId, context) {
11531
11967
  /*
11532
11968
  * THE EVENT'S OWN QUESTIONS. The card was a gate onto nothing: `DETAILS` had no case
11533
11969
  * here, so it drew a sentence about needing details and no way to give any. The
11534
- * questions ride on the tickets, so they are already in hand by the time this is asked.
11970
+ * questions come from the tickets and the event's questionnaire, which arrives with the
11971
+ * cart, so they are in hand by the time this is asked.
11535
11972
  */
11536
11973
  case "DETAILS":
11537
- return questions.length === 0 ? null : /* @__PURE__ */ jsx35("div", { className: "scopetickets-island-card__fields", children: questions.map((question) => /* @__PURE__ */ jsx35(
11538
- TextField,
11539
- {
11540
- label: question.Question,
11541
- value: collected.answers[String(question.QuestionId)] ?? "",
11542
- onChange: (value) => setCollected((was) => ({
11543
- ...was,
11544
- answers: { ...was.answers, [String(question.QuestionId)]: value }
11545
- })),
11546
- type: question.Type === "date" ? "text" : "text",
11547
- enterKeyHint: "done"
11548
- },
11549
- question.QuestionId
11550
- )) });
11974
+ return questions.length === 0 ? null : /* @__PURE__ */ jsx35("div", { className: "scopetickets-island-card__fields", children: questions.map((question) => {
11975
+ const key = String(question.QuestionId);
11976
+ const value = collected.answers[key];
11977
+ const answer = answersLocked2 ? void 0 : (next) => setCollected((was) => ({ ...was, answers: { ...was.answers, [key]: next } }));
11978
+ const kind = questionKind(question);
11979
+ switch (kind) {
11980
+ case "AGREEMENT":
11981
+ return /* @__PURE__ */ jsxs25("div", { className: "scopetickets-island-card__agreement", children: [
11982
+ /* @__PURE__ */ jsx35("span", { className: "scopetickets-island-card__agreement-label", children: question.Question }),
11983
+ /* @__PURE__ */ jsx35(
11984
+ Switch,
11985
+ {
11986
+ checked: value === AGREED,
11987
+ label: question.Question,
11988
+ onChange: (on) => answer?.(on ? AGREED : NOT_AGREED),
11989
+ disabled: answersLocked2
11990
+ }
11991
+ )
11992
+ ] }, question.QuestionId);
11993
+ case "INTEGER":
11994
+ return /* @__PURE__ */ jsx35(
11995
+ TextField,
11996
+ {
11997
+ label: question.Question,
11998
+ value: value ?? "",
11999
+ onChange: answer,
12000
+ inputMode: "numeric",
12001
+ maxLength: 11,
12002
+ readOnly: answersLocked2,
12003
+ enterKeyHint: "done"
12004
+ },
12005
+ question.QuestionId
12006
+ );
12007
+ case "TEXT":
12008
+ return /* @__PURE__ */ jsx35(
12009
+ TextField,
12010
+ {
12011
+ label: question.Question,
12012
+ value: value ?? "",
12013
+ onChange: answer,
12014
+ maxLength: MAX_ANSWER_LENGTH,
12015
+ readOnly: answersLocked2,
12016
+ enterKeyHint: "done"
12017
+ },
12018
+ question.QuestionId
12019
+ );
12020
+ default: {
12021
+ const exhaustive = kind;
12022
+ return exhaustive;
12023
+ }
12024
+ }
12025
+ }) });
11551
12026
  /*
11552
12027
  * WHO TO HEAR FROM AGAIN. `FollowList` was built and tested and mounted by nothing —
11553
12028
  * the organiser and the venue are on every event, and they are who a buyer would