---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# A flow in steps

A booking, a checkout, a setup: steps, a live summary beside them, a done state

Copy the file below whole (`src/screens/visits.tsx`, say) beside `frame.tsx` (`docs/screen-frame.md`), whose `NAVIGATION` holds its page (`/visits`), and swap the steps, fields and sample choices for yours; keep the parts and their props. Use it wherever a person makes one thing in a few ordered steps (book a visit, check out an order, set up a project, send a request); for one short form, a Card of Field rows in `PageBody variant="column"` is enough.

The Wizard holds a body of two columns (PageColumns): the heading and the step strip over them, the step's card in the main column, a summary card beside it that follows every answer as it is given (under the steps on a phone). Each step checks itself as it is left: Continue on a step with a missing or wrong answer keeps the step, writes the reason under each refused field (marked `aria-invalid`, read out at once) and focuses the first one; the reason follows what is typed after. Back goes one step back and keeps every answer (all panels stay mounted and the answers live in one state). The strip ticks a step once it is left filled. The review step lists the answers, each with Change, which returns to that step with its first field focused. The last step's Book visit shows a done card in the flow's place (its heading focused), and Book another empties the answers and starts again. Keys are the parts' own: Tab between fields; a select opens on Space, Enter or the arrows; the day's trigger opens the month (arrows move the day, Enter picks, Escape closes); a time is typed ("930", "2pm") or picked from its list with the arrows; the kind and the length move with the arrows. Light, dark, phone and desktop are the parts' own: add no class for them.

```tsx
// src/screens/visits.tsx: the flow in steps
import { type MouseEvent, type RefObject, useEffect, useRef, useState } from 'react';
import { flushSync } from 'react-dom';
import { AppFramePanel } from '@/components/goop/patterns/app-frame';
import { PageColumns } from '@/components/goop/patterns/page-columns';
import { Button } from '@/components/ui/goop/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/goop/card';
import { ChoiceGroup, ChoiceGroupItem } from '@/components/ui/goop/choice-group';
import {
  DatePicker,
  DatePickerContent,
  DatePickerPanel,
  DatePickerTrigger,
} from '@/components/ui/goop/date-picker';
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle } from '@/components/ui/goop/empty';
import { Field, FieldValue } from '@/components/ui/goop/field';
import { FieldInvalid } from '@/components/ui/goop/field-error';
import { MetaFacts, MetaFactsItem, MetaFactsLabel, MetaFactsValue } from '@/components/ui/goop/meta-facts';
import {
  PageHeader,
  PageHeaderContent,
  PageHeaderDescription,
  PageHeaderTitle,
} from '@/components/ui/goop/page-header';
import { RadioGroup, RadioGroupItem } from '@/components/ui/goop/radio-group';
import { SegmentedControl, SegmentedControlItem } from '@/components/ui/goop/segmented-control';
import {
  Select,
  SelectContent,
  SelectIcon,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from '@/components/ui/goop/select';
import { TextInput } from '@/components/ui/goop/text-input';
import { Textarea } from '@/components/ui/goop/textarea';
import { TimePicker } from '@/components/ui/goop/time-picker';
import {
  Wizard,
  WizardFooter,
  WizardHeader,
  WizardNext,
  WizardPanel,
  WizardPrevious,
} from '@/components/ui/goop/wizard';
import { ScreenFrame, ScreenTopBar } from './frame';

// ---- the sample data: swap it for yours
const STEPS = [
  { value: 'visit', label: 'Visit' },
  { value: 'when', label: 'Day and time' },
  { value: 'contact', label: 'Contact' },
  { value: 'review', label: 'Review' },
] as const;
type Step = (typeof STEPS)[number]['value'];
const CUSTOMERS = ['Diallo Dental', 'Eastgate Library', 'Kvist Bikes', 'Ortega Physio'];
const KINDS = [
  { value: 'setup', label: 'Setup', description: 'Install it and walk the team through it' },
  { value: 'check', label: 'Check-up', description: 'A look at how it runs, with notes after' },
  { value: 'training', label: 'Training', description: 'Time with the people who use it every day' },
];
const LENGTHS = [
  { value: '30', label: '30 min' },
  { value: '60', label: '1 hour' },
  { value: '120', label: '2 hours' },
];
/** The day the flow counts from: the screen never reads the clock (your app passes today). */
const TODAY = new Date(2026, 10, 19);

interface Answers {
  customer: string;
  kind: string;
  day: Date | null;
  start: string | null;
  length: string;
  name: string;
  email: string;
  note: string;
}
/** What the flow holds when it opens, and again after Book another. */
const EMPTY: Answers = {
  customer: '',
  kind: 'check',
  day: null,
  start: null,
  length: '60',
  name: '',
  email: '',
  note: '',
};
type FieldId = 'customer' | 'day' | 'start' | 'name' | 'email';
/** The field Change focuses on its step. */
const FIRST_FIELD: Record<Exclude<Step, 'review'>, FieldId> = { visit: 'customer', when: 'day', contact: 'name' };
const EMAIL = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;

/** A step's refused fields, in reading order, each with the sentence that says what to fix; none: the step may be left. */
function refusals(step: Step, answers: Answers): Partial<Record<FieldId, string>> {
  if (step === 'visit') return answers.customer ? {} : { customer: 'Choose the customer the visit is for.' };
  if (step === 'when')
    return {
      ...(answers.day ? {} : { day: 'Choose a day.' }),
      ...(answers.start ? {} : { start: 'Choose a start time.' }),
    };
  if (step === 'contact') {
    const email = answers.email.trim();
    return {
      ...(answers.name.trim() ? {} : { name: 'Write the name of the person you meet.' }),
      ...(EMAIL.test(email)
        ? {}
        : {
            email: email ? 'Write a whole email, like name@example.org.' : 'Write the email the confirmation goes to.',
          }),
    };
  }
  return {};
}

const dayWords = (day: Date) => day.toLocaleDateString('en-GB', { weekday: 'long', day: 'numeric', month: 'long' });
const whenWords = (answers: Answers) =>
  answers.day ? `${dayWords(answers.day)}${answers.start ? ` at ${answers.start}` : ''}` : '';
const kindWords = (answers: Answers) => KINDS.find((one) => one.value === answers.kind)?.label ?? '';
const lengthWords = (answers: Answers) => LENGTHS.find((one) => one.value === answers.length)?.label ?? '';

export default function BookVisitScreen() {
  const [step, setStep] = useState<Step>('visit');
  const [answers, setAnswers] = useState<Answers>(EMPTY);
  // the steps a person tried to leave (their reasons show, then follow what is typed) and the steps left filled
  const [tried, setTried] = useState<ReadonlySet<Step>>(new Set());
  const [left, setLeft] = useState<ReadonlySet<Step>>(new Set());
  const [booked, setBooked] = useState(false);
  const customerRef = useRef<HTMLButtonElement>(null);
  const dayRef = useRef<HTMLButtonElement>(null);
  const startRef = useRef<HTMLInputElement>(null);
  const nameRef = useRef<HTMLInputElement>(null);
  const emailRef = useRef<HTMLInputElement>(null);
  const bookedRef = useRef<HTMLHeadingElement>(null);
  const refs: Record<FieldId, RefObject<HTMLElement | null>> = {
    customer: customerRef,
    day: dayRef,
    start: startRef,
    name: nameRef,
    email: emailRef,
  };
  // the done card's heading takes the focus, so it is read in the flow's place
  useEffect(() => {
    if (booked) bookedRef.current?.focus();
  }, [booked]);

  const change = (next: Partial<Answers>) => setAnswers((was) => ({ ...was, ...next }));
  const errors: Partial<Record<FieldId, string>> = Object.assign(
    {},
    ...STEPS.map((one) => (tried.has(one.value) ? refusals(one.value, answers) : {})),
  );
  const filled = (one: Step) => Object.keys(refusals(one, answers)).length === 0;
  const go = (next: Step) => {
    setLeft((was) => new Set(was).add(step));
    setStep(next);
  };
  /** Continue: the step stays while a field of it is refused, and the first refused field takes the focus. */
  const check = (event: MouseEvent<HTMLButtonElement>) => {
    const first = (Object.keys(refusals(step, answers)) as FieldId[])[0];
    if (first === undefined) return;
    event.preventDefault();
    setTried((was) => new Set(was).add(step));
    refs[first].current?.focus();
  };
  /** Change on the review step: back to the step, drawn at once, with its first field focused. */
  const edit = (target: Exclude<Step, 'review'>) => {
    flushSync(() => go(target));
    refs[FIRST_FIELD[target]].current?.focus();
  };
  const again = () => {
    setAnswers(EMPTY);
    setTried(new Set());
    setLeft(new Set());
    setStep('visit');
    setBooked(false);
  };

  const heading = (
    // over the step strip the heading keeps no space of its own (the strip holds the room); over the done card it does
    <PageHeader spaced={booked}>
      <PageHeaderContent>
        <PageHeaderTitle asChild>
          <h1>Book a visit</h1>
        </PageHeaderTitle>
        <PageHeaderDescription>Four short steps; the summary beside them follows every answer.</PageHeaderDescription>
      </PageHeaderContent>
    </PageHeader>
  );
  const summary = (
    <Card variant="outline">
      <CardHeader>
        <CardTitle asChild>
          <h2>Your visit</h2>
        </CardTitle>
        <CardDescription>{booked ? 'Booked' : 'Not booked yet'}</CardDescription>
      </CardHeader>
      <CardContent>
        <MetaFacts aria-label="Summary" stack="always">
          <MetaFactsItem>
            <MetaFactsLabel>Customer</MetaFactsLabel>
            <MetaFactsValue>{answers.customer || 'Not chosen'}</MetaFactsValue>
          </MetaFactsItem>
          <MetaFactsItem>
            <MetaFactsLabel>Visit</MetaFactsLabel>
            <MetaFactsValue>{`${kindWords(answers)}, ${lengthWords(answers)}`}</MetaFactsValue>
          </MetaFactsItem>
          <MetaFactsItem>
            <MetaFactsLabel>When</MetaFactsLabel>
            <MetaFactsValue>{whenWords(answers) || 'Not chosen'}</MetaFactsValue>
          </MetaFactsItem>
          <MetaFactsItem>
            <MetaFactsLabel>Contact</MetaFactsLabel>
            <MetaFactsValue>{answers.name.trim() || 'Not given'}</MetaFactsValue>
          </MetaFactsItem>
        </MetaFacts>
      </CardContent>
    </Card>
  );
  const review: { label: string; words: string; step: Exclude<Step, 'review'> }[] = [
    { label: 'Customer', words: answers.customer, step: 'visit' },
    { label: 'Visit', words: `${kindWords(answers)}, ${lengthWords(answers)}`, step: 'when' },
    { label: 'When', words: whenWords(answers), step: 'when' },
    { label: 'Contact', words: `${answers.name.trim()}, ${answers.email.trim()}`, step: 'contact' },
  ];

  return (
    <ScreenFrame current="/visits">
      <AppFramePanel header={<ScreenTopBar title="Visits" />}>
        {booked ? (
          <PageColumns heading={heading} aside={summary} asideLabel="Summary">
            <Empty variant="outline">
              <EmptyHeader>
                <EmptyTitle asChild>
                  <h2 ref={bookedRef} tabIndex={-1} className="outline-none">
                    {`${answers.customer} is booked`}
                  </h2>
                </EmptyTitle>
                <EmptyDescription>
                  {`${kindWords(answers)}, ${whenWords(answers)}. The confirmation goes to ${answers.email.trim()}.`}
                </EmptyDescription>
              </EmptyHeader>
              <EmptyContent>
                <Button variant="outline" onClick={again}>
                  Book another
                </Button>
              </EmptyContent>
            </Empty>
          </PageColumns>
        ) : (
          <Wizard
            aria-label="Book a visit"
            steps={STEPS.map((one) => ({
              ...one,
              ...(one.value === 'review' ? {} : { complete: left.has(one.value) && filled(one.value) }),
            }))}
            value={step}
            onValueChange={(next) => go(next as Step)}
          >
            <PageColumns
              heading={
                <>
                  {heading}
                  <WizardHeader label="Booking steps" />
                </>
              }
              aside={summary}
              asideLabel="Summary"
            >
              <WizardPanel
                value="visit"
                headingLevel={2}
                title="What the visit is for"
                description="The customer, and the kind of visit."
              >
                <ul>
                  <Field as="li" label="Customer">
                    <FieldInvalid error={errors.customer}>
                      {(wiring) => (
                        <Select value={answers.customer} onValueChange={(customer) => change({ customer })}>
                          <SelectTrigger ref={customerRef} {...wiring}>
                            <SelectValue placeholder="Choose a customer" />
                            <SelectIcon />
                          </SelectTrigger>
                          <SelectContent aria-label="Customer" search={false}>
                            {CUSTOMERS.map((customer) => (
                              <SelectItem key={customer} value={customer}>
                                {customer}
                              </SelectItem>
                            ))}
                          </SelectContent>
                        </Select>
                      )}
                    </FieldInvalid>
                  </Field>
                  <li className="p-4 max-narrow:px-2.5">
                    <ChoiceGroup label="Kind of visit">
                      <RadioGroup value={answers.kind} onValueChange={(kind) => change({ kind })} name="kind">
                        {KINDS.map((one) => (
                          <ChoiceGroupItem key={one.value} label={one.label} description={one.description}>
                            <RadioGroupItem value={one.value} />
                          </ChoiceGroupItem>
                        ))}
                      </RadioGroup>
                    </ChoiceGroup>
                  </li>
                </ul>
              </WizardPanel>
              <WizardPanel
                value="when"
                headingLevel={2}
                title="When it happens"
                description="Weekdays, starting between 08:00 and 17:00."
              >
                <ul>
                  <Field as="li" label="Day">
                    <FieldInvalid error={errors.day}>
                      {(wiring) => (
                        <DatePicker value={answers.day} onValueChange={(day) => change({ day })} {...wiring}>
                          <DatePickerTrigger ref={dayRef} placeholder="Choose a day" />
                          <DatePickerContent aria-label="Day">
                            <DatePickerPanel minDate={TODAY} today={TODAY} disabledDays={[{ dayOfWeek: [0, 6] }]} />
                          </DatePickerContent>
                        </DatePicker>
                      )}
                    </FieldInvalid>
                  </Field>
                  <Field as="li" label="Start">
                    <FieldInvalid error={errors.start}>
                      <TimePicker
                        ref={startRef}
                        value={answers.start}
                        onValueChange={(start) => change({ start })}
                        step={30}
                        min="08:00"
                        max="17:00"
                        placeholder="Choose a time"
                        error="Type a time from 08:00 to 17:00."
                      />
                    </FieldInvalid>
                  </Field>
                  <Field as="li" label="Length">
                    <SegmentedControl value={answers.length} onValueChange={(length) => change({ length })}>
                      {LENGTHS.map((one) => (
                        <SegmentedControlItem key={one.value} value={one.value}>
                          {one.label}
                        </SegmentedControlItem>
                      ))}
                    </SegmentedControl>
                  </Field>
                </ul>
              </WizardPanel>
              <WizardPanel
                value="contact"
                headingLevel={2}
                title="Who you meet"
                description="The person on site, and where the confirmation goes."
              >
                <ul>
                  <Field as="li" label="Name">
                    <FieldInvalid error={errors.name}>
                      <TextInput
                        ref={nameRef}
                        autoComplete="name"
                        placeholder="Ngozi Ilori"
                        value={answers.name}
                        onChange={(event) => change({ name: event.currentTarget.value })}
                      />
                    </FieldInvalid>
                  </Field>
                  <Field as="li" label="Email" description="Where the confirmation goes">
                    <FieldInvalid error={errors.email}>
                      <TextInput
                        ref={emailRef}
                        type="email"
                        autoComplete="email"
                        placeholder="name@example.org"
                        value={answers.email}
                        onChange={(event) => change({ email: event.currentTarget.value })}
                      />
                    </FieldInvalid>
                  </Field>
                  <Field as="li" label="Note" description="Optional: parking, a door code" stack="always">
                    <Textarea
                      placeholder="Anything that helps on the day"
                      value={answers.note}
                      onChange={(event) => change({ note: event.currentTarget.value })}
                    />
                  </Field>
                </ul>
              </WizardPanel>
              <WizardPanel
                value="review"
                headingLevel={2}
                title="Check and book"
                description="Nothing is booked until you say so."
              >
                <ul>
                  {review.map((row) => (
                    <Field as="li" key={row.label} label={row.label}>
                      {(control) => (
                        <>
                          <FieldValue>{row.words}</FieldValue>
                          <Button
                            {...control}
                            variant="outline"
                            size="sm"
                            aria-label={`Change the ${row.label.toLowerCase()}`}
                            onClick={() => edit(row.step)}
                          >
                            Change
                          </Button>
                        </>
                      )}
                    </Field>
                  ))}
                </ul>
              </WizardPanel>
            </PageColumns>
            <WizardFooter>
              <WizardPrevious />
              <WizardNext onClick={check} finishLabel="Book visit" onFinish={() => setBooked(true)} />
            </WizardFooter>
          </Wizard>
        )}
      </AppFramePanel>
    </ScreenFrame>
  );
}
```
