{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-06",
  "description": "Transferring, archiving and deleting a workspace, with the new owner picked from the admins and deletion confirmed by typing the workspace name.",
  "registryDependencies": [
    "button",
    "input",
    "https://www.dashboardblocks.com/r/radix/locked-note.json",
    "https://www.dashboardblocks.com/r/radix/option-select.json",
    "https://www.dashboardblocks.com/r/radix/settings.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/settings/settings-06.tsx",
      "content": "'use client'\n\nimport { LockedNote } from '@/registry/components/dashboardblocks/locked-note'\nimport {\n  OptionSelect,\n  type SelectOption,\n} from '@/registry/components/dashboardblocks/option-select'\nimport { SettingsRow } from '@/registry/components/dashboardblocks/settings'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport {\n  type FormEvent,\n  type KeyboardEvent,\n  startTransition,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Input } from '@/components/ui/input'\n\ninterface DangerChoice {\n  label: string\n  options: readonly SelectOption[]\n  placeholder?: string\n}\n\ninterface DangerAction {\n  action: string\n  /** Asks the person to pick one of `options` before the action runs, such as who to hand the workspace to. The pick goes to `onAction`. */\n  choose?: DangerChoice\n  /** Asks the person to type the workspace name before the action runs. */\n  confirm?: boolean\n  description: string\n  disabled?: boolean\n  id: string\n  label: string\n}\n\ninterface Settings6Props {\n  actions: DangerAction[]\n  description: string\n  /** Why the actions are off, shown under the description when the block gets no `onAction`: `Only Sofia Rossi, the owner, can do either.` */\n  lockedMessage?: string\n  /**\n   * `choice` is the value picked from the action's `choose`, for an action that has one. Return a\n   * promise to keep the action's form open, and every action off, until it settles. Left out,\n   * every action is off.\n   */\n  onAction?: (id: string, choice?: string) => void | Promise<unknown>\n  title: string\n  workspace: string\n}\n\nconst exampleProps: Settings6Props = {\n  actions: [\n    {\n      action: 'Transfer',\n      choose: {\n        label: 'New owner',\n        options: [\n          { label: 'Maya Chen', value: 'maya' },\n          { label: 'Leo Martins', value: 'leo' },\n        ],\n        placeholder: 'Pick an admin',\n      },\n      description: 'Make another admin the owner. You will become an admin.',\n      id: 'transfer',\n      label: 'Transfer ownership',\n    },\n    {\n      action: 'Archive',\n      description:\n        'Stop syncs and alerts, and make dashboards read-only. You can restore it later.',\n      id: 'archive',\n      label: 'Archive workspace',\n    },\n    {\n      action: 'Delete',\n      confirm: true,\n      description:\n        'Permanently delete the workspace, its dashboards, data sources and API keys. This can’t be undone.',\n      id: 'delete',\n      label: 'Delete workspace',\n    },\n  ],\n  description: 'Actions that affect everyone in the workspace.',\n  title: 'Danger zone',\n  workspace: 'acme-analytics',\n}\n\nconst Settings6 = (props: Settings6Props) => {\n  const { actions, description, lockedMessage, onAction, title, workspace } = props\n  const locked = !onAction\n  const id = useId()\n  const [confirming, setConfirming] = useState<string | null>(null)\n  const [typed, setTyped] = useState('')\n  const [choice, setChoice] = useState<string | null>(null)\n  const buttons = useRef<Record<string, HTMLButtonElement | null>>({})\n  const firstField = useRef<HTMLElement | null>(null)\n  const focusAfterRender = useRef<(() => HTMLElement | null) | null>(null)\n  const section = useRef<HTMLElement>(null)\n  const heading = useRef<HTMLHeadingElement>(null)\n  const lockedFor = useRef(locked)\n  const [running, setRunning] = useState<string | null>(null)\n  const [settled, setSettled] = useState({ count: 0, id: '' })\n  const settledFor = useRef(0)\n\n  useEffect(() => {\n    focusAfterRender.current?.()?.focus()\n    focusAfterRender.current = null\n  })\n\n  useEffect(() => {\n    if (locked === lockedFor.current) return\n    lockedFor.current = locked\n    const active = document.activeElement\n    if (locked && (active === document.body || section.current?.contains(active)))\n      heading.current?.focus()\n  }, [locked])\n\n  useEffect(() => {\n    if (settled.count === settledFor.current) return\n    settledFor.current = settled.count\n    const button = buttons.current[settled.id]\n    ;(button && !button.disabled ? button : heading.current)?.focus()\n  }, [settled])\n\n  const asks = (item: DangerAction) => item.confirm || !!item.choose\n  const ready = (item: DangerAction) =>\n    (!item.confirm || typed === workspace) &&\n    (!item.choose || item.choose.options.some((option) => option.value === choice))\n\n  const reset = () => {\n    setConfirming(null)\n    setTyped('')\n    setChoice(null)\n  }\n\n  const close = (actionId: string) => {\n    reset()\n    focusAfterRender.current = () => {\n      const button = buttons.current[actionId]\n      return button && !button.disabled ? button : heading.current\n    }\n  }\n\n  const confirm = (event: FormEvent<HTMLFormElement>, item: DangerAction) => {\n    event.preventDefault()\n    if (!ready(item) || running) return\n    const result = onAction?.(item.id, choice ?? undefined)\n    if (!result) return close(item.id)\n    setRunning(item.id)\n    void result.finally(() =>\n      startTransition(() => {\n        setRunning(null)\n        reset()\n        setSettled((previous) => ({ count: previous.count + 1, id: item.id }))\n      }),\n    )\n  }\n\n  const onFormKeyDown = (event: KeyboardEvent<HTMLFormElement>, item: DangerAction) => {\n    if (event.key !== 'Escape' || event.defaultPrevented || running) return\n    if (!event.currentTarget.contains(event.target as Node)) return\n    event.preventDefault()\n    close(item.id)\n  }\n\n  return (\n    <section ref={section} className='@container flex flex-col gap-3'>\n      <header className='flex flex-col gap-0.5'>\n        <h2\n          ref={heading}\n          tabIndex={-1}\n          className='font-semibold tracking-tight outline-none'\n        >\n          {title}\n        </h2>\n        <p className='text-muted-foreground text-sm'>{description}</p>\n        {locked && lockedMessage && <LockedNote>{lockedMessage}</LockedNote>}\n      </header>\n      <ul className='flex flex-col divide-y border-t'>\n        {actions.map((item) => {\n          const open = confirming === item.id && !locked\n          return (\n            <li key={item.id} className='flex flex-col gap-3 py-3'>\n              <SettingsRow\n                id={`${id}-${item.id}`}\n                label={item.label}\n                description={item.description}\n              >\n                <Button\n                  ref={(node) => {\n                    buttons.current[item.id] = node\n                  }}\n                  variant={item.confirm ? 'destructive' : 'outline'}\n                  size='sm'\n                  disabled={item.disabled || locked || running !== null}\n                  aria-describedby={`${id}-${item.id}-description`}\n                  aria-expanded={asks(item) ? open : undefined}\n                  aria-controls={open ? `${id}-${item.id}-form` : undefined}\n                  onClick={() => {\n                    if (!asks(item)) return onAction?.(item.id)\n                    if (open) return close(item.id)\n                    setConfirming(item.id)\n                    setTyped('')\n                    setChoice(null)\n                    focusAfterRender.current = () => firstField.current\n                  }}\n                >\n                  {item.action}\n                </Button>\n              </SettingsRow>\n              {open && (\n                // oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- Escape from any field in the form closes it, as Cancel does\n                <form\n                  method='post'\n                  id={`${id}-${item.id}-form`}\n                  onSubmit={(event) => confirm(event, item)}\n                  onKeyDown={(event) => onFormKeyDown(event, item)}\n                  className='flex flex-col gap-3 rounded-lg border p-4'\n                >\n                  {item.choose && (\n                    <div className='flex flex-col gap-2'>\n                      <label htmlFor={`${id}-${item.id}-choice`} className='text-sm'>\n                        {item.choose.label}\n                      </label>\n                      <OptionSelect\n                        ref={(node) => {\n                          firstField.current = node\n                        }}\n                        id={`${id}-${item.id}-choice`}\n                        className='w-full'\n                        options={item.choose.options}\n                        placeholder={item.choose.placeholder}\n                        value={choice}\n                        onValueChange={setChoice}\n                      />\n                    </div>\n                  )}\n                  {item.confirm && (\n                    <div className='flex flex-col gap-2'>\n                      <label htmlFor={`${id}-${item.id}-confirm`} className='text-sm'>\n                        Type{' '}\n                        <strong className='font-mono font-semibold'>{workspace}</strong>{' '}\n                        to confirm.\n                      </label>\n                      <Input\n                        ref={(node) => {\n                          if (!item.choose) firstField.current = node\n                        }}\n                        id={`${id}-${item.id}-confirm`}\n                        autoComplete='off'\n                        spellCheck={false}\n                        value={typed}\n                        onChange={(event) => setTyped(event.target.value)}\n                      />\n                    </div>\n                  )}\n                  <div className='flex flex-wrap justify-end gap-2'>\n                    <Button\n                      type='button'\n                      variant='ghost'\n                      disabled={running !== null}\n                      onClick={() => close(item.id)}\n                    >\n                      Cancel\n                    </Button>\n                    <Button\n                      type='submit'\n                      variant={item.confirm ? 'destructive' : 'default'}\n                      disabled={!ready(item) || running !== null}\n                      aria-busy={running === item.id ? true : undefined}\n                    >\n                      {running === item.id && (\n                        <IconPlaceholder\n                          lucide='Loader2Icon'\n                          tabler='IconLoader'\n                          hugeicons='Loading03Icon'\n                          phosphor='SpinnerIcon'\n                          remixicon='RiLoaderLine'\n                          data-icon='inline-start'\n                          className='animate-spin motion-reduce:animate-none'\n                        />\n                      )}\n                      {item.label}\n                    </Button>\n                  </div>\n                </form>\n              )}\n            </li>\n          )\n        })}\n      </ul>\n    </section>\n  )\n}\n\nexport {\n  Settings6,\n  exampleProps as settings6ExampleProps,\n  type DangerAction,\n  type DangerChoice,\n  type Settings6Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/settings/settings-06.tsx"
    }
  ],
  "meta": {
    "shows": "Transferring, archiving and deleting a workspace, with the new owner picked from the admins and deletion confirmed by typing the workspace name.",
    "size": "half",
    "usedWith": [
      "settings-01",
      "security-06"
    ],
    "component": "Settings6",
    "props": "{ actions: { action: string; choose?: { label: string; options: { disabled?: boolean; icon?: ReactNode; label: string; value: string }[]; placeholder?: string }; confirm?: boolean; description: string; disabled?: boolean; id: string; label: string }[]; description: string; lockedMessage?: string; onAction?: (id: string, choice: string) => void | Promise<unknown>; title: string; workspace: string }"
  },
  "type": "registry:component"
}
