MSM customer screens (@msm-platform/customer-react)
MSM's customer screens as a React library, and their server half for the partner's own server. The screens cover booking (the partner's businesses, a business's event types and a week of its availability, then hold, sign in if needed, confirm and cancel), phone-first sign-in (a new customer gives their name after the code), bookings with cancellation, memberships and passes, and details (only the name is editable), with sign out and sign out everywhere. React and React DOM are peers; it does not use React Router. examples/customer-nextjs is the starter that mounts both halves, and the screens' dev host in this repository.
npm install @msm-platform/customer-react
It depends on @msm-platform/customer-sdk, which the server half calls the engine through, and on libphonenumber-js for the phone input. Versions are 0.x until engine 1.0.0: a breaking change raises the minor version (0.1.x → 0.2.0) and is marked Breaking in CHANGELOG.md, so a caret range such as ^0.1.0 takes only compatible releases.
Public API
What the changelog treats as breaking to rename or remove: the exports of ., ./headless and ./server, with the hooks' options and the fields they return (Your own markup), and the stylesheet ./style.css; the props below of MsmCustomer, MsmBooking, MsmAccount, MsmSignIn and MsmPayButtons, and the statuses MsmPayButtons reports, including brand: {name, logo}, botCheck: {provider: "turnstile", siteKey} and the screen values businesses, {businessId}, {businessId, eventTypeId}, bookings, passes and details (a new value is additive; renaming or removing one, or changing the default businesses, is breaking); the nine --msm-customer-* properties (Theming); the server half's options and routes, including the botCheckToken field; and readCustomerSession. Another bot-check provider would be an additive member of botCheck's union; renaming "turnstile" or botCheckToken is breaking. The server half's clientIp is required in every environment, and createCustomerHandler throws without it.
The screens
import "@msm-platform/customer-react/style.css";
import { MsmCustomer } from "@msm-platform/customer-react";
<MsmCustomer
basePath="/msm"
brand={{ name: "Demo Studio", logo: "/logo.svg" }}
botCheck={{
provider: "turnstile",
siteKey: process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY,
}}
/>;
| Prop |
Meaning |
basePath |
Where the server half is mounted, such as /msm. The screens call only ${basePath}/auth/* and ${basePath}/engine/web/*, with X-MSM-BFF: 1. |
brand |
Optional {name, logo} for the header and sign-in. Loading it is the host's job. Colours come from CSS (Theming). |
botCheck |
Required: { provider: "turnstile", siteKey }, the partner's Cloudflare Turnstile site key. A plain object, so a server component can pass it. |
screen, onNavigate |
businesses (the default), { businessId }, { businessId, eventTypeId }, bookings, passes or details. Leave both out and the package switches screens itself; pass both to drive it from the host's URL or router, which also lets the partner's own pages link straight to a business or one of its event types. |
The browser holds no credentials: the server half adds the client's and keeps the session in an encrypted HttpOnly cookie.
Booking
Browsing needs no session: the business list, a business and its availability are public reads. Availability shows a week at a time from today in the business's timezone, events with the seats left and open time slots in one list, narrowed to one event type when the screen names one. Choosing a time holds it; a customer who is signed out signs in first, giving their name after the code when they are new, and the time they chose is held straight after. The hold lasts 10 minutes, the engine's hold, and confirming turns it into a booking, shown with the same cancel step and late-cancellation wording as the bookings screen. The engine's refusals are shown in the screens' own words, picked by their code: a full event, a taken slot, the limit of 5 unconfirmed holds, a hold that lapsed before confirming (with an offer to hold it again), a time that can no longer be booked, and an event type that needs a membership or pass. Payment is not part of booking yet.
Before sending a code, sign-in shows Cloudflare Turnstile and sends its token as botCheckToken. The widget's script (https://challenges.cloudflare.com/turnstile/v0/api.js) loads only in the phone step, so a Content Security Policy needs https://challenges.cloudflare.com in script-src and frame-src. Without a botCheck prop, sign-in says it isn't set up and sends nothing. In development, Cloudflare's test site key 1x00000000000000000000AA always passes.
The built entry starts with "use client", so a Next.js server component can import it; it touches no browser globals at import and renders on the server (as "Loading…" until mounted).
Components for your own pages
Besides MsmCustomer, three components show one part of the screens on your own pages, such as in a modal or overlay your site draws, and MsmPayButtons pays for a time your page holds: the package ships no dialog, focus trap or scroll lock. Each of the three takes basePath, brand and botCheck as MsmCustomer does, renders its own .msm-customer root, and moves focus to its first field when it mounts. Components on the same basePath share one sign-in: signing in or out in one shows in all of them, and each optional onSessionChange(signedIn) hears every sign-in and sign-out after the first session check, including a session the server half ended, so your header can refresh.
import {
MsmAccount,
MsmBooking,
MsmPayButtons,
MsmSignIn,
} from "@msm-platform/customer-react";
MsmBooking
The booking flow for one business, in steps: the customer chooses an event type; then who provides it, with Anyone first, when two or more resources can; then a time. See all times, every time at the business filtered by event type and by resource, is offered on the first step, unfiltered, and on the resource and times steps, filtered by the choice made there (none for Anyone); Back returns to the step it was opened from. A signed-out customer signs in with the time kept, and gives their name too when they are new, then holds, confirms and sees the booking with its cancel step. It has no tabs and never leaves the business.
| Prop |
Meaning |
businessId |
The business. |
eventTypeId |
Optional: opens past the first step on this event type, or filters See all times by it. |
resourceId |
Optional: a resource that provides the event type, or "any" for anyone; with all, filters every time by it. |
all |
Optional true: See all times. |
allFrom |
Optional, with all: { eventTypeId, resourceId? }, the resource or times step See all times was opened from (resourceId is a resource or "any" from the times step); Back returns to it. |
time |
Optional MsmBookingTime, { startsAt, eventTypeId, eventId?, resourceId? }: opens on that time. A time that can no longer be booked shows the step it was in with a note. |
onChange |
Called with MsmBookingSelection, { businessId, eventTypeId?, resourceId?, all?, allFrom?, time? }, at every step and every step back. Pass it to keep the selection in your URL and feed it back as props; leave it out and the component keeps the selection itself. |
onBooked |
Called once with the booking, CustomerBooking, when the customer confirms it. |
onClose |
Adds a Close button to every step, and Done to the booked step, that call it. |
autoFocus |
Optional, default true: the first field takes focus when the flow opens, as a dialog expects. Pass false for a flow placed in a page, so it neither takes the page's focus nor scrolls it; later steps still take focus. |
A hold cannot be read back, so mounting MsmBooking again on a time holds that time again.
MsmAccount
Bookings, Passes and My details, with no Book tab, and sign-in in place when signed out. screen (bookings, the default, passes or details) and onNavigate follow MsmCustomer's rule: leave both out and it switches tabs itself.
MsmSignIn
The phone-first sign-in form on its own: phone, code, and a name only when the customer is new. onSignedIn() is called once the customer is signed in, whether they already had an account or just registered, and at once when they already were; onCancel adds a Cancel button. It never navigates: close your modal on either.
MsmPayButtons
The "Pay with …" buttons for a reservation your page already holds for the signed-in customer, such as from your own class panel: one button for each of the business's online payment methods, in its order, then the provider's page, and the result. Pass basePath, businessId, the held reservationId and onResult, which is called once with { status: "confirmed", bookingId }, { status: "released" } (the payment didn't go through, or the hold lapsed) or { status: "unconfirmed_paid" } (paid after the time was taken; the business settles with the customer). It shows no price, sign-in or booking: your page does. With a server half with cookies, the buttons send this page to the provider's page, calling the optional onLeave just before, and the provider sends the customer back to this page with msmCheckout in the query. Show the same reservation's MsmPayButtons again there; it removes msmCheckout, reads the payment and calls onResult. With a cookieless server half, the provider's page opens in a new tab as described under Sessions, and this page stays and calls onResult as soon as the payment arrives. useMsmPayment takes the same props and returns its state, pay(method) and payAgain, for drawing the buttons yourself.
Your own markup (@msm-platform/customer-react/headless)
For a site that draws every screen itself, ./headless exports the screens' logic as hooks with no markup and no stylesheet: the same session, sign-in, availability, booking, payment and account logic that MsmCustomer, MsmBooking, MsmSignIn and MsmAccount run on. Wrap the part of your page that uses them in MsmCustomerProvider, which takes basePath, an optional locale and onSessionChange, and renders nothing of its own. Components and providers on the same basePath share one sign-in.
import {
MsmCustomerProvider,
useMsmAvailability,
useMsmBooking,
useMsmSession,
useMsmSignIn,
} from "@msm-platform/customer-react/headless";