{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-07",
  "description": "A profile form with your photo, name, email, time zone and theme, a save bar that shows once something changes, and a new email confirmed before it takes effect.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/announcements.json",
    "button",
    "field",
    "input",
    "https://www.dashboardblocks.com/r/radix/option-select.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/forms.json",
    "https://www.dashboardblocks.com/r/radix/team.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/settings/settings-07.tsx",
      "content": "'use client'\n\nimport {\n  Announcements,\n  useAnnouncements,\n} from '@/registry/components/dashboardblocks/announcements'\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type FormErrors,\n  FormSection,\n  isEmail,\n  SaveBar,\n  useSimpleForm,\n} from '@/registry/components/dashboardblocks/forms'\nimport { OptionSelect } from '@/registry/components/dashboardblocks/option-select'\nimport { PersonAvatar } from '@/registry/components/dashboardblocks/team'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  type FormEvent,\n  type ReactNode,\n  startTransition,\n  useEffect,\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} from '@/components/ui/field'\nimport { Input } from '@/components/ui/input'\n\nimport { cn } from '@/lib/utils'\n\ntype Theme = 'light' | 'dark' | 'system'\n\ninterface Profile {\n  avatar?: string\n  email: string\n  name: string\n  theme: Theme\n  /** An IANA time zone, e.g. */\n  timeZone: string\n}\n\n/** Why the server refused a field, shown under it. */\ntype ProfileErrors = Partial<Record<'email' | 'name', string>>\n\ninterface TimeZoneOption {\n  label: string\n  value: string\n}\n\ninterface Settings7Props extends BlockStateProps {\n  description: string\n  /** Called with the chosen image, or `null` when the photo is removed. Leave out to hide Upload photo. */\n  onAvatarChange?: (file: File | null) => void\n  /** Resolve to field errors to refuse the change. */\n  onSave?: (profile: Profile) => void | ProfileErrors | Promise<void | ProfileErrors>\n  /** Leave out to show the empty state. */\n  profile?: Profile\n  timeZones: TimeZoneOption[]\n  title: string\n}\n\ntype ProfileValues = Omit<Profile, 'avatar'> & { avatar: string }\n\nconst exampleProps: Settings7Props = {\n  description: 'How you appear to others in the workspace, and how the app looks to you.',\n  onAvatarChange: () => {},\n  profile: {\n    avatar: '/images/avatar-05.webp',\n    email: 'amara@acme.co',\n    name: 'Amara Okafor',\n    theme: 'system',\n    timeZone: 'Europe/London',\n  },\n  timeZones: [\n    { label: 'Los Angeles (GMT−7)', value: 'America/Los_Angeles' },\n    { label: 'New York (GMT−4)', value: 'America/New_York' },\n    { label: 'London (GMT+1)', value: 'Europe/London' },\n    { label: 'Berlin (GMT+2)', value: 'Europe/Berlin' },\n    { label: 'Lagos (GMT+1)', value: 'Africa/Lagos' },\n    { label: 'Singapore (GMT+8)', value: 'Asia/Singapore' },\n    { label: 'Tokyo (GMT+9)', value: 'Asia/Tokyo' },\n  ],\n  title: 'Profile',\n}\n\nconst themes: { icon: ReactNode; label: string; value: Theme }[] = [\n  {\n    icon: (\n      <IconPlaceholder\n        lucide='SunIcon'\n        tabler='IconSun'\n        hugeicons='Sun03Icon'\n        phosphor='SunIcon'\n        remixicon='RiSunLine'\n      />\n    ),\n    label: 'Light',\n    value: 'light',\n  },\n  {\n    icon: (\n      <IconPlaceholder\n        lucide='MoonIcon'\n        tabler='IconMoon'\n        hugeicons='Moon02Icon'\n        phosphor='MoonIcon'\n        remixicon='RiMoonLine'\n      />\n    ),\n    label: 'Dark',\n    value: 'dark',\n  },\n  {\n    icon: (\n      <IconPlaceholder\n        lucide='MonitorIcon'\n        tabler='IconDeviceDesktop'\n        hugeicons='ComputerIcon'\n        phosphor='MonitorIcon'\n        remixicon='RiComputerLine'\n      />\n    ),\n    label: 'System',\n    value: 'system',\n  },\n]\n\nconst MAX_AVATAR_BYTES = 2 * 1024 * 1024\n\nfunction validate(values: ProfileValues): FormErrors<ProfileValues> {\n  return {\n    email: !values.email.trim()\n      ? 'Enter your email address.'\n      : !isEmail(values.email.trim())\n        ? 'Enter an email address like name@example.com.'\n        : undefined,\n    name: values.name.trim() ? undefined : 'Enter your name.',\n  }\n}\n\nfunction Settings7Content(props: Settings7Props & { profile: Profile }) {\n  const { onAvatarChange, onSave, profile, timeZones } = props\n  const fileInput = useRef<HTMLInputElement>(null)\n  const [avatarError, setAvatarError] = useState<string | null>(null)\n  const [notice, setNotice] = useState<{\n    text: string\n    tone: 'error' | 'saved'\n  } | null>(null)\n  const [said, announce] = useAnnouncements()\n  const form = useSimpleForm<ProfileValues>({\n    defaultValues: { ...profile, avatar: profile.avatar ?? '' },\n    onSubmit: (values) =>\n      onSave?.({\n        ...values,\n        avatar: values.avatar || undefined,\n        email: values.email.trim().toLowerCase(),\n        name: values.name.trim(),\n      }),\n    validate,\n  })\n  const { values } = form\n  const changes = form.changedFields.length\n  const emailChanged = form.changedFields.includes('email')\n\n  const objectUrls = useRef<string[]>([])\n  useEffect(() => {\n    const urls = objectUrls.current\n    return () => urls.forEach((url) => URL.revokeObjectURL(url))\n  }, [])\n\n  const chooseAvatar = (file: File | undefined) => {\n    if (!file) return\n    if (!file.type.startsWith('image/')) return setAvatarError('Choose an image file.')\n    if (file.size > MAX_AVATAR_BYTES) return setAvatarError('Choose an image under 2 MB.')\n    setAvatarError(null)\n    const url = URL.createObjectURL(file)\n    objectUrls.current.push(url)\n    form.setValue('avatar', url)\n    setNotice(null)\n    onAvatarChange?.(file)\n  }\n\n  const removeAvatar = () => {\n    form.setValue('avatar', '')\n    setAvatarError(null)\n    setNotice(null)\n    onAvatarChange?.(null)\n  }\n\n  const say = (text: string, tone: 'error' | 'saved') => {\n    setNotice({ text, tone })\n    announce(text)\n  }\n\n  const save = async (event: FormEvent<HTMLFormElement>) => {\n    const email = values.email.trim().toLowerCase()\n    const confirmEmail = emailChanged\n    setNotice(null)\n    try {\n      await form.submit(event, {\n        onSaved: () =>\n          say(confirmEmail ? `Saved. Check ${email} to confirm it.` : 'Saved.', 'saved'),\n      })\n    } catch {\n      startTransition(() => say('Couldn’t save your profile. Try again.', 'error'))\n    }\n  }\n\n  return (\n    <>\n      <form method='post' noValidate onSubmit={(event) => void save(event)}>\n        <div className='flex flex-col gap-6'>\n          <FormSection\n            title='Your details'\n            description='Your photo, name and email address.'\n          >\n            <FieldGroup>\n              <div className='flex items-center gap-4'>\n                <PersonAvatar\n                  person={{\n                    avatar: values.avatar || undefined,\n                    name: values.name || profile.name,\n                  }}\n                  size='lg'\n                  className='size-16'\n                />\n                <div className='flex flex-col gap-2'>\n                  <div className='flex flex-wrap gap-2'>\n                    {onAvatarChange && (\n                      <Button\n                        type='button'\n                        variant='outline'\n                        size='sm'\n                        aria-describedby={`${form.getId('avatar')}-hint`}\n                        onClick={() => fileInput.current?.click()}\n                      >\n                        <IconPlaceholder\n                          lucide='UploadIcon'\n                          tabler='IconUpload'\n                          hugeicons='Upload01Icon'\n                          phosphor='UploadSimpleIcon'\n                          remixicon='RiUploadLine'\n                          data-icon='inline-start'\n                          aria-hidden\n                        />\n                        {values.avatar ? 'Change photo' : 'Upload photo'}\n                      </Button>\n                    )}\n                    {values.avatar && (\n                      <Button\n                        type='button'\n                        variant='ghost'\n                        size='sm'\n                        onClick={removeAvatar}\n                      >\n                        <IconPlaceholder\n                          lucide='Trash2Icon'\n                          tabler='IconTrash'\n                          hugeicons='Delete02Icon'\n                          phosphor='TrashIcon'\n                          remixicon='RiDeleteBinLine'\n                          data-icon='inline-start'\n                        />\n                        {onAvatarChange ? 'Remove' : 'Remove photo'}\n                      </Button>\n                    )}\n                  </div>\n                  {onAvatarChange && (\n                    <>\n                      <p\n                        id={`${form.getId('avatar')}-hint`}\n                        className={cn(\n                          'text-xs',\n                          avatarError ? 'text-destructive' : 'text-muted-foreground',\n                        )}\n                      >\n                        {avatarError ?? 'JPG, PNG or GIF, up to 2 MB.'}\n                      </p>\n                      <input\n                        ref={fileInput}\n                        type='file'\n                        accept='image/*'\n                        tabIndex={-1}\n                        aria-hidden\n                        className='sr-only'\n                        onChange={(event) => {\n                          chooseAvatar(event.target.files?.[0])\n                          event.target.value = ''\n                        }}\n                      />\n                    </>\n                  )}\n                </div>\n              </div>\n              <Field data-invalid={form.errors.name ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('name')}>Name</FieldLabel>\n                <Input autoComplete='name' {...form.field('name')} />\n                <FieldError {...form.error('name')} />\n              </Field>\n              <Field data-invalid={form.errors.email ? true : undefined}>\n                <FieldLabel htmlFor={form.getId('email')}>Email</FieldLabel>\n                <Input type='email' autoComplete='email' {...form.field('email')} />\n                {emailChanged && !form.errors.email && (\n                  <FieldDescription>\n                    We’ll send a link to the new address. It changes once you confirm.\n                  </FieldDescription>\n                )}\n                <FieldError {...form.error('email')} />\n              </Field>\n            </FieldGroup>\n          </FormSection>\n          <FormSection\n            title='Preferences'\n            description='Your time zone, and how the app looks.'\n          >\n            <FieldGroup>\n              <Field>\n                <FieldLabel htmlFor={form.getId('timeZone')}>Time zone</FieldLabel>\n                <OptionSelect\n                  className='w-full'\n                  options={timeZones}\n                  {...form.select('timeZone')}\n                />\n                <FieldDescription>\n                  Used for dates in dashboards, reports and email digests.\n                </FieldDescription>\n              </Field>\n              <fieldset className='flex flex-col gap-3'>\n                <legend className='mb-3 text-sm font-medium'>Theme</legend>\n                <div className='grid grid-cols-3 gap-2'>\n                  {themes.map((theme) => (\n                    <label\n                      key={theme.value}\n                      className='has-checked:border-primary has-checked:ring-primary has-focus-visible:ring-ring/50 flex cursor-pointer flex-col items-center gap-2 rounded-lg border p-3 text-sm has-checked:ring-1 has-focus-visible:ring-3 [&_svg]:size-5'\n                    >\n                      <input\n                        type='radio'\n                        name={form.getId('theme')}\n                        value={theme.value}\n                        checked={values.theme === theme.value}\n                        onChange={() => form.setValue('theme', theme.value)}\n                        className='sr-only'\n                      />\n                      <span aria-hidden className='text-muted-foreground'>\n                        {theme.icon}\n                      </span>\n                      {theme.label}\n                    </label>\n                  ))}\n                </div>\n              </fieldset>\n            </FieldGroup>\n          </FormSection>\n        </div>\n        {notice && (notice.tone === 'error' || !form.isDirty) && (\n          <p\n            className={cn(\n              'mt-4 text-sm',\n              notice.tone === 'error' ? 'text-destructive' : 'text-muted-foreground',\n            )}\n          >\n            {notice.text}\n          </p>\n        )}\n        <Announcements said={said} />\n        <SaveBar\n          className='mt-6'\n          isDirty={form.isDirty}\n          isSubmitting={form.isSubmitting}\n          message={`${changes} unsaved ${changes === 1 ? 'change' : 'changes'}`}\n          onDiscard={() => {\n            form.reset()\n            setAvatarError(null)\n            setNotice(null)\n          }}\n        />\n      </form>\n    </>\n  )\n}\n\nconst Settings7 = (props: Settings7Props) => {\n  const { description, profile, errorMessage, status, title } = props\n  const ready = !status && profile !== undefined\n\n  return (\n    <BlockStateProvider\n      errorMessage={errorMessage}\n      state={getBlockState(status, profile)}\n    >\n      <section className='@container flex flex-col gap-3'>\n        <header className='flex flex-col gap-0.5'>\n          <h2 className='font-semibold tracking-tight'>{title}</h2>\n          <p className='text-muted-foreground text-sm'>{description}</p>\n        </header>\n        {ready ? (\n          <Settings7Content {...props} profile={profile} />\n        ) : (\n          <div className='border-t'>\n            <BlockStateRows rows={6} />\n          </div>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Settings7,\n  exampleProps as settings7ExampleProps,\n  type Profile,\n  type ProfileErrors,\n  type Settings7Props,\n  type Theme,\n  type TimeZoneOption,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/settings/settings-07.tsx"
    }
  ],
  "meta": {
    "shows": "A profile form with your photo, name, email, time zone and theme, a save bar that shows once something changes, and a new email confirmed before it takes effect.",
    "size": "half",
    "usedWith": [
      "security-05",
      "settings-03"
    ],
    "component": "Settings7",
    "props": "{ description: string; onAvatarChange?: (file: null | File) => void; onSave?: (profile: { avatar?: string; email: string; name: string; theme: \"light\" | \"dark\" | \"system\"; timeZone: string }) => void | { name?: string; email?: string } | Promise<void | { name?: string; email?: string }>; profile?: { avatar?: string; email: string; name: string; theme: \"light\" | \"dark\" | \"system\"; timeZone: string }; timeZones: { label: string; value: string }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
