@bowlos/reservations 0.4.0 → 0.6.0

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 (44) hide show
  1. package/README.md +25 -7
  2. package/dist/{account-COEgvwfx.d.cts → account-BRapzoNI.d.cts} +4 -1
  3. package/dist/{account-CzyIERC5.d.ts → account-VO6BzPNK.d.ts} +4 -1
  4. package/dist/{chunk-NYTGLAQH.js → chunk-H42X4FRR.js} +19 -8
  5. package/dist/chunk-H42X4FRR.js.map +1 -0
  6. package/dist/{chunk-QGTGKNJW.js → chunk-YICHFUAY.js} +41 -11
  7. package/dist/chunk-YICHFUAY.js.map +1 -0
  8. package/dist/components.cjs +144 -60
  9. package/dist/components.cjs.map +1 -1
  10. package/dist/components.d.cts +84 -7
  11. package/dist/components.d.ts +84 -7
  12. package/dist/components.js +136 -21
  13. package/dist/components.js.map +1 -1
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +1 -1
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +172 -4
  18. package/dist/index.js.map +1 -1
  19. package/dist/{react-B_8H7AyT.d.cts → react-7ruEsubp.d.cts} +5 -2
  20. package/dist/{react-bG9YV_xP.d.ts → react-Cb_NZCXa.d.ts} +5 -2
  21. package/dist/react.cjs +16 -3
  22. package/dist/react.cjs.map +1 -1
  23. package/dist/react.d.cts +6 -4
  24. package/dist/react.d.ts +6 -4
  25. package/dist/react.js +2 -3
  26. package/package.json +1 -1
  27. package/templates/center-site/app/book/page.tsx +55 -28
  28. package/templates/center-site/app/flash/page.tsx +18 -0
  29. package/templates/center-site/app/layout.tsx +5 -1
  30. package/templates/center-site/app/providers.tsx +26 -4
  31. package/templates/center-site/app/site-header.tsx +31 -0
  32. package/templates/center-site/env.example +10 -5
  33. package/templates/center-site/lib/bowlos.ts +13 -5
  34. package/templates/center-site/package.json +1 -1
  35. package/dist/chunk-2RMK6BWO.js +0 -41
  36. package/dist/chunk-2RMK6BWO.js.map +0 -1
  37. package/dist/chunk-4FL2QYSS.js +0 -174
  38. package/dist/chunk-4FL2QYSS.js.map +0 -1
  39. package/dist/chunk-NYTGLAQH.js.map +0 -1
  40. package/dist/chunk-QGTGKNJW.js.map +0 -1
  41. package/dist/cli.d.cts +0 -1
  42. package/dist/cli.d.ts +0 -1
  43. package/dist/cli.js +0 -176
  44. package/dist/cli.js.map +0 -1
@@ -92,6 +92,7 @@ var BowlosApiError = class _BowlosApiError extends Error {
92
92
  }
93
93
  };
94
94
  var BowlosContext = react.createContext(null);
95
+ var AccountContext = react.createContext(null);
95
96
  function useBowlosClient() {
96
97
  const client = react.useContext(BowlosContext);
97
98
  if (!client) {
@@ -100,49 +101,11 @@ function useBowlosClient() {
100
101
  return client;
101
102
  }
102
103
  function useAccount() {
103
- const client = useBowlosClient();
104
- const [status, setStatus] = react.useState("loading");
105
- const [customer, setCustomer] = react.useState(null);
106
- const [error, setError] = react.useState(null);
107
- const refresh = react.useCallback(async () => {
108
- try {
109
- const state = await client.probe();
110
- setStatus(state);
111
- setCustomer(state === "linked" ? await client.me() : null);
112
- setError(null);
113
- } catch (e) {
114
- setStatus("unauthenticated");
115
- setCustomer(null);
116
- if (e instanceof BowlosApiError) setError(e);
117
- }
118
- }, [client]);
119
- react.useEffect(() => {
120
- void refresh();
121
- }, [refresh]);
122
- const run = react.useCallback(
123
- async (action) => {
124
- setError(null);
125
- try {
126
- await action();
127
- await refresh();
128
- } catch (e) {
129
- if (e instanceof BowlosApiError) setError(e);
130
- throw e;
131
- }
132
- },
133
- [refresh]
134
- );
135
- const signIn = react.useCallback(
136
- (email, password) => run(() => client.signIn(email, password)),
137
- [client, run]
138
- );
139
- const signUp = react.useCallback(
140
- (email, password) => run(() => client.signUp(email, password)),
141
- [client, run]
142
- );
143
- const link = react.useCallback((profile) => run(() => client.link(profile)), [client, run]);
144
- const signOut = react.useCallback(() => run(() => client.signOut()), [client, run]);
145
- return { status, customer, error, signIn, signUp, link, signOut, refresh };
104
+ const account = react.useContext(AccountContext);
105
+ if (!account) {
106
+ throw new Error("useAccount must be used within a <BowlosProvider>.");
107
+ }
108
+ return account;
146
109
  }
147
110
  function useBowlosQuery(name, args = {}, options = {}) {
148
111
  const client = useBowlosClient();
@@ -198,6 +161,9 @@ function useMyPasses(args, options) {
198
161
  function useFlashSale(args, options) {
199
162
  return useBowlosQuery("getPublicFlashSaleBySlug", args, { ...options, auth: true });
200
163
  }
164
+ function useFlashSales(args, options) {
165
+ return useBowlosQuery("listPublicFlashSales", args, options);
166
+ }
201
167
 
202
168
  // src/data.ts
203
169
  function availableUnitCount(availability) {
@@ -568,19 +534,23 @@ var DEFAULT_LABELS = {
568
534
  quantity: "Quantity",
569
535
  name: "Name",
570
536
  email: "Email",
571
- hold: "Reserve",
572
- holding: "Reserving\u2026",
537
+ hold: "Book",
538
+ holding: "Booking\u2026",
573
539
  continueToPayment: "Continue to payment",
574
540
  preparing: "Preparing\u2026",
575
541
  cancel: "Cancel",
576
542
  releaseHold: "Release hold",
577
- heldHeading: "Reserved",
543
+ heldHeading: "Almost there",
578
544
  heldBody: "We're holding your spot for a few minutes. Continue to payment to confirm.",
545
+ securing: "Securing your spot\u2026",
579
546
  paymentHeading: "Payment",
580
547
  confirmedHeading: "You're booked",
581
548
  confirmationLabel: "Confirmation",
582
549
  bookAnother: "Book another",
583
- checkingAvailability: "Checking availability\u2026"
550
+ checkingAvailability: "Checking availability\u2026",
551
+ bookingAs: "Booking as {name}",
552
+ notYou: "Not you?",
553
+ signInHint: "Sign in to book faster"
584
554
  };
585
555
  function BookingFlow({
586
556
  centerId,
@@ -592,10 +562,16 @@ function BookingFlow({
592
562
  renderPayment,
593
563
  onConfirmed,
594
564
  unitLabel = { singular: "lane", plural: "lanes" },
565
+ completeSaleOnly = true,
566
+ accountHref,
595
567
  labels,
596
568
  className
597
569
  }) {
598
570
  const t = { ...DEFAULT_LABELS, ...labels };
571
+ const account = useAccount();
572
+ const signedIn = account.status === "linked" && account.customer !== null;
573
+ const acctName = account.customer?.fullName ?? "";
574
+ const acctEmail = account.customer?.email ?? "";
599
575
  const [dateISO, setDateISO] = react.useState(defaultDateISO);
600
576
  const [startMinuteOfDay, setStartMinuteOfDay] = react.useState(defaultStartMinuteOfDay);
601
577
  const endMinuteOfDay = startMinuteOfDay + durationMinutes;
@@ -619,6 +595,13 @@ function BookingFlow({
619
595
  onConfirmedRef.current?.(flow.reservation);
620
596
  }
621
597
  }, [flow.status, flow.reservation]);
598
+ const prepareRef = react.useRef(flow.preparePayment);
599
+ prepareRef.current = flow.preparePayment;
600
+ react.useEffect(() => {
601
+ if (completeSaleOnly && flow.status === "held") {
602
+ void prepareRef.current();
603
+ }
604
+ }, [completeSaleOnly, flow.status]);
622
605
  const bookingArgs = react.useMemo(
623
606
  () => ({
624
607
  centerId,
@@ -628,9 +611,9 @@ function BookingFlow({
628
611
  endMinuteOfDay,
629
612
  mode: pricingMode,
630
613
  units,
631
- customer: { fullName, email, marketingOptIn: false }
614
+ customer: signedIn ? { fullName: acctName, email: acctEmail, marketingOptIn: false } : { fullName, email, marketingOptIn: false }
632
615
  }),
633
- [centerId, productId, dateISO, startMinuteOfDay, endMinuteOfDay, pricingMode, units, fullName, email]
616
+ [centerId, productId, dateISO, startMinuteOfDay, endMinuteOfDay, pricingMode, units, signedIn, acctName, acctEmail, fullName, email]
634
617
  );
635
618
  const freeUnits = availability.data ? availableUnitCount(availability.data) : null;
636
619
  const quoteCents = preview.data?.totalCentsPerPlan?.[0]?.totalCents ?? null;
@@ -663,6 +646,13 @@ function BookingFlow({
663
646
  ] });
664
647
  }
665
648
  if (flow.status === "held" || flow.status === "preparingPayment") {
649
+ if (completeSaleOnly) {
650
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
651
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.heldHeading }),
652
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.body, children: t.securing }),
653
+ flow.error && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.error, children: flow.error.code })
654
+ ] });
655
+ }
666
656
  const preparing = flow.status === "preparingPayment";
667
657
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
668
658
  /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.heldHeading }),
@@ -710,19 +700,36 @@ function BookingFlow({
710
700
  }
711
701
  )
712
702
  ] }),
713
- /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
714
- t.name,
715
- /* @__PURE__ */ jsxRuntime.jsx("input", { value: fullName, onChange: (e) => setFullName(e.target.value), style: s.input, required: true })
716
- ] }),
717
- /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
718
- t.email,
719
- /* @__PURE__ */ jsxRuntime.jsx("input", { type: "email", value: email, onChange: (e) => setEmail(e.target.value), style: s.input, required: true })
703
+ signedIn ? /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.meta, children: [
704
+ t.bookingAs.replace("{name}", acctName),
705
+ accountHref ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
706
+ " \xB7 ",
707
+ /* @__PURE__ */ jsxRuntime.jsx("a", { href: accountHref, style: s.linkBtn, children: t.notYou })
708
+ ] }) : null
709
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
710
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
711
+ t.name,
712
+ /* @__PURE__ */ jsxRuntime.jsx("input", { value: fullName, onChange: (e) => setFullName(e.target.value), style: s.input, required: true })
713
+ ] }),
714
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: s.label, children: [
715
+ t.email,
716
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "email", value: email, onChange: (e) => setEmail(e.target.value), style: s.input, required: true })
717
+ ] }),
718
+ accountHref ? /* @__PURE__ */ jsxRuntime.jsx("a", { href: accountHref, style: s.linkBtn, children: t.signInHint }) : null
720
719
  ] }),
721
720
  /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.meta, "aria-live": "polite", children: [
722
721
  dateISO === "" ? "" : availability.loading ? t.checkingAvailability : freeUnits !== null ? `${freeUnits} ${freeUnits === 1 ? unitLabel.singular : unitLabel.plural} available` : availability.error ? availability.error.code : "",
723
722
  quoteCents !== null ? ` \xB7 ${formatCents(quoteCents)}` : ""
724
723
  ] }),
725
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", style: s.primaryBtn, disabled: holding || !fullName || !email || dateISO === "", children: holding ? t.holding : `${t.hold} ${unitNoun}` }),
724
+ /* @__PURE__ */ jsxRuntime.jsx(
725
+ "button",
726
+ {
727
+ type: "submit",
728
+ style: s.primaryBtn,
729
+ disabled: holding || dateISO === "" || !signedIn && (!fullName || !email),
730
+ children: holding ? t.holding : `${t.hold} ${unitNoun}`
731
+ }
732
+ ),
726
733
  flow.error && /* @__PURE__ */ jsxRuntime.jsxs("p", { style: s.error, children: [
727
734
  flow.error.code,
728
735
  " \u2014 ",
@@ -856,6 +863,35 @@ function AuthGate({ children, labels, className }) {
856
863
  return /* @__PURE__ */ jsxRuntime.jsx(AuthForm, { account, labels, className });
857
864
  }
858
865
  var DEFAULT_LABELS3 = {
866
+ signIn: "Sign in",
867
+ signOut: "Sign out",
868
+ loading: "\u2026"
869
+ };
870
+ function AccountMenu({ accountHref = "/account", labels, className }) {
871
+ const t = { ...DEFAULT_LABELS3, ...labels };
872
+ const account = useAccount();
873
+ const s = styles();
874
+ const wrap = {
875
+ display: "inline-flex",
876
+ alignItems: "center",
877
+ gap: "0.625rem",
878
+ fontFamily: token("fontFamily"),
879
+ fontSize: "0.9rem",
880
+ color: token("colorText")
881
+ };
882
+ if (account.status === "loading") {
883
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: wrap, children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.muted, children: t.loading }) });
884
+ }
885
+ if (account.status === "linked" && account.customer) {
886
+ const first = account.customer.fullName.split(" ")[0] || account.customer.fullName;
887
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className, style: wrap, children: [
888
+ /* @__PURE__ */ jsxRuntime.jsx("a", { href: accountHref, style: s.linkBtn, children: first }),
889
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.linkBtn, onClick: () => void account.signOut(), children: t.signOut })
890
+ ] });
891
+ }
892
+ return /* @__PURE__ */ jsxRuntime.jsx("a", { className, href: accountHref, style: { ...wrap, ...s.linkBtn }, children: t.signIn });
893
+ }
894
+ var DEFAULT_LABELS4 = {
859
895
  welcome: "Welcome, {name}",
860
896
  signOut: "Sign out",
861
897
  reservations: "Reservations",
@@ -899,7 +935,7 @@ function Dashboard({
899
935
  customerName,
900
936
  onSignOut
901
937
  }) {
902
- const t = { ...DEFAULT_LABELS3, ...labels };
938
+ const t = { ...DEFAULT_LABELS4, ...labels };
903
939
  const s = styles();
904
940
  const show = (k) => sections.includes(k);
905
941
  const reservations = useMyReservations(
@@ -1016,7 +1052,7 @@ function formatDate(value) {
1016
1052
  if (Number.isNaN(d.getTime())) return String(value);
1017
1053
  return d.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
1018
1054
  }
1019
- var DEFAULT_LABELS4 = {
1055
+ var DEFAULT_LABELS5 = {
1020
1056
  loading: "Loading\u2026",
1021
1057
  unavailable: "This flash sale isn\u2019t available.",
1022
1058
  ended: "This flash sale has ended.",
@@ -1027,7 +1063,7 @@ var DEFAULT_LABELS4 = {
1027
1063
  saleEnded: "Sale ended"
1028
1064
  };
1029
1065
  function FlashSale({ slug, onBook, labels, className }) {
1030
- const t = { ...DEFAULT_LABELS4, ...labels };
1066
+ const t = { ...DEFAULT_LABELS5, ...labels };
1031
1067
  const account = useAccount();
1032
1068
  const sale = useFlashSale({ slug });
1033
1069
  const s = styles();
@@ -1106,14 +1142,62 @@ function Hero({
1106
1142
  description && /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.body, children: description })
1107
1143
  ] });
1108
1144
  }
1145
+ var DEFAULT_LABELS6 = {
1146
+ heading: "Flash sales",
1147
+ loading: "Loading\u2026",
1148
+ unavailable: "Flash sales are unavailable right now.",
1149
+ empty: "No flash sales right now \u2014 check back soon.",
1150
+ liveNow: "On sale now",
1151
+ opens: "Opens",
1152
+ view: "View sale",
1153
+ soon: "Upcoming"
1154
+ };
1155
+ function FlashSaleIndex({ brandId, onOpen, labels, className }) {
1156
+ const t = { ...DEFAULT_LABELS6, ...labels };
1157
+ const s = styles();
1158
+ const list = useFlashSales({ brandId });
1159
+ let body;
1160
+ if (list.loading && !list.data) {
1161
+ body = /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.loading });
1162
+ } else if (list.error) {
1163
+ body = /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.unavailable });
1164
+ } else if ((list.data?.sales.length ?? 0) === 0) {
1165
+ body = /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.muted, children: t.empty });
1166
+ } else {
1167
+ body = /* @__PURE__ */ jsxRuntime.jsx("div", { children: list.data?.sales.map((sale) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: s.listItem, children: [
1168
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1169
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listTitle, children: sale.displayName }),
1170
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: s.listMeta, children: sale.status === "live" ? t.liveNow : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1171
+ t.opens,
1172
+ " ",
1173
+ /* @__PURE__ */ jsxRuntime.jsx(When, { ms: sale.windowStartAt })
1174
+ ] }) })
1175
+ ] }),
1176
+ sale.status === "live" && onOpen ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: s.primaryBtn, onClick: () => onOpen(sale), children: t.view }) : /* @__PURE__ */ jsxRuntime.jsx("span", { style: s.badge, children: sale.status === "live" ? t.liveNow : t.soon })
1177
+ ] }, sale.slug)) });
1178
+ }
1179
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: s.card, children: [
1180
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: s.heading, children: t.heading }),
1181
+ body
1182
+ ] });
1183
+ }
1184
+ function When({ ms }) {
1185
+ const [text, setText] = react.useState(null);
1186
+ react.useEffect(() => {
1187
+ setText(new Date(ms).toLocaleString(void 0, { dateStyle: "medium", timeStyle: "short" }));
1188
+ }, [ms]);
1189
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: text ?? "" });
1190
+ }
1109
1191
 
1110
1192
  exports.AccountDashboard = AccountDashboard;
1193
+ exports.AccountMenu = AccountMenu;
1111
1194
  exports.AuthForm = AuthForm;
1112
1195
  exports.AuthGate = AuthGate;
1113
1196
  exports.BOWLOS_DEFAULT_THEME = BOWLOS_DEFAULT_THEME;
1114
1197
  exports.BookingFlow = BookingFlow;
1115
1198
  exports.BowlosTheme = BowlosTheme;
1116
1199
  exports.FlashSale = FlashSale;
1200
+ exports.FlashSaleIndex = FlashSaleIndex;
1117
1201
  exports.formatCents = formatCents;
1118
1202
  exports.formatCentsRange = formatCentsRange;
1119
1203
  //# sourceMappingURL=components.cjs.map