Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions openframe-frontend-core/docs/EMBEDDING_HUBSPOT_MEETINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`<MeetingSchedulerModal>`)

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
<MeetingSchedulerModal
isOpen={open}
onClose={close}
title="Book an Onboarding Call"
link={link} // a SchedulingLink from your /api/meetings payload; null while read or when none
loading={isLoading} // the scheduler draws its loading state until the link lands
apiBaseUrl={CONTENT_PREFIX}
/>
```

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.

Original file line number Diff line number Diff line change
@@ -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. */
Expand Down Expand Up @@ -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<MeetingSchedulerModalProps> = {}) => (
<MeetingSchedulerModal isOpen onClose={vi.fn()} title="Book an Onboarding Call" link={link} {...props} />
);

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,
}),
);
});
});
88 changes: 85 additions & 3 deletions openframe-frontend-core/src/components/meeting-scheduler/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
<ModalV2 isOpen={isOpen} onClose={onClose} className={cn('md:max-w-[600px]', className)}>
<ModalV2Header>
<ModalV2Title>{title}</ModalV2Title>
</ModalV2Header>
{/* 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. */}
<ModalV2Content className="flex flex-col">
{link || loading ? (
<LoadingWhen loading={!link}>
<HubSpotMeetingScheduler
layout="modal"
meetingId={link?.id ?? ''}
apiBaseUrl={apiBaseUrl}
hosts={link?.hosts}
fallbackUrl={link?.link}
onBack={onClose}
onBooked={booking => {
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();
}}
/>
</LoadingWhen>
) : (
<p className="text-ods-text-secondary text-h4">{emptyMessage}</p>
)}
</ModalV2Content>
</ModalV2>
);
}

// 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).
Expand Down
Loading