---
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

Planning a site visit: steps that check themselves, a review, a done state

Copy the file below whole (`src/screens/visits.tsx`) beside `frame.tsx` (`docs/screen-frame.md`), add the `frame` block's row to the frame's `NAVIGATION` before Settings (`node goop/agent/start.mjs flow` does it), 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 (plan a visit, set up a workspace, send a request); for one short form, the settings rows of `docs/screen-settings.md` are enough. The reference holds no flow of steps: this one is Meadow's Wizard as it composes itself, each step a settings section on the page fill (its title over a muted line, then its Field rows), in Meadow's reading column (`PageBody variant="column"`).

The page's heading, then the step strip (WizardHeader: Meadow's Steps, a dot for a step to come, the current one in the accent, a tick once a step is left filled), then the current step, its Back and Continue at its end. Each step checks itself as it is left: Continue on a step with a missing answer keeps the step, writes the reason under the refused field (ChoiceGroup's `error`, FieldInvalid: marked invalid, read out at once) and focuses it; the reason goes as soon as the answer is given. Back goes one step back and keeps every answer (every panel stays mounted and the answers live in one state). The review lists the answers in a band of properties, each with Change, which returns to that step. The last step's Plan visit shows the done state in the flow's place (its heading focused), and Plan another empties the answers and starts again. Keys are the parts' own: Tab between fields; the arrows move between the sites; a select opens on Space, Enter or the arrows. Light, dark, phone and desktop are the parts' own: add no class for them.

```tsx
// src/screens/visits.tsx: planning a site visit in steps, its review, then the visit planned
import { type MouseEvent, useEffect, useRef, useState } from 'react';
import { AppFramePanel } from '@/components/goop/patterns/app-frame';
import { PageBody } from '@/components/goop/patterns/page-body';
import { Button } from '@/components/ui/goop/button';
import { ChoiceGroup, ChoiceGroupItem } from '@/components/ui/goop/choice-group';
import {
  Empty,
  EmptyContent,
  EmptyDescription,
  EmptyHeader,
  EmptyMedia,
  EmptyTitle,
} from '@/components/ui/goop/empty';
import { Field } from '@/components/ui/goop/field';
import { FieldInvalid } from '@/components/ui/goop/field-error';
import { IconTile, IconTileIcon } from '@/components/ui/goop/icon-tile';
import {
  PageHeader,
  PageHeaderContent,
  PageHeaderDescription,
  PageHeaderTitle,
} from '@/components/ui/goop/page-header';
import { Properties, PropertyRow } from '@/components/ui/goop/properties';
import { RadioGroup, RadioGroupItem } from '@/components/ui/goop/radio-group';
import {
  Select,
  SelectContent,
  SelectIcon,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from '@/components/ui/goop/select';
import { Switch } from '@/components/ui/goop/switch';
import { Textarea } from '@/components/ui/goop/textarea';
import {
  Wizard,
  WizardFooter,
  WizardHeader,
  WizardNext,
  WizardPanel,
  WizardPrevious,
} from '@/components/ui/goop/wizard';
import { ScreenFrame, ScreenTopBar } from './frame';
import { PEOPLE } from './sample';

// ---- the sample choices: swap them for yours
const SITES = [
  { value: 'north-hedge', words: 'North hedge', line: 'The new planting along the top field' },
  { value: 'riverside', words: 'Riverside orchards', line: 'Twelve rows of apple and pear' },
  { value: 'greenhouse', words: 'Greenhouse', line: 'Benches along the south wall' },
];
const DAYS = [
  { value: '2026-11-30', words: 'Monday 30 November' },
  { value: '2026-12-01', words: 'Tuesday 1 December' },
  { value: '2026-12-02', words: 'Wednesday 2 December' },
  { value: '2026-12-03', words: 'Thursday 3 December' },
];
const TIMES = ['8:00 am', '9:00 am', '11:00 am', '2:00 pm'];

// ---- the flow
type Step = 'site' | 'when' | 'crew' | 'review';
interface Answers {
  site: string;
  day: string;
  time: string;
  lead: string;
  note: string;
  remind: boolean;
}
const EMPTY: Answers = { site: '', day: '', time: '9:00 am', lead: '', note: '', remind: true };
const ORDER: readonly Step[] = ['site', 'when', 'crew', 'review'];
const LABELS: Record<Step, string> = { site: 'Site', when: 'When', crew: 'Crew', review: 'Review' };

/** What keeps each step from being left: a missing answer's reason, or nothing. */
function problemsOf(answers: Answers): Record<Step, string | undefined> {
  return {
    site: answers.site ? undefined : 'Choose a site.',
    when: answers.day ? undefined : 'Choose a day.',
    crew: answers.lead ? undefined : 'Choose who leads the visit.',
    review: undefined,
  };
}

const wordsOf = (list: readonly { value: string; words: string }[], value: string) =>
  list.find((one) => one.value === value)?.words ?? '';

export default function VisitsScreen() {
  const [step, setStep] = useState<Step>('site');
  const [answers, setAnswers] = useState<Answers>(EMPTY);
  // the steps whose Continue was refused: their reasons show (and go as the answer is given)
  const [tried, setTried] = useState<readonly Step[]>([]);
  const [refusals, setRefusals] = useState(0);
  const [done, setDone] = useState(false);
  const flow = useRef<HTMLDivElement>(null);
  const doneHeading = useRef<HTMLHeadingElement>(null);
  const problems = problemsOf(answers);
  const shown = (one: Step) => (tried.includes(one) ? problems[one] : undefined);
  const answer = (change: Partial<Answers>) => setAnswers((now) => ({ ...now, ...change }));
  const at = ORDER.indexOf(step);

  // a refused Continue: the focus to the refused field of the step shown (a group's first control, as the sites')
  useEffect(() => {
    if (!refusals) return;
    const refused = flow.current?.querySelector<HTMLElement>(
      '[data-slot="wizard-panel"]:not([hidden]) [aria-invalid="true"]',
    );
    const control = refused?.matches('input, textarea, button')
      ? refused
      : refused?.querySelector<HTMLElement>('input, textarea, button');
    control?.focus();
  }, [refusals]);
  // done: the focus to the done state's heading, so its words are read
  useEffect(() => {
    if (done) doneHeading.current?.focus();
  }, [done]);

  const next = (event: MouseEvent<HTMLButtonElement>) => {
    if (!problems[step]) return;
    event.preventDefault();
    setTried((now) => (now.includes(step) ? now : [...now, step]));
    setRefusals((count) => count + 1);
  };
  const again = () => {
    setAnswers(EMPTY);
    setTried([]);
    setStep('site');
    setDone(false);
  };
  /** An answer in the review, with the way back to its step. */
  const reviewed = (words: string, to: Step) => (
    <span className="flex grow items-center justify-between gap-3">
      {words}
      <Button variant="ghost" size="sm" aria-label={`Change ${LABELS[to].toLowerCase()}`} onClick={() => setStep(to)}>
        Change
      </Button>
    </span>
  );

  return (
    <ScreenFrame>
      <AppFramePanel header={<ScreenTopBar title="Plan a visit" />}>
        <PageBody variant="column">
          <PageHeader>
            <PageHeaderContent>
              <PageHeaderTitle asChild>
                <h1>Plan a site visit</h1>
              </PageHeaderTitle>
              <PageHeaderDescription>Where the crew goes, when, and who leads.</PageHeaderDescription>
            </PageHeaderContent>
          </PageHeader>
          {done ? (
            <Empty>
              <EmptyHeader>
                <EmptyMedia>
                  <IconTile>
                    <IconTileIcon icon="circle-check" />
                  </IconTile>
                </EmptyMedia>
                <EmptyTitle asChild>
                  <h2 ref={doneHeading} tabIndex={-1}>
                    Visit planned
                  </h2>
                </EmptyTitle>
                <EmptyDescription>
                  {wordsOf(SITES, answers.site)}, {wordsOf(DAYS, answers.day)} at {answers.time}, led by {answers.lead}.
                </EmptyDescription>
              </EmptyHeader>
              <EmptyContent>
                <Button onClick={again}>Plan another</Button>
              </EmptyContent>
            </Empty>
          ) : (
            <Wizard
              ref={flow}
              aria-label="Plan a site visit"
              steps={ORDER.map((one, index) => ({
                value: one,
                label: LABELS[one],
                complete: index < at && !problems[one],
              }))}
              value={step}
              onValueChange={(to) => setStep(to as Step)}
            >
              <WizardHeader label="Visit steps" />
              <WizardPanel value="site" title="Which site?" description="The place the crew goes.">
                <ChoiceGroup label="Site" error={shown('site')}>
                  <RadioGroup name="site" value={answers.site} onValueChange={(site) => answer({ site })}>
                    {SITES.map((site) => (
                      <ChoiceGroupItem key={site.value} label={site.words} description={site.line}>
                        <RadioGroupItem value={site.value} />
                      </ChoiceGroupItem>
                    ))}
                  </RadioGroup>
                </ChoiceGroup>
              </WizardPanel>
              <WizardPanel value="when" title="When?" description="The day and the hour the crew meets there.">
                <ul>
                  <Field as="li" label="Day" description="This week or the next.">
                    {(control) => (
                      <FieldInvalid {...control} error={shown('when')}>
                        {(wired) => (
                          <Select value={answers.day} onValueChange={(day) => answer({ day })}>
                            <SelectTrigger {...wired}>
                              <SelectValue placeholder="Choose a day" />
                              <SelectIcon />
                            </SelectTrigger>
                            <SelectContent searchLabel="Day" search={false}>
                              {DAYS.map((day) => (
                                <SelectItem key={day.value} value={day.value}>
                                  {day.words}
                                </SelectItem>
                              ))}
                            </SelectContent>
                          </Select>
                        )}
                      </FieldInvalid>
                    )}
                  </Field>
                  <Field as="li" label="Time" description="When the crew meets at the site.">
                    {(control) => (
                      <Select value={answers.time} onValueChange={(time) => answer({ time })}>
                        <SelectTrigger {...control}>
                          <SelectValue />
                          <SelectIcon />
                        </SelectTrigger>
                        <SelectContent searchLabel="Time" search={false}>
                          {TIMES.map((time) => (
                            <SelectItem key={time} value={time}>
                              {time}
                            </SelectItem>
                          ))}
                        </SelectContent>
                      </Select>
                    )}
                  </Field>
                </ul>
              </WizardPanel>
              <WizardPanel value="crew" title="Who goes?" description="The visit's lead, and a word for the crew.">
                <ul>
                  <Field as="li" label="Lead" description="They get the visit on their calendar.">
                    {(control) => (
                      <FieldInvalid {...control} error={shown('crew')}>
                        {(wired) => (
                          <Select value={answers.lead} onValueChange={(lead) => answer({ lead })}>
                            <SelectTrigger {...wired}>
                              <SelectValue placeholder="Choose a lead" />
                              <SelectIcon />
                            </SelectTrigger>
                            <SelectContent searchLabel="Lead" search={false}>
                              {PEOPLE.map((person) => (
                                <SelectItem key={person} value={person}>
                                  {person}
                                </SelectItem>
                              ))}
                            </SelectContent>
                          </Select>
                        )}
                      </FieldInvalid>
                    )}
                  </Field>
                  <Field as="li" label="Note for the crew" description="What to bring, where to park.">
                    <Textarea value={answers.note} onChange={(event) => answer({ note: event.currentTarget.value })} />
                  </Field>
                  <Field as="li" label="Remind the crew" description="A note the evening before.">
                    {(control) => (
                      <Switch {...control} checked={answers.remind} onCheckedChange={(remind) => answer({ remind })} />
                    )}
                  </Field>
                </ul>
              </WizardPanel>
              <WizardPanel value="review" title="Check the visit" description="Change anything before you plan it.">
                <Properties variant="band" aria-label="The visit">
                  <PropertyRow label="Site">{reviewed(wordsOf(SITES, answers.site), 'site')}</PropertyRow>
                  <PropertyRow label="When">
                    {reviewed(`${wordsOf(DAYS, answers.day)} at ${answers.time}`, 'when')}
                  </PropertyRow>
                  <PropertyRow label="Lead">{reviewed(answers.lead, 'crew')}</PropertyRow>
                  <PropertyRow label="Reminder">{answers.remind ? 'The evening before' : 'None'}</PropertyRow>
                </Properties>
              </WizardPanel>
              <WizardFooter>
                <WizardPrevious />
                <WizardNext finishLabel="Plan visit" onClick={next} onFinish={() => setDone(true)} />
              </WizardFooter>
            </Wizard>
          )}
        </PageBody>
      </AppFramePanel>
    </ScreenFrame>
  );
}
```

```tsx frame { words: 'Plan a visit', path: '/visits', icon: 'calendar-plus' },

```

```
