@bowlos/reservations 0.3.0 → 0.5.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.
- package/README.md +34 -7
- package/dist/{chunk-4VDDL2CN.js → chunk-E5KVVXSJ.js} +15 -7
- package/dist/chunk-E5KVVXSJ.js.map +1 -0
- package/dist/{chunk-TCYTNCUL.js → chunk-YICHFUAY.js} +41 -3
- package/dist/chunk-YICHFUAY.js.map +1 -0
- package/dist/cli.cjs +74 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/components.cjs +94 -60
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +41 -7
- package/dist/components.d.ts +41 -7
- package/dist/components.js +90 -21
- package/dist/components.js.map +1 -1
- package/dist/index.js +172 -4
- package/dist/index.js.map +1 -1
- package/dist/{react-B_8H7AyT.d.cts → react-7ruEsubp.d.cts} +5 -2
- package/dist/{react-bG9YV_xP.d.ts → react-Cb_NZCXa.d.ts} +5 -2
- package/dist/react.cjs +12 -3
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +2 -3
- package/package.json +4 -3
- package/templates/center-site/README.md +85 -0
- package/templates/center-site/app/account/page.tsx +19 -0
- package/templates/center-site/app/book/checkout-form.tsx +85 -0
- package/templates/center-site/app/book/page.tsx +208 -0
- package/templates/center-site/app/flash/[slug]/page.tsx +24 -0
- package/templates/center-site/app/layout.tsx +21 -0
- package/templates/center-site/app/page.tsx +26 -0
- package/templates/center-site/app/providers.tsx +43 -0
- package/templates/center-site/app/site-header.tsx +30 -0
- package/templates/center-site/env.example +23 -0
- package/templates/center-site/gitignore +8 -0
- package/templates/center-site/lib/bowlos.ts +39 -0
- package/templates/center-site/next.config.mjs +8 -0
- package/templates/center-site/package.json +26 -0
- package/templates/center-site/tsconfig.json +38 -0
- package/dist/chunk-4VDDL2CN.js.map +0 -1
- package/dist/chunk-T5DDHWEC.js +0 -174
- package/dist/chunk-T5DDHWEC.js.map +0 -1
- package/dist/chunk-TCYTNCUL.js.map +0 -1
- package/dist/chunk-TZTFJVDI.js +0 -41
- package/dist/chunk-TZTFJVDI.js.map +0 -1
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -106
- package/dist/cli.js.map +0 -1
package/dist/react.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UseQueryOptions, a as UseQueryResult } from './react-
|
|
2
|
-
export { A as AccountStatus, B as BowlosProvider, b as BowlosProviderProps, c as UseAccountResult, u as useAccount, d as useBowlosClient, e as useBowlosQuery } from './react-
|
|
1
|
+
import { U as UseQueryOptions, a as UseQueryResult } from './react-7ruEsubp.cjs';
|
|
2
|
+
export { A as AccountStatus, B as BowlosProvider, b as BowlosProviderProps, c as UseAccountResult, u as useAccount, d as useBowlosClient, e as useBowlosQuery } from './react-7ruEsubp.cjs';
|
|
3
3
|
import { a as AvailabilityArgs, b as AvailabilityResult, f as BookingPreviewArgs, g as BookingQuote, e as BookingHold, P as PaymentIntentInfo, h as BowlosApiError, n as CreateBookingArgs, m as CheckoutStatusResult } from './data-DrM0D6Pi.cjs';
|
|
4
4
|
import { a as FlashSaleArgs, F as FlashBookingOptionsArgs, B as BrandScoped, M as MembershipDetailArgs, R as ReservationDetailArgs } from './account-COEgvwfx.cjs';
|
|
5
5
|
import 'react/jsx-runtime';
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UseQueryOptions, a as UseQueryResult } from './react-
|
|
2
|
-
export { A as AccountStatus, B as BowlosProvider, b as BowlosProviderProps, c as UseAccountResult, u as useAccount, d as useBowlosClient, e as useBowlosQuery } from './react-
|
|
1
|
+
import { U as UseQueryOptions, a as UseQueryResult } from './react-Cb_NZCXa.js';
|
|
2
|
+
export { A as AccountStatus, B as BowlosProvider, b as BowlosProviderProps, c as UseAccountResult, u as useAccount, d as useBowlosClient, e as useBowlosQuery } from './react-Cb_NZCXa.js';
|
|
3
3
|
import { a as AvailabilityArgs, b as AvailabilityResult, f as BookingPreviewArgs, g as BookingQuote, e as BookingHold, P as PaymentIntentInfo, h as BowlosApiError, n as CreateBookingArgs, m as CheckoutStatusResult } from './data-DrM0D6Pi.js';
|
|
4
4
|
import { a as FlashSaleArgs, F as FlashBookingOptionsArgs, B as BrandScoped, M as MembershipDetailArgs, R as ReservationDetailArgs } from './account-CzyIERC5.js';
|
|
5
5
|
import 'react/jsx-runtime';
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { BowlosProvider, useAccount, useAvailability, useBookingFlow, useBookingPreview, useBowlosClient, useBowlosQuery, useFlashSale, useFlashSaleBookingOptions, useMyCredits, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-TCYTNCUL.js';
|
|
1
|
+
export { BowlosProvider, useAccount, useAvailability, useBookingFlow, useBookingPreview, useBowlosClient, useBowlosQuery, useFlashSale, useFlashSaleBookingOptions, useMyCredits, useMyLoyalty, useMyMembershipDetail, useMyMemberships, useMyPasses, useMyReservationDetail, useMyReservations } from './chunk-E5KVVXSJ.js';
|
|
2
|
+
import './chunk-YICHFUAY.js';
|
|
4
3
|
//# sourceMappingURL=react.js.map
|
|
5
4
|
//# sourceMappingURL=react.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bowlos/reservations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "BowlOS Reservations SDK — headless client + React hooks for the Module 14 public API gateway. White-label booking, account, and flash-sale reads for third-party-hosted center sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BowlOS",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"files": [
|
|
20
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"templates"
|
|
21
22
|
],
|
|
22
23
|
"main": "./dist/index.cjs",
|
|
23
24
|
"module": "./dist/index.js",
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
"./package.json": "./package.json"
|
|
60
61
|
},
|
|
61
62
|
"scripts": {
|
|
62
|
-
"build": "tsup",
|
|
63
|
+
"build": "tsup && node scripts/build-templates.mjs",
|
|
63
64
|
"lint": "echo \"reservations lint deferred until ESLint workspace plumbing lands\"",
|
|
64
65
|
"typecheck": "tsc --noEmit",
|
|
65
66
|
"test": "echo \"reservations tests run via the root vitest config (packages/**/*.test.{ts,tsx})\"",
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Example: a center website on `@bowlos/reservations`
|
|
2
|
+
|
|
3
|
+
A complete, minimal center site built entirely on the **`@bowlos/reservations`** SDK — the
|
|
4
|
+
**agent-build proof**: it's the reference an AI agent (or a developer) follows to stand up a
|
|
5
|
+
white-label booking site against the BowlOS public-API gateway, with **Stripe Connect** payments.
|
|
6
|
+
|
|
7
|
+
It is a **standalone Next.js (App Router) app** — deliberately *not* part of the BowlOS monorepo
|
|
8
|
+
build. You copy this folder, `npm install`, point it at a gateway + key, and run it.
|
|
9
|
+
|
|
10
|
+
## What it demonstrates
|
|
11
|
+
|
|
12
|
+
The full headless funnel, using only the SDK's public API:
|
|
13
|
+
|
|
14
|
+
| Concern | SDK surface used |
|
|
15
|
+
|---|---|
|
|
16
|
+
| Provider / client | `createBowlosClient`, `localStorageTokenStore`, `BowlosProvider` |
|
|
17
|
+
| Live availability + price | `useAvailability`, `useBookingPreview`, `availableUnitCount` |
|
|
18
|
+
| Book → pay → confirm | `useBookingFlow` (`startHold → preparePayment → startPolling`) |
|
|
19
|
+
| **Stripe Connect handoff** | `PaymentIntentInfo.{clientSecret, connectedAccountId}` → Stripe Elements |
|
|
20
|
+
| Auth lifecycle | `useAccount` (`signIn` / `signUp` / `link` / `signOut`) |
|
|
21
|
+
| Account reads | `useMyReservations` (gated with `enabled`) |
|
|
22
|
+
|
|
23
|
+
The **payment handoff** is the key bit (`app/book/checkout-form.tsx`): the SDK never loads
|
|
24
|
+
Stripe.js. `preparePayment()` returns a `PaymentIntentInfo`; the app initializes Stripe.js with the
|
|
25
|
+
**platform publishable key scoped to the operator's connected account** (`stripeAccount:
|
|
26
|
+
connectedAccountId`) and confirms the `clientSecret`. The charge lands on the operator's Stripe
|
|
27
|
+
account, so their name appears on the statement / receipt / wallet sheet.
|
|
28
|
+
|
|
29
|
+
## File map
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
app/
|
|
33
|
+
layout.tsx BowlosProvider (via providers.tsx)
|
|
34
|
+
providers.tsx creates the client once, provides it
|
|
35
|
+
page.tsx home
|
|
36
|
+
book/
|
|
37
|
+
page.tsx the booking funnel (useBookingFlow state machine)
|
|
38
|
+
checkout-form.tsx Stripe Connect payment handoff
|
|
39
|
+
account/
|
|
40
|
+
page.tsx sign in / sign up + link / my reservations
|
|
41
|
+
lib/
|
|
42
|
+
bowlos.ts client config + env + helpers
|
|
43
|
+
env.example the env vars you must set
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Run it
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cp env.example .env.local # then fill in the values
|
|
50
|
+
npm install
|
|
51
|
+
npm run dev # http://localhost:3000
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Every value in `env.example` is `NEXT_PUBLIC_*` on purpose — the brand API key is a *publishable*
|
|
55
|
+
key, gated by the gateway's per-key **origin allow-list** (like a Stripe publishable key). Add your
|
|
56
|
+
dev + deployed origins to the key's allow-list in the operator admin.
|
|
57
|
+
|
|
58
|
+
Before you start, run the doctor to confirm the wiring:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx bowlos doctor --api-key "$NEXT_PUBLIC_BOWLOS_API_KEY" --base-url "$NEXT_PUBLIC_BOWLOS_BASE_URL"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## The live proof (closes the readiness gate)
|
|
65
|
+
|
|
66
|
+
This template is the *code* proof. The *live* proof — a real sandbox paid booking — needs a brand
|
|
67
|
+
key and a connected Stripe test account:
|
|
68
|
+
|
|
69
|
+
1. **Mint a brand API key** (operator admin → Super-Admin → API keys). Set its allowed origins to
|
|
70
|
+
include `http://localhost:3000`. Use a **test**-mode key.
|
|
71
|
+
2. **Connect a Test-Brand Stripe account** (Payments → Connect) and make sure it's charges-enabled.
|
|
72
|
+
(Reservation/flash direct charges are already live on the gateway.)
|
|
73
|
+
3. Fill `.env.local` (key, base URL, brand/center/product ids, `pk_test_…` Stripe key) and
|
|
74
|
+
`npm run dev`.
|
|
75
|
+
4. Book a lane → pay with a Stripe **test card** (`4242 4242 4242 4242`, any future expiry / CVC).
|
|
76
|
+
5. Confirm the page reaches **"You're booked"** (the gateway webhook materialized the reservation),
|
|
77
|
+
the reservation shows under **/account**, and — the F7 white-label check — the **operator's**
|
|
78
|
+
business name (not BowlOS/REDcloud) appears on the Stripe receipt + statement descriptor.
|
|
79
|
+
|
|
80
|
+
## Notes
|
|
81
|
+
|
|
82
|
+
- Product/center/brand ids are read from env to keep the proof focused on the funnel. A production
|
|
83
|
+
site would discover them via `listPublicCenters` / `listPublicProducts` (also on the gateway).
|
|
84
|
+
- Versions mirror the BowlOS web app (Next 16.2.4, React 19.2, `@stripe/*` 9.4 / 6.3). Bump as you
|
|
85
|
+
like — `@bowlos/reservations` only requires React as a peer.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { AccountDashboard } from "@bowlos/reservations/components";
|
|
3
|
+
import { BRAND_ID } from "../../lib/bowlos";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The whole account surface as one drop-in component: `<AccountDashboard>` signs
|
|
7
|
+
* the customer in (sign in / create account / finish profile) and then shows
|
|
8
|
+
* their reservations, memberships, loyalty, account credit, and passes — all on
|
|
9
|
+
* the SDK hooks, themed by the `<BowlosTheme>` in `providers.tsx`. Compare
|
|
10
|
+
* `app/book/page.tsx`, which drives the lower-level hooks by hand.
|
|
11
|
+
*/
|
|
12
|
+
export default function AccountPage() {
|
|
13
|
+
return (
|
|
14
|
+
<main>
|
|
15
|
+
<h1>My account</h1>
|
|
16
|
+
<AccountDashboard brandId={BRAND_ID} />
|
|
17
|
+
</main>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo, useState, type FormEvent } from "react";
|
|
3
|
+
import { loadStripe } from "@stripe/stripe-js";
|
|
4
|
+
import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
|
|
5
|
+
import type { PaymentIntentInfo } from "@bowlos/reservations";
|
|
6
|
+
import { STRIPE_PUBLISHABLE_KEY } from "../../lib/bowlos";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* THE PAYMENT HANDOFF.
|
|
10
|
+
*
|
|
11
|
+
* The SDK never loads Stripe.js — `useBookingFlow().preparePayment()` returns a
|
|
12
|
+
* `PaymentIntentInfo` and hands it here. We initialize Stripe.js with the
|
|
13
|
+
* PLATFORM publishable key but scoped to the operator's CONNECTED account
|
|
14
|
+
* (`stripeAccount: connectedAccountId`), so the charge is created directly on
|
|
15
|
+
* the operator's Stripe account — their business name lands on the card
|
|
16
|
+
* statement, receipt, and wallet sheet (the white-label requirement). Then we
|
|
17
|
+
* confirm the PaymentIntent with its `clientSecret`.
|
|
18
|
+
*/
|
|
19
|
+
export function CheckoutForm({
|
|
20
|
+
paymentIntent,
|
|
21
|
+
onPaid,
|
|
22
|
+
}: {
|
|
23
|
+
paymentIntent: PaymentIntentInfo;
|
|
24
|
+
onPaid: () => void;
|
|
25
|
+
}) {
|
|
26
|
+
const stripePromise = useMemo(
|
|
27
|
+
() => loadStripe(STRIPE_PUBLISHABLE_KEY, { stripeAccount: paymentIntent.connectedAccountId }),
|
|
28
|
+
[paymentIntent.connectedAccountId],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Elements
|
|
33
|
+
stripe={stripePromise}
|
|
34
|
+
options={{
|
|
35
|
+
clientSecret: paymentIntent.clientSecret,
|
|
36
|
+
// For saved cards across this operator, also pass the SDK's customer
|
|
37
|
+
// session: customerSessionClientSecret: paymentIntent.customerSessionClientSecret
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
<PayForm onPaid={onPaid} />
|
|
41
|
+
</Elements>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function PayForm({ onPaid }: { onPaid: () => void }) {
|
|
46
|
+
const stripe = useStripe();
|
|
47
|
+
const elements = useElements();
|
|
48
|
+
const [submitting, setSubmitting] = useState(false);
|
|
49
|
+
const [message, setMessage] = useState<string | null>(null);
|
|
50
|
+
|
|
51
|
+
async function handleSubmit(e: FormEvent) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
if (!stripe || !elements) return;
|
|
54
|
+
setSubmitting(true);
|
|
55
|
+
setMessage(null);
|
|
56
|
+
|
|
57
|
+
// `redirect: "if_required"` keeps the customer on-page for card payments;
|
|
58
|
+
// wallets that need a redirect still work.
|
|
59
|
+
const { error } = await stripe.confirmPayment({ elements, redirect: "if_required" });
|
|
60
|
+
|
|
61
|
+
if (error) {
|
|
62
|
+
setMessage(error.message ?? "Payment failed — please try again.");
|
|
63
|
+
setSubmitting(false);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Paid. The gateway's Stripe webhook materializes the reservation
|
|
68
|
+
// asynchronously, so hand control back so the page can poll for it.
|
|
69
|
+
onPaid();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<form onSubmit={handleSubmit}>
|
|
74
|
+
<PaymentElement />
|
|
75
|
+
<button type="submit" disabled={!stripe || submitting} style={{ marginTop: "1rem" }}>
|
|
76
|
+
{submitting ? "Paying…" : "Pay now"}
|
|
77
|
+
</button>
|
|
78
|
+
{message && (
|
|
79
|
+
<p role="alert" style={{ color: "crimson" }}>
|
|
80
|
+
{message}
|
|
81
|
+
</p>
|
|
82
|
+
)}
|
|
83
|
+
</form>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, type FormEvent } from "react";
|
|
3
|
+
import {
|
|
4
|
+
useAccount,
|
|
5
|
+
useAvailability,
|
|
6
|
+
useBookingPreview,
|
|
7
|
+
useBookingFlow,
|
|
8
|
+
} from "@bowlos/reservations/react";
|
|
9
|
+
import { availableUnitCount, type CreateBookingArgs } from "@bowlos/reservations";
|
|
10
|
+
import { CENTER_ID, DEMO_PRODUCT_ID, formatCents } from "../../lib/bowlos";
|
|
11
|
+
import { CheckoutForm } from "./checkout-form";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The booking funnel as a single page, driven by `useBookingFlow` — the headless
|
|
15
|
+
* (Path B) reference. Account-aware (hides Name/Email and books as the signed-in
|
|
16
|
+
* customer) and pay-to-confirm: the moment the hold lands we advance straight to
|
|
17
|
+
* payment, so the customer never sees a held-but-unpaid reservation.
|
|
18
|
+
*/
|
|
19
|
+
export default function BookPage() {
|
|
20
|
+
const account = useAccount();
|
|
21
|
+
const signedIn = account.status === "linked" && account.customer !== null;
|
|
22
|
+
|
|
23
|
+
const [dateISO, setDateISO] = useState("2026-07-04");
|
|
24
|
+
const [startMinuteOfDay, setStartMinuteOfDay] = useState(18 * 60); // 6:00 PM
|
|
25
|
+
const endMinuteOfDay = startMinuteOfDay + 60;
|
|
26
|
+
const [units, setUnits] = useState(1);
|
|
27
|
+
const [fullName, setFullName] = useState("");
|
|
28
|
+
const [email, setEmail] = useState("");
|
|
29
|
+
|
|
30
|
+
const availability = useAvailability({
|
|
31
|
+
productId: DEMO_PRODUCT_ID,
|
|
32
|
+
dateISO,
|
|
33
|
+
startMinuteOfDay,
|
|
34
|
+
endMinuteOfDay,
|
|
35
|
+
});
|
|
36
|
+
const preview = useBookingPreview({
|
|
37
|
+
centerId: CENTER_ID,
|
|
38
|
+
productId: DEMO_PRODUCT_ID,
|
|
39
|
+
dateISO,
|
|
40
|
+
startMinuteOfDay,
|
|
41
|
+
endMinuteOfDay,
|
|
42
|
+
mode: "per_unit_per_hour",
|
|
43
|
+
units,
|
|
44
|
+
});
|
|
45
|
+
const flow = useBookingFlow();
|
|
46
|
+
|
|
47
|
+
// Complete-sale-only: as soon as the hold lands, go straight to payment.
|
|
48
|
+
const prepareRef = useRef(flow.preparePayment);
|
|
49
|
+
prepareRef.current = flow.preparePayment;
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (flow.status === "held") void prepareRef.current();
|
|
52
|
+
}, [flow.status]);
|
|
53
|
+
|
|
54
|
+
const freeUnits = availability.data ? availableUnitCount(availability.data) : null;
|
|
55
|
+
const quoteCents = preview.data?.totalCentsPerPlan?.[0]?.totalCents ?? null;
|
|
56
|
+
|
|
57
|
+
const bookingArgs: CreateBookingArgs = useMemo(
|
|
58
|
+
() => ({
|
|
59
|
+
centerId: CENTER_ID,
|
|
60
|
+
productId: DEMO_PRODUCT_ID,
|
|
61
|
+
dateISO,
|
|
62
|
+
startMinuteOfDay,
|
|
63
|
+
endMinuteOfDay,
|
|
64
|
+
mode: "per_unit_per_hour",
|
|
65
|
+
units,
|
|
66
|
+
customer: signedIn
|
|
67
|
+
? {
|
|
68
|
+
fullName: account.customer?.fullName ?? "",
|
|
69
|
+
email: account.customer?.email ?? "",
|
|
70
|
+
marketingOptIn: false,
|
|
71
|
+
}
|
|
72
|
+
: { fullName, email, marketingOptIn: false },
|
|
73
|
+
}),
|
|
74
|
+
[dateISO, startMinuteOfDay, endMinuteOfDay, units, signedIn, account.customer, fullName, email],
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
async function onBook(e: FormEvent) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
await flow.startHold(bookingArgs);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ── confirmed ──────────────────────────────────────────────────────────────
|
|
83
|
+
if (flow.status === "confirmed") {
|
|
84
|
+
return (
|
|
85
|
+
<main>
|
|
86
|
+
<h1>You're booked 🎳</h1>
|
|
87
|
+
<p>Confirmation: {flow.reservation?.reservationDisplayId ?? "(materializing…)"}</p>
|
|
88
|
+
<button onClick={flow.reset}>Book another</button>
|
|
89
|
+
</main>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── pay: hand the Connect PaymentIntent to Stripe Elements ───────────────────
|
|
94
|
+
if (flow.status === "awaitingPayment" && flow.paymentIntent) {
|
|
95
|
+
return (
|
|
96
|
+
<main>
|
|
97
|
+
<h1>Payment</h1>
|
|
98
|
+
<p>Paying {formatCents(flow.paymentIntent.amountCents)} to the operator.</p>
|
|
99
|
+
<CheckoutForm paymentIntent={flow.paymentIntent} onPaid={() => flow.startPolling()} />
|
|
100
|
+
<button onClick={flow.abandon} style={{ marginTop: "1rem" }}>
|
|
101
|
+
Cancel
|
|
102
|
+
</button>
|
|
103
|
+
</main>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ── held / preparing: transient — auto-advancing to payment ──────────────────
|
|
108
|
+
if (flow.status === "held" || flow.status === "preparingPayment") {
|
|
109
|
+
return (
|
|
110
|
+
<main>
|
|
111
|
+
<h1>Securing your spot…</h1>
|
|
112
|
+
{flow.error && <p role="alert">Error: {flow.error.code}</p>}
|
|
113
|
+
</main>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ── form (idle / holding / error) ────────────────────────────────────────────
|
|
118
|
+
const holding = flow.status === "holding";
|
|
119
|
+
return (
|
|
120
|
+
<main>
|
|
121
|
+
<h1>Book a lane</h1>
|
|
122
|
+
<form onSubmit={onBook} style={{ display: "grid", gap: "0.75rem", maxWidth: 360 }}>
|
|
123
|
+
<label>
|
|
124
|
+
Date{" "}
|
|
125
|
+
<input type="date" value={dateISO} onChange={(e) => setDateISO(e.target.value)} />
|
|
126
|
+
</label>
|
|
127
|
+
<label>
|
|
128
|
+
Start{" "}
|
|
129
|
+
<input
|
|
130
|
+
type="time"
|
|
131
|
+
value={minutesToTime(startMinuteOfDay)}
|
|
132
|
+
onChange={(e) => setStartMinuteOfDay(timeToMinutes(e.target.value))}
|
|
133
|
+
/>
|
|
134
|
+
</label>
|
|
135
|
+
<label>
|
|
136
|
+
Lanes{" "}
|
|
137
|
+
<input
|
|
138
|
+
type="number"
|
|
139
|
+
min={1}
|
|
140
|
+
value={units}
|
|
141
|
+
onChange={(e) => setUnits(Math.max(1, Number(e.target.value) || 1))}
|
|
142
|
+
/>
|
|
143
|
+
</label>
|
|
144
|
+
|
|
145
|
+
{signedIn ? (
|
|
146
|
+
<p>
|
|
147
|
+
Booking as <strong>{account.customer?.fullName}</strong>.
|
|
148
|
+
</p>
|
|
149
|
+
) : (
|
|
150
|
+
<>
|
|
151
|
+
<label>
|
|
152
|
+
Name{" "}
|
|
153
|
+
<input value={fullName} onChange={(e) => setFullName(e.target.value)} required />
|
|
154
|
+
</label>
|
|
155
|
+
<label>
|
|
156
|
+
Email{" "}
|
|
157
|
+
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} required />
|
|
158
|
+
</label>
|
|
159
|
+
<p style={{ fontSize: "0.85rem" }}>
|
|
160
|
+
<a href="/account">Sign in to book faster</a>
|
|
161
|
+
</p>
|
|
162
|
+
</>
|
|
163
|
+
)}
|
|
164
|
+
|
|
165
|
+
<p aria-live="polite">
|
|
166
|
+
{availability.loading
|
|
167
|
+
? "Checking availability…"
|
|
168
|
+
: freeUnits !== null
|
|
169
|
+
? `${freeUnits} lane(s) free`
|
|
170
|
+
: availability.error
|
|
171
|
+
? `Availability unavailable (${availability.error.code})`
|
|
172
|
+
: ""}
|
|
173
|
+
</p>
|
|
174
|
+
<p aria-live="polite">
|
|
175
|
+
{preview.loading
|
|
176
|
+
? "Pricing…"
|
|
177
|
+
: quoteCents !== null
|
|
178
|
+
? `Quote: ${formatCents(quoteCents)}`
|
|
179
|
+
: preview.error
|
|
180
|
+
? `Pricing unavailable (${preview.error.code})`
|
|
181
|
+
: ""}
|
|
182
|
+
</p>
|
|
183
|
+
|
|
184
|
+
<button type="submit" disabled={holding || (!signedIn && (!fullName || !email))}>
|
|
185
|
+
{holding ? "Booking…" : "Book my lane"}
|
|
186
|
+
</button>
|
|
187
|
+
</form>
|
|
188
|
+
{flow.error && (
|
|
189
|
+
<p role="alert">
|
|
190
|
+
Booking error: {flow.error.code} — {flow.error.message}
|
|
191
|
+
</p>
|
|
192
|
+
)}
|
|
193
|
+
</main>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function minutesToTime(min: number): string {
|
|
198
|
+
const h = Math.floor(min / 60)
|
|
199
|
+
.toString()
|
|
200
|
+
.padStart(2, "0");
|
|
201
|
+
const m = (min % 60).toString().padStart(2, "0");
|
|
202
|
+
return `${h}:${m}`;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function timeToMinutes(t: string): number {
|
|
206
|
+
const [h, m] = t.split(":").map(Number);
|
|
207
|
+
return (h ?? 0) * 60 + (m ?? 0);
|
|
208
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useParams, useRouter } from "next/navigation";
|
|
3
|
+
import { FlashSale } from "@bowlos/reservations/components";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The branded flash-sale page at `/flash/<slug>`. `<FlashSale>` is session-aware:
|
|
7
|
+
* logged-out visitors see the brand, countdown, the operator's pre-login message,
|
|
8
|
+
* and item names with prices locked behind a sign-in form (sale prices never
|
|
9
|
+
* cross the wire until a customer signs in). Once signed in, prices unlock and
|
|
10
|
+
* Book hands off — here we route into the booking flow carrying the flash item
|
|
11
|
+
* (the storefront-handoff pattern, so checkout reuses the one hardened path).
|
|
12
|
+
*/
|
|
13
|
+
export default function FlashSalePage() {
|
|
14
|
+
const params = useParams<{ slug: string }>();
|
|
15
|
+
const router = useRouter();
|
|
16
|
+
return (
|
|
17
|
+
<main>
|
|
18
|
+
<FlashSale
|
|
19
|
+
slug={params.slug}
|
|
20
|
+
onBook={(item) => router.push(`/book?flashItem=${item.id}`)}
|
|
21
|
+
/>
|
|
22
|
+
</main>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { Providers } from "./providers";
|
|
3
|
+
import { SiteHeader } from "./site-header";
|
|
4
|
+
|
|
5
|
+
export const metadata = {
|
|
6
|
+
title: "Lucky Strike Lanes",
|
|
7
|
+
description: "Book a lane — demo center site on @bowlos/reservations",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
11
|
+
return (
|
|
12
|
+
<html lang="en">
|
|
13
|
+
<body style={{ fontFamily: "system-ui, sans-serif", maxWidth: 640, margin: "2rem auto", padding: "0 1rem" }}>
|
|
14
|
+
<Providers>
|
|
15
|
+
<SiteHeader />
|
|
16
|
+
{children}
|
|
17
|
+
</Providers>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Link from "next/link";
|
|
2
|
+
|
|
3
|
+
export default function HomePage() {
|
|
4
|
+
return (
|
|
5
|
+
<main>
|
|
6
|
+
<h1>Lucky Strike Lanes</h1>
|
|
7
|
+
<p>
|
|
8
|
+
A reference center website built entirely on <code>@bowlos/reservations</code> — booking,
|
|
9
|
+
Stripe Connect payment, account, and flash sales, all over the public API gateway and
|
|
10
|
+
themed with one <code><BowlosTheme></code>.
|
|
11
|
+
</p>
|
|
12
|
+
<ul>
|
|
13
|
+
<li>
|
|
14
|
+
<Link href="/book">Book a lane →</Link> <small>(lower-level hooks)</small>
|
|
15
|
+
</li>
|
|
16
|
+
<li>
|
|
17
|
+
<Link href="/account">My account →</Link> <small>(<AccountDashboard>)</small>
|
|
18
|
+
</li>
|
|
19
|
+
<li>
|
|
20
|
+
<Link href="/flash/tuesday-blowout">Flash sale →</Link>{" "}
|
|
21
|
+
<small>(<FlashSale>, swap in your slug)</small>
|
|
22
|
+
</li>
|
|
23
|
+
</ul>
|
|
24
|
+
</main>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import { BowlosProvider } from "@bowlos/reservations/react";
|
|
4
|
+
import { BowlosTheme } from "@bowlos/reservations/components";
|
|
5
|
+
import { makeBowlosClient } from "../lib/bowlos";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps the app in the SDK provider + a `<BowlosTheme>`. The client is created
|
|
9
|
+
* once (lazy `useState` initializer). If the BowlOS env vars aren't set yet,
|
|
10
|
+
* `makeBowlosClient()` returns null and we render a branded "connecting" notice
|
|
11
|
+
* instead of throwing — so the build/page never breaks (e.g. a fresh Vercel
|
|
12
|
+
* deploy before you've added the env vars). The theme sets the `--bowlos-*` CSS
|
|
13
|
+
* vars so every drop-in component picks up this center's accent + radius.
|
|
14
|
+
*/
|
|
15
|
+
export function Providers({ children }: { children: ReactNode }) {
|
|
16
|
+
const [client] = useState(() => makeBowlosClient());
|
|
17
|
+
|
|
18
|
+
if (!client) {
|
|
19
|
+
return <BookingUnavailable />;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<BowlosProvider client={client}>
|
|
24
|
+
<BowlosTheme theme={{ colorPrimary: "#e4002b", radius: "8px" }}>{children}</BowlosTheme>
|
|
25
|
+
</BowlosProvider>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Shown when the BowlOS env vars aren't configured (no key/base URL). */
|
|
30
|
+
function BookingUnavailable() {
|
|
31
|
+
return (
|
|
32
|
+
<main style={{ maxWidth: 520, margin: "4rem auto", padding: "0 1.25rem", textAlign: "center" }}>
|
|
33
|
+
<h1 style={{ fontSize: "1.5rem", marginBottom: "0.5rem" }}>Connecting the booking system…</h1>
|
|
34
|
+
<p style={{ color: "#6b7280" }}>
|
|
35
|
+
Online booking is being set up. Please check back soon.
|
|
36
|
+
</p>
|
|
37
|
+
<p style={{ color: "#9ca3af", fontSize: "0.8rem", marginTop: "1.5rem" }}>
|
|
38
|
+
(Set the <code>NEXT_PUBLIC_BOWLOS_*</code> env vars in your host and redeploy to enable
|
|
39
|
+
booking.)
|
|
40
|
+
</p>
|
|
41
|
+
</main>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import Link from "next/link";
|
|
3
|
+
import { AccountMenu } from "@bowlos/reservations/components";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Site header with a persistent login indicator. `<AccountMenu>` reads the
|
|
7
|
+
* shared session (from the root `<BowlosProvider>`), so it shows the same thing
|
|
8
|
+
* on every page and updates the moment a customer signs in or out anywhere.
|
|
9
|
+
*/
|
|
10
|
+
export function SiteHeader() {
|
|
11
|
+
return (
|
|
12
|
+
<header
|
|
13
|
+
style={{
|
|
14
|
+
display: "flex",
|
|
15
|
+
justifyContent: "space-between",
|
|
16
|
+
alignItems: "center",
|
|
17
|
+
padding: "0.5rem 0",
|
|
18
|
+
borderBottom: "1px solid #e5e7eb",
|
|
19
|
+
marginBottom: "1.5rem",
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
<nav style={{ display: "flex", gap: "1rem", fontSize: "0.9rem" }}>
|
|
23
|
+
<Link href="/">Home</Link>
|
|
24
|
+
<Link href="/book">Book</Link>
|
|
25
|
+
<Link href="/account">My account</Link>
|
|
26
|
+
</nav>
|
|
27
|
+
<AccountMenu accountHref="/account" />
|
|
28
|
+
</header>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copy to .env.local and fill in. All NEXT_PUBLIC_* values are exposed to the
|
|
2
|
+
# browser — that is correct here: the brand API key is a *publishable* key,
|
|
3
|
+
# gated by the gateway's per-key origin allow-list (just like a Stripe
|
|
4
|
+
# publishable key). Never put a secret key in a NEXT_PUBLIC_* var.
|
|
5
|
+
|
|
6
|
+
# Gateway base URL (include the version prefix) + the brand publishable key.
|
|
7
|
+
# The key is a publishable `bpk_<mode>_…` string from the BowlOS admin's
|
|
8
|
+
# "Public API keys" page, shown once at mint (test keys start `bpk_test_`,
|
|
9
|
+
# live keys `bpk_live_`). Browser-safe, like a Stripe publishable key.
|
|
10
|
+
NEXT_PUBLIC_BOWLOS_BASE_URL=https://your-deployment.convex.site/api/public/v1
|
|
11
|
+
NEXT_PUBLIC_BOWLOS_API_KEY=bpk_test_xxxxxxxxxxxx
|
|
12
|
+
|
|
13
|
+
# The brand + center this site books against, and a bookable product. These are
|
|
14
|
+
# the raw IDs from the BowlOS admin (NO "brand_"/"center_" prefix — they look
|
|
15
|
+
# like k17b60wd8vz1mhgqxz1a36bjvh869mfs).
|
|
16
|
+
NEXT_PUBLIC_BOWLOS_BRAND_ID=your-brand-id
|
|
17
|
+
NEXT_PUBLIC_BOWLOS_CENTER_ID=your-center-id
|
|
18
|
+
NEXT_PUBLIC_DEMO_PRODUCT_ID=your-product-id
|
|
19
|
+
|
|
20
|
+
# Platform Stripe *publishable* key — used WITH the operator's connected
|
|
21
|
+
# account id (returned by the SDK) so the charge lands on the operator's
|
|
22
|
+
# Stripe account. Use a test key (pk_test_…) for the sandbox proof.
|
|
23
|
+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_xxxxxxxxxxxx
|