{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-01",
  "description": "Invite people by email with a role, change roles, remove members and resend or revoke pending invites, counted against the plan's seats.",
  "registryDependencies": [
    "button",
    "input",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/details.json",
    "https://www.dashboardblocks.com/r/radix/settings.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json",
    "https://www.dashboardblocks.com/r/radix/team.json",
    "https://www.dashboardblocks.com/r/radix/format.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/settings/settings-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport {\n  type Role,\n  RoleMenu,\n  roleConfig,\n  roleOrder,\n} from '@/registry/components/dashboardblocks/settings'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport { PersonAvatar } from '@/registry/components/dashboardblocks/team'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatRelativeTime } from '@/registry/lib/dashboardblocks/format'\nimport { type FormEvent, useId, useState } from 'react'\nimport { flushSync } from 'react-dom'\n\nimport { Button } from '@/components/ui/button'\nimport { Input } from '@/components/ui/input'\n\ninterface Member {\n  avatar?: string\n  email: string\n  id: string\n  name: string\n  role: Role\n}\n\ninterface Invite {\n  email: string\n  id: string\n  role: Role\n  sentAt: Date\n}\n\ninterface Settings1Props extends BlockStateProps {\n  /** The signed-in member, who can't change their own role or remove themselves. */\n  currentMemberId: string\n  description: string\n  invites?: Invite[]\n  /** Leave out, or pass none, to show the empty state. */\n  members?: Member[]\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  onInvite?: (email: string, role: Role) => void\n  onRemoveMember?: (id: string) => void\n  onResendInvite?: (id: string) => void\n  onRevokeInvite?: (id: string) => void\n  onRoleChange?: (id: string, role: Role) => void\n  seats?: number\n  title: string\n}\n\nconst NOW = new Date(Date.UTC(2026, 8, 26, 16, 0))\nconst daysAgo = (days: number) => new Date(NOW.getTime() - days * 86_400_000)\n\nconst exampleProps: Settings1Props = {\n  currentMemberId: 'm1',\n  description: 'Invite people to the workspace and choose what they can do.',\n  invites: [\n    { email: 'noah@acme.co', id: 'i1', role: 'member', sentAt: daysAgo(2) },\n    { email: 'yuki@acme.co', id: 'i2', role: 'viewer', sentAt: daysAgo(9) },\n  ],\n  members: [\n    {\n      avatar: '/images/avatar-05.webp',\n      email: 'amara@acme.co',\n      id: 'm1',\n      name: 'Amara Okafor',\n      role: 'owner',\n    },\n    {\n      avatar: '/images/avatar-04.webp',\n      email: 'liam@acme.co',\n      id: 'm2',\n      name: 'Liam Carter',\n      role: 'admin',\n    },\n    {\n      avatar: '/images/avatar-01.webp',\n      email: 'sofia@acme.co',\n      id: 'm3',\n      name: 'Sofia Rossi',\n      role: 'member',\n    },\n    {\n      avatar: '/images/avatar-06.webp',\n      email: 'mateo@acme.co',\n      id: 'm4',\n      name: 'Mateo García',\n      role: 'member',\n    },\n    {\n      avatar: '/images/avatar-02.webp',\n      email: 'priya@acme.co',\n      id: 'm5',\n      name: 'Priya Nair',\n      role: 'viewer',\n    },\n  ],\n  now: NOW,\n  seats: 10,\n  title: 'Members',\n}\n\nconst INVITE_EXPIRY_DAYS = 7\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\nconst Settings1 = (props: Settings1Props) => {\n  const {\n    currentMemberId,\n    description,\n    now,\n    onInvite,\n    onRemoveMember,\n    onResendInvite,\n    onRevokeInvite,\n    onRoleChange,\n    seats,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const emailId = useId()\n  const [members, setMembers] = useState(props.members ?? [])\n  const [invites, setInvites] = useState(props.invites ?? [])\n  const state = getBlockState(status, props.members)\n  const ready = !state\n  const [email, setEmail] = useState('')\n  const [role, setRole] = useState<Role>('member')\n  const [error, setError] = useState<string | null>(null)\n\n  const used = members.length + invites.length\n  const full = seats !== undefined && ready && used >= seats\n  const sorted = [...members].sort(\n    (a, b) => roleOrder.indexOf(a.role) - roleOrder.indexOf(b.role),\n  )\n\n  const fail = (message: string) => {\n    flushSync(() => setError(message))\n    document.getElementById(emailId)?.focus()\n  }\n\n  const invite = (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault()\n    const address = email.trim().toLowerCase()\n    if (!EMAIL.test(address)) return fail('Enter an email address.')\n    if (\n      members.some((member) => member.email === address) ||\n      invites.some((pending) => pending.email === address)\n    ) {\n      return fail(`${address} is already in the workspace or invited.`)\n    }\n    setInvites((current) => [\n      { email: address, id: `invite-${address}`, role, sentAt: now },\n      ...current,\n    ])\n    setEmail('')\n    setError(null)\n    onInvite?.(address, role)\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <section className='@container flex flex-col gap-5'>\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'>\n            {description}\n            {ready && seats !== undefined && (\n              <>\n                {' '}\n                {used} of {seats} seats used.\n              </>\n            )}\n          </p>\n        </header>\n        <form method='post' onSubmit={invite} noValidate className='flex flex-col gap-2'>\n          <label htmlFor={emailId} className='text-sm font-medium'>\n            Invite by email\n          </label>\n          <div className='flex flex-col gap-2 @md:flex-row'>\n            <Input\n              id={emailId}\n              type='email'\n              autoComplete='off'\n              placeholder='name@company.com'\n              value={email}\n              onChange={(event) => setEmail(event.target.value)}\n              aria-invalid={error ? true : undefined}\n              aria-describedby={error ? `${emailId}-error` : undefined}\n              disabled={full || status !== undefined}\n              className='@md:flex-1'\n            />\n            <div className='flex gap-2'>\n              <RoleMenu\n                label='Role for the invite'\n                value={role}\n                onValueChange={setRole}\n              />\n              <Button\n                type='submit'\n                disabled={full || status !== undefined}\n                className='flex-1 @md:flex-none'\n              >\n                Send invite\n              </Button>\n            </div>\n          </div>\n          {error && (\n            <p id={`${emailId}-error`} className='text-destructive text-sm'>\n              {error}\n            </p>\n          )}\n          {full && (\n            <p className='text-muted-foreground text-sm'>\n              Every seat is taken. Remove a member or add seats to invite more.\n            </p>\n          )}\n        </form>\n\n        <section aria-labelledby={`${emailId}-members`} className='flex flex-col gap-1'>\n          <h3 id={`${emailId}-members`} className='text-sm font-medium'>\n            {ready\n              ? `${members.length} ${members.length === 1 ? 'member' : 'members'}`\n              : 'Members'}\n          </h3>\n          {!ready && (\n            <div className='border-t'>\n              <BlockStateRows rows={5} />\n            </div>\n          )}\n          {ready && (\n            <ul className='flex flex-col divide-y border-t'>\n              {sorted.map((member) => {\n                const isYou = member.id === currentMemberId\n                const locked = isYou || member.role === 'owner'\n                return (\n                  <li key={member.id} className='flex items-center gap-3 py-2.5'>\n                    <PersonAvatar person={member} />\n                    <div className='flex min-w-0 flex-1 flex-col'>\n                      <span className='truncate text-sm font-medium'>\n                        {member.name}\n                        {isYou && (\n                          <span className='text-muted-foreground font-normal'>\n                            {' '}\n                            (you)\n                          </span>\n                        )}\n                      </span>\n                      <span className='text-muted-foreground truncate text-xs'>\n                        {member.email}\n                      </span>\n                    </div>\n                    {locked ? (\n                      <span className='text-muted-foreground px-2.5 text-sm'>\n                        {roleConfig[member.role].label}\n                      </span>\n                    ) : (\n                      <>\n                        <RoleMenu\n                          label={`Role for ${member.name}`}\n                          value={member.role}\n                          onValueChange={(next) => {\n                            setMembers((current) =>\n                              current.map((item) =>\n                                item.id === member.id ? { ...item, role: next } : item,\n                              ),\n                            )\n                            onRoleChange?.(member.id, next)\n                          }}\n                        />\n                        <Button\n                          variant='ghost'\n                          size='icon-sm'\n                          aria-label={`Remove ${member.name}`}\n                          onClick={() => {\n                            setMembers((current) =>\n                              current.filter((item) => item.id !== member.id),\n                            )\n                            onRemoveMember?.(member.id)\n                          }}\n                        >\n                          <IconPlaceholder\n                            lucide='XIcon'\n                            tabler='IconX'\n                            hugeicons='Cancel01Icon'\n                            phosphor='XIcon'\n                            remixicon='RiCloseLine'\n                            aria-hidden\n                          />\n                        </Button>\n                      </>\n                    )}\n                  </li>\n                )\n              })}\n            </ul>\n          )}\n        </section>\n\n        {ready && invites.length > 0 && (\n          <section aria-labelledby={`${emailId}-invites`} className='flex flex-col gap-1'>\n            <h3 id={`${emailId}-invites`} className='text-sm font-medium'>\n              {invites.length} pending {invites.length === 1 ? 'invite' : 'invites'}\n            </h3>\n            <ul className='flex flex-col divide-y border-t'>\n              {invites.map((pending) => {\n                const expired =\n                  now.getTime() - pending.sentAt.getTime() >\n                  INVITE_EXPIRY_DAYS * 86_400_000\n                return (\n                  <li\n                    key={pending.id}\n                    className='flex flex-wrap items-center gap-x-3 gap-y-2 py-2.5'\n                  >\n                    <span\n                      aria-hidden\n                      className='bg-muted text-muted-foreground flex size-8 shrink-0 items-center justify-center rounded-full [&_svg]:size-4'\n                    >\n                      <IconPlaceholder\n                        lucide='MailIcon'\n                        tabler='IconMail'\n                        hugeicons='MailIcon'\n                        phosphor='EnvelopeIcon'\n                        remixicon='RiMailLine'\n                      />\n                    </span>\n                    <div className='flex min-w-0 flex-1 flex-col'>\n                      <span className='truncate text-sm font-medium'>\n                        {pending.email}\n                      </span>\n                      <Details className='text-muted-foreground text-xs'>\n                        {roleConfig[pending.role].label}\n                        {expired ? (\n                          <StatusLabel variant='text' tone='warning' className='text-xs'>\n                            Expired\n                          </StatusLabel>\n                        ) : (\n                          <>\n                            Sent{' '}\n                            <time dateTime={pending.sentAt.toISOString()}>\n                              {formatRelativeTime(pending.sentAt, now, { style: 'long' })}\n                            </time>\n                          </>\n                        )}\n                      </Details>\n                    </div>\n                    <div className='flex gap-1'>\n                      <Button\n                        variant='ghost'\n                        size='sm'\n                        aria-label={`Resend invite to ${pending.email}`}\n                        onClick={() => {\n                          setInvites((current) =>\n                            current.map((item) =>\n                              item.id === pending.id ? { ...item, sentAt: now } : item,\n                            ),\n                          )\n                          onResendInvite?.(pending.id)\n                        }}\n                      >\n                        <IconPlaceholder\n                          lucide='SendIcon'\n                          tabler='IconSend'\n                          hugeicons='SentIcon'\n                          phosphor='PaperPlaneTiltIcon'\n                          remixicon='RiSendPlaneLine'\n                          data-icon='inline-start'\n                        />\n                        Resend\n                      </Button>\n                      <Button\n                        variant='ghost'\n                        size='sm'\n                        aria-label={`Revoke invite to ${pending.email}`}\n                        onClick={() => {\n                          setInvites((current) =>\n                            current.filter((item) => item.id !== pending.id),\n                          )\n                          onRevokeInvite?.(pending.id)\n                        }}\n                      >\n                        Revoke\n                      </Button>\n                    </div>\n                  </li>\n                )\n              })}\n            </ul>\n          </section>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Settings1,\n  exampleProps as settings1ExampleProps,\n  type Invite,\n  type Member,\n  type Settings1Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/settings/settings-01.tsx"
    }
  ],
  "meta": {
    "shows": "Invite people by email with a role, change roles, remove members and resend or revoke pending invites, counted against the plan's seats.",
    "size": "full",
    "usedWith": [
      "team-05",
      "billing-01",
      "team-01"
    ],
    "component": "Settings1",
    "props": "{ currentMemberId: string; description: string; invites?: { email: string; id: string; role: \"owner\" | \"admin\" | \"member\" | \"viewer\"; sentAt: Date }[]; members?: { avatar?: string; email: string; id: string; name: string; role: \"owner\" | \"admin\" | \"member\" | \"viewer\" }[]; now: Date; onInvite?: (email: string, role: \"owner\" | \"admin\" | \"member\" | \"viewer\") => void; onRemoveMember?: (id: string) => void; onResendInvite?: (id: string) => void; onRevokeInvite?: (id: string) => void; onRoleChange?: (id: string, role: \"owner\" | \"admin\" | \"member\" | \"viewer\") => void; seats?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
