{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "auth-02",
  "description": "A list of the workspaces you belong to with your role in each, pending invites to join and a search once there are many.",
  "registryDependencies": [
    "button",
    "input",
    "https://www.dashboardblocks.com/r/radix/auth.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/details.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/auth/auth-02.tsx",
      "content": "'use client'\n\nimport {\n  AuthLayout,\n  AuthSwitch,\n  WorkspaceAvatar,\n} from '@/registry/components/dashboardblocks/auth'\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 { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { type ReactNode, startTransition, useId, useState } from 'react'\n\nimport { Button, buttonVariants } from '@/components/ui/button'\nimport { Input } from '@/components/ui/input'\n\nimport { cn } from '@/lib/utils'\n\ninterface PickerWorkspace {\n  href: string\n  id: string\n  logo?: string\n  /** Drawn in the primary colour when there's no `logo`. */\n  mark?: ReactNode\n  members: number\n  name: string\n  role: string\n}\n\ninterface PendingInvite {\n  id: string\n  invitedBy: string\n  logo?: string\n  /** Drawn in the primary colour when there's no `logo`. */\n  mark?: ReactNode\n  name: string\n}\n\ninterface Auth2Props extends BlockStateProps {\n  createHref: string\n  email: string\n  invites?: PendingInvite[]\n  onAcceptInvite?: (id: string) => void | Promise<void>\n  signOutHref: string\n  /** Leave out, or pass none, to show the empty state. */\n  workspaces?: PickerWorkspace[]\n}\n\nconst exampleProps: Auth2Props = {\n  createHref: '#',\n  email: 'amara@acme.co',\n  invites: [\n    {\n      id: 'i1',\n      invitedBy: 'Liam Carter',\n      mark: (\n        <svg viewBox='0 0 24 24' fill='currentColor' aria-hidden>\n          <rect x='4.5' y='2.5' width='5' height='19' rx='2.5' />\n          <path\n            d='M7 5l9.75 14'\n            stroke='currentColor'\n            strokeWidth='5'\n            strokeLinecap='round'\n          />\n          <circle cx='17' cy='6.25' r='3.75' />\n        </svg>\n      ),\n      name: 'Northwind Finance',\n    },\n  ],\n  onAcceptInvite: () => new Promise((resolve) => setTimeout(resolve, 600)),\n  signOutHref: '#',\n  workspaces: [\n    { href: '#', id: 'w1', members: 24, name: 'Acme Analytics', role: 'Owner' },\n    { href: '#', id: 'w2', members: 8, name: 'Acme Marketing', role: 'Admin' },\n    { href: '#', id: 'w3', members: 112, name: 'Globex', role: 'Member' },\n    { href: '#', id: 'w4', members: 3, name: 'Side project', role: 'Owner' },\n  ],\n}\n\nconst SEARCH_AFTER = 5\n\nconst Auth2 = (props: Auth2Props) => {\n  const { createHref, email, onAcceptInvite, signOutHref, errorMessage, status } = props\n  const id = useId()\n  const [workspaces, setWorkspaces] = useState(props.workspaces ?? [])\n  const [invites, setInvites] = useState(props.invites ?? [])\n  const ready = !status && workspaces.length > 0\n  const [joining, setJoining] = useState<string | null>(null)\n  const [query, setQuery] = useState('')\n  const [error, setError] = useState<string | null>(null)\n\n  const shown = workspaces.filter((workspace) =>\n    workspace.name.toLowerCase().includes(query.trim().toLowerCase()),\n  )\n\n  const join = async (invite: PendingInvite) => {\n    setJoining(invite.id)\n    setError(null)\n    try {\n      await onAcceptInvite?.(invite.id)\n      startTransition(() => {\n        setInvites((current) => current.filter((item) => item.id !== invite.id))\n        setWorkspaces((current) => [\n          ...current,\n          {\n            href: '#',\n            id: invite.id,\n            logo: invite.logo,\n            mark: invite.mark,\n            members: 0,\n            name: invite.name,\n            role: 'Member',\n          },\n        ])\n      })\n    } catch {\n      startTransition(() => setError(`Couldn’t join ${invite.name}. Try again.`))\n    } finally {\n      startTransition(() => setJoining(null))\n    }\n  }\n\n  return (\n    <BlockStateProvider\n      errorMessage={errorMessage}\n      state={getBlockState(status, workspaces)}\n    >\n      <AuthLayout\n        title='Choose a workspace'\n        description={\n          <>\n            Signed in as <span className='text-foreground font-medium'>{email}</span>.\n            {ready && (\n              <>\n                {' '}\n                You’re in {workspaces.length}{' '}\n                {workspaces.length === 1 ? 'workspace' : 'workspaces'}\n                {invites.length > 0 &&\n                  `, with ${invites.length} ${invites.length === 1 ? 'invite' : 'invites'} waiting`}\n                .\n              </>\n            )}\n          </>\n        }\n      >\n        <div className='flex flex-col gap-6'>\n          {ready && workspaces.length > SEARCH_AFTER && (\n            <div>\n              <label htmlFor={`${id}-search`} className='sr-only'>\n                Find a workspace\n              </label>\n              <Input\n                id={`${id}-search`}\n                type='search'\n                placeholder='Find a workspace'\n                value={query}\n                onChange={(event) => setQuery(event.target.value)}\n              />\n            </div>\n          )}\n\n          <section aria-labelledby={`${id}-yours`} className='flex flex-col gap-2'>\n            <h2 id={`${id}-yours`} className='text-sm font-medium'>\n              Your workspaces\n            </h2>\n            {!ready ? (\n              <div className='border-y'>\n                <BlockStateRows rows={3} />\n              </div>\n            ) : shown.length > 0 ? (\n              <ul className='flex flex-col divide-y border-y'>\n                {shown.map((workspace) => (\n                  <li key={workspace.id}>\n                    <a\n                      href={workspace.href}\n                      className='hover:bg-muted focus-visible:ring-ring/50 -mx-2 flex items-center gap-3 rounded-md px-2 py-2.5 outline-none focus-visible:ring-3 focus-visible:ring-inset'\n                    >\n                      <WorkspaceAvatar\n                        name={workspace.name}\n                        logo={workspace.logo}\n                        mark={workspace.mark}\n                      />\n                      <span className='flex min-w-0 flex-1 flex-col'>\n                        <span className='truncate text-sm font-medium'>\n                          {workspace.name}\n                        </span>\n                        <Details className='text-muted-foreground text-xs'>\n                          {workspace.role}\n                          {workspace.members > 0 &&\n                            `${workspace.members} ${workspace.members === 1 ? 'member' : 'members'}`}\n                        </Details>\n                      </span>\n                      <IconPlaceholder\n                        lucide='ChevronRightIcon'\n                        tabler='IconChevronRight'\n                        hugeicons='ArrowRight01Icon'\n                        phosphor='CaretRightIcon'\n                        remixicon='RiArrowRightSLine'\n                        aria-hidden\n                        className='text-muted-foreground size-4 shrink-0'\n                      />\n                    </a>\n                  </li>\n                ))}\n              </ul>\n            ) : (\n              <p className='text-muted-foreground border-y py-4 text-sm'>\n                No workspaces match “{query}”.\n              </p>\n            )}\n          </section>\n\n          {ready && invites.length > 0 && (\n            <section aria-labelledby={`${id}-invites`} className='flex flex-col gap-2'>\n              <h2 id={`${id}-invites`} className='text-sm font-medium'>\n                Invites\n              </h2>\n              <ul className='flex flex-col divide-y border-y'>\n                {invites.map((invite) => (\n                  <li key={invite.id} className='flex items-center gap-3 py-2.5'>\n                    <WorkspaceAvatar\n                      name={invite.name}\n                      logo={invite.logo}\n                      mark={invite.mark}\n                    />\n                    <span className='flex min-w-0 flex-1 flex-col'>\n                      <span className='truncate text-sm font-medium'>{invite.name}</span>\n                      <span className='text-muted-foreground truncate text-xs'>\n                        From {invite.invitedBy}\n                      </span>\n                    </span>\n                    <Button\n                      size='sm'\n                      variant='outline'\n                      disabled={joining === invite.id}\n                      aria-label={`Join ${invite.name}`}\n                      onClick={() => void join(invite)}\n                    >\n                      {joining === invite.id ? 'Joining' : 'Join'}\n                    </Button>\n                  </li>\n                ))}\n              </ul>\n              {error && (\n                <p role='alert' className='text-destructive text-sm'>\n                  {error}\n                </p>\n              )}\n            </section>\n          )}\n\n          <a\n            href={createHref}\n            className={cn(buttonVariants({ variant: 'outline' }), 'w-full')}\n          >\n            <IconPlaceholder\n              lucide='PlusIcon'\n              tabler='IconPlus'\n              hugeicons='PlusSignIcon'\n              phosphor='PlusIcon'\n              remixicon='RiAddLine'\n              data-icon='inline-start'\n              aria-hidden\n            />\n            Create a workspace\n          </a>\n        </div>\n        <AuthSwitch\n          href={signOutHref}\n          title='Use another account'\n          description={`Sign out of ${email} first.`}\n        />\n      </AuthLayout>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Auth2,\n  exampleProps as auth2ExampleProps,\n  type Auth2Props,\n  type PendingInvite,\n  type PickerWorkspace,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/auth/auth-02.tsx"
    }
  ],
  "meta": {
    "shows": "A list of the workspaces you belong to with your role in each, pending invites to join and a search once there are many.",
    "size": "page",
    "usedWith": [
      "auth-01"
    ],
    "component": "Auth2",
    "props": "{ createHref: string; email: string; invites?: { id: string; invitedBy: string; logo?: string; mark?: ReactNode; name: string }[]; onAcceptInvite?: (id: string) => void | Promise<void>; signOutHref: string; workspaces?: { href: string; id: string; logo?: string; mark?: ReactNode; members: number; name: string; role: string }[]; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
