{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "onboarding-04",
  "description": "A short form asking for a role, a team size and up to three goals, then listing the dashboards set up for them.",
  "registryDependencies": [
    "button",
    "field",
    "https://www.dashboardblocks.com/r/radix/choice-cards.json",
    "https://www.dashboardblocks.com/r/radix/onboarding.json",
    "https://www.dashboardblocks.com/r/radix/option-select.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/onboarding/onboarding-04.tsx",
      "content": "'use client'\n\nimport {\n  type ChoiceCardOption,\n  ChoiceCards,\n} from '@/registry/components/dashboardblocks/choice-cards'\nimport { ActionCard } from '@/registry/components/dashboardblocks/onboarding'\nimport { OptionSelect } from '@/registry/components/dashboardblocks/option-select'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  type FormEvent,\n  startTransition,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport {\n  Field,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldLabel,\n  FieldTitle,\n} from '@/components/ui/field'\n\nimport { cn } from '@/lib/utils'\n\ninterface Goal extends ChoiceCardOption {\n  dashboard: { description: string; href: string; title: string }\n}\n\ntype Answers = {\n  goals: string[]\n  role: string\n  teamSize: string\n}\n\ninterface Onboarding4Props {\n  goals: Goal[]\n  maxGoals?: number\n  onSave?: (answers: Answers) => Promise<void>\n  roles: { label: string; value: string }[]\n  teamSizes: ChoiceCardOption[]\n}\n\nconst exampleProps: Onboarding4Props = {\n  goals: [\n    {\n      dashboard: {\n        description: 'MRR, expansion and churn by plan.',\n        href: '/dashboards/revenue',\n        title: 'Revenue overview',\n      },\n      description: 'MRR, expansion and churn.',\n      icon: (\n        <IconPlaceholder\n          lucide='TrendingUpIcon'\n          tabler='IconTrendingUp'\n          hugeicons='ChartUpIcon'\n          phosphor='TrendUpIcon'\n          remixicon='RiLineChartLine'\n        />\n      ),\n      title: 'Revenue growth',\n      value: 'revenue',\n    },\n    {\n      dashboard: {\n        description: 'Visits to paid, step by step and by channel.',\n        href: '/dashboards/acquisition',\n        title: 'Acquisition funnel',\n      },\n      description: 'Traffic, sign-ups and cost per sign-up.',\n      icon: (\n        <IconPlaceholder\n          lucide='TargetIcon'\n          tabler='IconTarget'\n          hugeicons='Target02Icon'\n          phosphor='TargetIcon'\n          remixicon='RiFocus3Line'\n        />\n      ),\n      title: 'Acquisition',\n      value: 'acquisition',\n    },\n    {\n      dashboard: {\n        description: 'Monthly cohorts and the accounts at risk.',\n        href: '/dashboards/retention',\n        title: 'Retention cohorts',\n      },\n      description: 'Cohorts, active users and churn risk.',\n      icon: (\n        <IconPlaceholder\n          lucide='UserCheckIcon'\n          tabler='IconUserCheck'\n          hugeicons='UserCheck01Icon'\n          phosphor='UserCheckIcon'\n          remixicon='RiUserFollowLine'\n        />\n      ),\n      title: 'Retention',\n      value: 'retention',\n    },\n    {\n      dashboard: {\n        description: 'Weekly users of each feature, and who stopped.',\n        href: '/dashboards/features',\n        title: 'Feature adoption',\n      },\n      description: 'Which features people use, and how often.',\n      icon: (\n        <IconPlaceholder\n          lucide='ZapIcon'\n          tabler='IconBolt'\n          hugeicons='FlashIcon'\n          phosphor='LightningIcon'\n          remixicon='RiFlashlightLine'\n        />\n      ),\n      title: 'Feature adoption',\n      value: 'features',\n    },\n    {\n      dashboard: {\n        description: 'Backlog, first response time and CSAT.',\n        href: '/dashboards/support',\n        title: 'Support health',\n      },\n      description: 'Ticket volume, response times and CSAT.',\n      icon: (\n        <IconPlaceholder\n          lucide='HeadphonesIcon'\n          tabler='IconHeadphones'\n          hugeicons='HeadphonesIcon'\n          phosphor='HeadphonesIcon'\n          remixicon='RiHeadphoneLine'\n        />\n      ),\n      title: 'Customer support',\n      value: 'support',\n    },\n    {\n      dashboard: {\n        description: \"Today's orders, late shipments and low stock.\",\n        href: '/dashboards/operations',\n        title: 'Operations daily',\n      },\n      description: 'Orders, fulfilment and stock.',\n      icon: (\n        <IconPlaceholder\n          lucide='TruckIcon'\n          tabler='IconTruck'\n          hugeicons='DeliveryTruck01Icon'\n          phosphor='TruckIcon'\n          remixicon='RiTruckLine'\n        />\n      ),\n      title: 'Operations',\n      value: 'operations',\n    },\n  ],\n  roles: [\n    { label: 'Founder or executive', value: 'executive' },\n    { label: 'Product manager', value: 'product' },\n    { label: 'Engineer', value: 'engineering' },\n    { label: 'Data analyst', value: 'data' },\n    { label: 'Marketing', value: 'marketing' },\n    { label: 'Sales or success', value: 'sales' },\n    { label: 'Operations or finance', value: 'operations' },\n  ],\n  teamSizes: [\n    { title: 'Just me', value: '1' },\n    { title: '2–10', value: '2-10' },\n    { title: '11–50', value: '11-50' },\n    { title: '51 or more', value: '51+' },\n  ],\n}\n\nasync function saveAnswers() {\n  await new Promise((resolve) => setTimeout(resolve, 800))\n}\n\ntype Errors = Partial<Record<keyof Answers, string>>\n\nfunction validate(answers: Answers, maxGoals: number): Errors {\n  return {\n    goals:\n      answers.goals.length === 0\n        ? 'Pick at least one goal.'\n        : answers.goals.length > maxGoals\n          ? `Pick up to ${maxGoals}. Unpick one to continue.`\n          : undefined,\n    role: answers.role ? undefined : 'Choose your role.',\n    teamSize: answers.teamSize ? undefined : 'Pick the size of your team.',\n  }\n}\n\nconst Onboarding4 = (props: Onboarding4Props) => {\n  const { goals, maxGoals = 3, onSave = saveAnswers, roles, teamSizes } = props\n  const id = useId()\n  const emptyAnswers: Answers = { goals: [], role: '', teamSize: '' }\n  const [answers, setAnswers] = useState(emptyAnswers)\n  const [submitted, setSubmitted] = useState(false)\n  const [saving, setSaving] = useState(false)\n  const [saved, setSaved] = useState(false)\n  const errors = submitted ? validate(answers, maxGoals) : {}\n  const fieldId = (name: keyof Answers) => `${id}-${name}`\n  const shownSaved = useRef(saved)\n\n  useEffect(() => {\n    if (shownSaved.current === saved) return\n    shownSaved.current = saved\n    document.getElementById(saved ? `${id}-result` : `${id}-role`)?.focus()\n  }, [id, saved])\n\n  function set<K extends keyof Answers>(name: K, value: Answers[K]) {\n    setAnswers((current) => ({ ...current, [name]: value }))\n  }\n\n  async function onSubmit(event: FormEvent<HTMLFormElement>) {\n    event.preventDefault()\n    setSubmitted(true)\n    const current = validate(answers, maxGoals)\n    const invalid = (['role', 'teamSize', 'goals'] as const).find((name) => current[name])\n    if (invalid) {\n      document.getElementById(fieldId(invalid))?.focus()\n      return\n    }\n    setSaving(true)\n    try {\n      await onSave(answers)\n      startTransition(() => setSaved(true))\n    } finally {\n      startTransition(() => setSaving(false))\n    }\n  }\n\n  if (saved) {\n    const picked = goals.filter((goal) => answers.goals.includes(goal.value))\n    return (\n      <section className='@container flex flex-col gap-4'>\n        <header className='flex flex-wrap items-start justify-between gap-3'>\n          <div className='flex min-w-0 flex-col gap-0.5'>\n            <h2\n              id={`${id}-result`}\n              tabIndex={-1}\n              className='font-semibold tracking-tight outline-none'\n            >\n              {picked.length === 1\n                ? 'Your dashboard is ready'\n                : `${picked.length} dashboards are ready`}\n            </h2>\n            <p className='text-muted-foreground text-sm'>\n              Built from your goals, with sample data until your sources sync.\n            </p>\n          </div>\n          <Button\n            size='sm'\n            variant='outline'\n            onClick={() => {\n              setSaved(false)\n              setSubmitted(false)\n            }}\n          >\n            Change answers\n          </Button>\n        </header>\n        <ul className='grid gap-x-8 gap-y-3 @lg:grid-cols-2'>\n          {picked.map((goal) => (\n            <li key={goal.value}>\n              <ActionCard\n                description={goal.dashboard.description}\n                href={goal.dashboard.href}\n                icon={goal.icon}\n                title={goal.dashboard.title}\n              />\n            </li>\n          ))}\n        </ul>\n      </section>\n    )\n  }\n\n  return (\n    <section className='@container'>\n      <form\n        method='post'\n        noValidate\n        onSubmit={(event) => void onSubmit(event)}\n        className='flex flex-col gap-4'\n      >\n        <header className='flex flex-col gap-0.5'>\n          <h2 className='font-semibold tracking-tight'>Tell us about your team</h2>\n          <p className='text-muted-foreground text-sm'>\n            Three questions, and we&apos;ll set up dashboards to match.\n          </p>\n        </header>\n        <div className='border-t pt-4'>\n          <FieldGroup>\n            <Field data-invalid={errors.role ? true : undefined}>\n              <FieldLabel htmlFor={fieldId('role')}>Your role</FieldLabel>\n              <OptionSelect\n                id={fieldId('role')}\n                className='w-full @md:w-72'\n                aria-invalid={errors.role ? true : undefined}\n                aria-describedby={errors.role ? `${fieldId('role')}-error` : undefined}\n                placeholder='Choose a role'\n                value={answers.role || null}\n                options={roles}\n                onValueChange={(role) => set('role', role)}\n              />\n              <FieldError id={`${fieldId('role')}-error`}>{errors.role}</FieldError>\n            </Field>\n            <div className='flex flex-col gap-3'>\n              <FieldTitle id={`${fieldId('teamSize')}-label`}>Team size</FieldTitle>\n              <ChoiceCards\n                id={fieldId('teamSize')}\n                aria-labelledby={`${fieldId('teamSize')}-label`}\n                aria-invalid={errors.teamSize ? true : undefined}\n                aria-describedby={\n                  errors.teamSize ? `${fieldId('teamSize')}-error` : undefined\n                }\n                className='grid-cols-2 @md:grid-cols-4'\n                options={teamSizes}\n                value={answers.teamSize}\n                onValueChange={(value) => set('teamSize', value)}\n              />\n              <FieldError id={`${fieldId('teamSize')}-error`}>\n                {errors.teamSize}\n              </FieldError>\n            </div>\n            <div className='flex flex-col gap-3'>\n              <div className='flex flex-col gap-1'>\n                <FieldTitle id={`${fieldId('goals')}-label`}>\n                  What do you want to track?\n                </FieldTitle>\n                <FieldDescription id={`${fieldId('goals')}-description`}>\n                  Pick up to {maxGoals}.{' '}\n                  <span\n                    className={cn(\n                      'tabular-nums',\n                      answers.goals.length > maxGoals && 'text-destructive',\n                    )}\n                  >\n                    {answers.goals.length} of {maxGoals} picked.\n                  </span>\n                </FieldDescription>\n              </div>\n              <ChoiceCards\n                type='checkbox'\n                id={fieldId('goals')}\n                aria-labelledby={`${fieldId('goals')}-label`}\n                aria-invalid={errors.goals ? true : undefined}\n                aria-describedby={`${fieldId('goals')}-description${errors.goals ? ` ${fieldId('goals')}-error` : ''}`}\n                className='@md:grid-cols-2'\n                options={goals}\n                value={answers.goals}\n                onValueChange={(value) => set('goals', value)}\n              />\n              <FieldError id={`${fieldId('goals')}-error`}>{errors.goals}</FieldError>\n            </div>\n          </FieldGroup>\n        </div>\n        <div className='flex justify-end border-t pt-4'>\n          <Button type='submit' disabled={saving}>\n            {saving ? 'Setting up' : 'Set up my dashboards'}\n          </Button>\n        </div>\n      </form>\n    </section>\n  )\n}\n\nexport { Onboarding4, exampleProps as onboarding4ExampleProps, type Onboarding4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/onboarding/onboarding-04.tsx"
    }
  ],
  "meta": {
    "shows": "A short form asking for a role, a team size and up to three goals, then listing the dashboards set up for them.",
    "size": "half",
    "usedWith": [
      "onboarding-03",
      "checklist-01"
    ],
    "component": "Onboarding4",
    "props": "{ goals: { dashboard: { description: string; href: string; title: string }; aside?: ReactNode; badge?: ReactNode; description?: ReactNode; disabled?: boolean; icon?: ReactNode; title: string; value: string }[]; maxGoals?: number; onSave?: (answers: { goals: string[]; role: string; teamSize: string }) => Promise<void>; roles: { label: string; value: string }[]; teamSizes: { aside?: ReactNode; badge?: ReactNode; description?: ReactNode; disabled?: boolean; icon?: ReactNode; title: string; value: string }[] }"
  },
  "type": "registry:component"
}
