diff --git a/openframe-frontend-core/docs/EMBEDDING_HUBSPOT_MEETINGS.md b/openframe-frontend-core/docs/EMBEDDING_HUBSPOT_MEETINGS.md index 2ca2595b75..4d9d2bcb33 100644 --- a/openframe-frontend-core/docs/EMBEDDING_HUBSPOT_MEETINGS.md +++ b/openframe-frontend-core/docs/EMBEDDING_HUBSPOT_MEETINGS.md @@ -215,3 +215,25 @@ asks for `layout="modal"`: - Opt-in: the default `layout="card"` is byte for byte what every existing embed renders. `flow="details-first"` has no modal arrangement and keeps the card. +## The booking window (``) + +The whole window, not just its body: a 600px `ModalV2` with the title, the scheduler in +`layout="modal"`, a "Call booked" toast, and closing on a confirmed booking or a phone's +Cancel. Prefer it to wrapping `HubSpotMeetingScheduler` in a modal of your own. + +```tsx + +``` + +The host passes the link it resolved rather than a meeting id: the same read usually +decides whether the entry point is offered at all, so the window does not read the +directory again. With no link and not `loading`, `emptyMessage` is shown in place of the +scheduler. `onBooked` fires after the toast, before the window closes. + diff --git a/openframe-frontend-core/src/__tests__/meeting-scheduler-modal.test.tsx b/openframe-frontend-core/src/__tests__/meeting-scheduler-modal.test.tsx index 65f47684d4..3614bb8d1c 100644 --- a/openframe-frontend-core/src/__tests__/meeting-scheduler-modal.test.tsx +++ b/openframe-frontend-core/src/__tests__/meeting-scheduler-modal.test.tsx @@ -1,7 +1,12 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { HubSpotMeetingScheduler, type HubSpotMeetingSchedulerProps } from '../components/meeting-scheduler'; -import type { MeetingAvailability } from '../schemas/meeting-booking-schema'; +import { + HubSpotMeetingScheduler, + MeetingSchedulerModal, + type HubSpotMeetingSchedulerProps, + type MeetingSchedulerModalProps, +} from '../components/meeting-scheduler'; +import type { MeetingAvailability, SchedulingLink } from '../schemas/meeting-booking-schema'; import { availabilityWith, fillIdentity } from './fixtures/meeting-booking'; /** A slot two hours from now, on the hour — inside the month the calendar opens on. */ @@ -117,3 +122,71 @@ describe('HubSpotMeetingScheduler — modal layout', () => { expect(await screen.findByLabelText(/^Email/)).toBeInTheDocument(); }); }); + +const link: SchedulingLink = { + id: '1', + link: 'https://meetings.example.com/onboarding', + slug: 'onboarding', + purpose: 'openframe-users', + title: 'Onboarding call', + description: null, + kind: 'personal', + durationsMinutes: [30, 45], + hosts: [], + nextAvailableMs: SLOT_MS, +}; + +const bookingWindow = (props: Partial = {}) => ( + +); + +describe('MeetingSchedulerModal', () => { + it('is the titled window around the scheduler in its modal layout', async () => { + render(bookingWindow()); + expect(screen.getByText('Book an Onboarding Call')).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument(); + expect(await timeChip()).toBeInTheDocument(); + }); + + it('with no link to book it says so instead of drawing the scheduler', () => { + render(bookingWindow({ link: null, emptyMessage: 'No onboarding calls can be booked right now.' })); + expect(screen.getByText('No onboarding calls can be booked right now.')).toBeInTheDocument(); + expect(screen.queryByRole('button', { name: 'Continue' })).not.toBeInTheDocument(); + }); + + it('while the link is read the scheduler holds its place, not the empty line', () => { + render(bookingWindow({ link: null, loading: true })); + expect(screen.queryByText('No calls can be booked right now.')).not.toBeInTheDocument(); + }); + + it('Cancel closes the window', () => { + const onClose = vi.fn(); + render(bookingWindow({ onClose })); + fireEvent.click(screen.getByRole('button', { name: 'Cancel' })); + expect(onClose).toHaveBeenCalledTimes(1); + }); + + it('a confirmed booking toasts, reports the booking and closes the window', async () => { + const confirmation = { meetingId: '1', title: 'Onboarding call', startTimeMs: SLOT_MS, durationMs: 1_800_000 }; + book.mockResolvedValue({ ok: true, confirmation }); + const onClose = vi.fn(); + const onBooked = vi.fn(); + render(bookingWindow({ onClose, onBooked })); + fireEvent.click(await timeChip()); + fireEvent.click(screen.getByRole('button', { name: 'Continue' })); + await screen.findByLabelText(/^Email/); + fillIdentity(); + const submit = screen.getByRole('button', { name: 'Confirm Booking' }); + await waitFor(() => expect(submit).not.toBeDisabled()); + fireEvent.click(submit); + await waitFor(() => expect(onClose).toHaveBeenCalledTimes(1)); + expect(onBooked).toHaveBeenCalledWith(confirmation); + expect(toast).toHaveBeenCalledWith( + expect.objectContaining({ + title: 'Call booked', + variant: 'success', + description: expect.stringContaining('Onboarding call - ') as unknown, + }), + ); + }); +}); diff --git a/openframe-frontend-core/src/components/meeting-scheduler/index.tsx b/openframe-frontend-core/src/components/meeting-scheduler/index.tsx index eff3c4da1e..7ab91253df 100644 --- a/openframe-frontend-core/src/components/meeting-scheduler/index.tsx +++ b/openframe-frontend-core/src/components/meeting-scheduler/index.tsx @@ -53,14 +53,15 @@ import { type MeetingAvailability, type MeetingBookingErrorCode, type MeetingHost, + type SchedulingLink, } from '../../schemas/meeting-booking-schema'; import { cn } from '../../utils/cn'; import { FORM_RESCUE_ATTEMPT_FIELD, type FormRescueDefinition } from '../../utils/form-rescue'; -import { formatDurationCompact, formatDateWithTimezone } from '../../utils/format'; +import { formatDurationCompact, formatDateWithTimezone, VIEWER_TIMEZONE } from '../../utils/format'; import { BackButton } from '../layout/back-button'; import { LoadingRegion } from '../loading/loading-region'; -import { Alert, AlertDescription, Button } from '../ui'; -import { LOADING_NOOP, useLoadingScope } from '../ui/loading-scope'; +import { Alert, AlertDescription, Button, ModalV2, ModalV2Content, ModalV2Header, ModalV2Title } from '../ui'; +import { LOADING_NOOP, LoadingWhen, useLoadingScope } from '../ui/loading-scope'; import { BookingForm, DEFAULT_SUBMIT_LABEL, type BookingFieldRow, type BookingFormProps } from './booking-form'; import { Confirmation } from './confirmation'; import { SchedulerContextPanel } from './context-panel'; @@ -1213,6 +1214,87 @@ export function HubSpotMeetingScheduler({ ); } +export interface MeetingSchedulerModalProps { + isOpen: boolean; + onClose: () => void; + /** The window's heading, e.g. "Book an Onboarding Call". */ + title: string; + /** The link to book (from the host's `/api/meetings` directory); `null` while it is read or when there is none. */ + link: SchedulingLink | null; + /** The host is still reading `link`: the scheduler draws its own loading state in its place. */ + loading?: boolean; + /** Endpoints prefix, as on `HubSpotMeetingScheduler`. */ + apiBaseUrl?: string; + /** Fires after a confirmed booking, once the booked toast is up; the window closes itself. */ + onBooked?: (booking: BookingConfirmation) => void; + /** The line shown in place of the scheduler when there is no link to book. */ + emptyMessage?: string; + className?: string; +} + +/** + * The whole booking window: a 600px `ModalV2` with the title, the scheduler in + * its modal layout, and a booked toast. The window closes on a confirmed + * booking, and on a phone's Cancel (the scheduler's host exit). + * + * The host passes the link it resolved, not a meeting id: the same read + * usually decides whether the entry point is offered at all, so the window + * takes its answer rather than reading the directory again. While it is read + * the scheduler draws its loading state in the same tree, so nothing remounts + * when the link lands. + */ +export function MeetingSchedulerModal({ + isOpen, + onClose, + title, + link, + loading = false, + apiBaseUrl = '', + onBooked, + emptyMessage = 'No calls can be booked right now.', + className, +}: MeetingSchedulerModalProps) { + const { toast } = useToast(); + + return ( + + + {title} + + {/* The window scrolls as a whole on a phone (the scheduler's footer rides + with the card); without this slot the body has no scroll box at all. */} + + {link || loading ? ( + + { + const when = formatDateWithTimezone(booking.startTimeMs, VIEWER_TIMEZONE, 'weekdayDateTimeZoned', { + viewerLocale: true, + }); + toast({ + title: 'Call booked', + description: `${booking.title} - ${when}. Check your email for the invite.`, + variant: 'success', + }); + onBooked?.(booking); + onClose(); + }} + /> + + ) : ( +

{emptyMessage}

+ )} +
+
+ ); +} + // The override surface: a host builds its `detailsForm` by re-rendering // `BookingForm` with `fieldRows`, so it needs both from this entry point (the // package exports `./components/meeting-scheduler`, not the file beneath it).