{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "auth-07",
  "description": "A new password form with a strength meter and the rules it still needs, a done state that leads to sign-in, and an expired link state.",
  "registryDependencies": [
    "button",
    "field",
    "https://www.dashboardblocks.com/r/radix/auth.json",
    "https://www.dashboardblocks.com/r/radix/forms.json",
    "https://www.dashboardblocks.com/r/radix/rolling-text.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/auth/auth-07.tsx",
      "content": "'use client'\n\nimport {\n  AuthIcon,\n  AuthLayout,\n  AuthReveal,\n  AuthSwitch,\n  PasswordInput,\n  PasswordStrength,\n  getMissingPasswordRules,\n} from '@/registry/components/dashboardblocks/auth'\nimport {\n  type FormErrors,\n  useSimpleForm,\n} from '@/registry/components/dashboardblocks/forms'\nimport { RollingText } from '@/registry/components/dashboardblocks/rolling-text'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { type FormEvent, startTransition, useRef, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Field, FieldError, FieldLabel } from '@/components/ui/field'\n\n/** Refuse with a sentence for the new password, such as one found in a breach, or say the link has expired. */\ntype Auth7Result = { message: string; status: 'error' } | { status: 'expired' } | void\n\ninterface Auth7Props {\n  /** The account the link was sent to, named under the title. */\n  email?: string\n  /** Where \"Send a new link\" leads, such as a page with Auth 6. */\n  forgotPasswordHref: string\n  /** The link was already used or is too old: check it on the server before the page renders. */\n  linkExpired?: boolean\n  /** Save the new password. Check the rules again on the server. */\n  onSave?: (password: string) => Promise<Auth7Result>\n  signInHref: string\n}\n\nconst exampleProps: Auth7Props = {\n  email: 'amara@acme.co',\n  forgotPasswordHref: '#forgot-password',\n  onSave: async () => {\n    await new Promise((resolve) => setTimeout(resolve, 800))\n  },\n  signInHref: '#sign-in',\n}\n\ntype Values = { confirm: string; password: string }\n\nconst Auth7 = (props: Auth7Props) => {\n  const { email, forgotPasswordHref, onSave, signInHref } = props\n  const [outcome, setOutcome] = useState<'expired' | 'saved' | null>(\n    props.linkExpired ? 'expired' : null,\n  )\n  const [message, setMessage] = useState<string | null>(null)\n  const refused = useRef(false)\n\n  const form = useSimpleForm<Values>({\n    defaultValues: { confirm: '', password: '' },\n    onSubmit: async ({ password }) => {\n      refused.current = false\n      const result = await onSave?.(password)\n      if (!result) return\n      refused.current = true\n      if (result.status === 'expired') {\n        startTransition(() => setOutcome('expired'))\n        return\n      }\n      return { password: result.message }\n    },\n    validate: ({ confirm, password }): FormErrors<Values> => ({\n      confirm: !confirm\n        ? 'Type the new password again.'\n        : confirm === password\n          ? undefined\n          : 'The passwords don’t match.',\n      password: !password\n        ? 'Choose a new password.'\n        : getMissingPasswordRules(password).length\n          ? 'Not strong enough yet.'\n          : undefined,\n    }),\n  })\n\n  const submit = async (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault()\n    if (form.isSubmitting) return\n    setMessage(null)\n    try {\n      const saved = await form.submit(event)\n      if (saved && !refused.current) startTransition(() => setOutcome('saved'))\n    } catch {\n      startTransition(() =>\n        setMessage('We couldn’t save the password. Check your connection and try again.'),\n      )\n    }\n  }\n\n  const pending = form.isSubmitting\n  const strengthId = `${form.getId('password')}-strength`\n  const title =\n    outcome === 'saved'\n      ? 'Password saved'\n      : outcome === 'expired'\n        ? 'This link has expired'\n        : 'Set a new password'\n  const description =\n    outcome === 'saved'\n      ? 'Sign in with your new password.'\n      : outcome === 'expired'\n        ? 'Reset links work once, for a short time. Ask for a new one.'\n        : email\n          ? `For ${email}.`\n          : 'Choose one you don’t use anywhere else.'\n\n  return (\n    <AuthLayout\n      media={\n        outcome === 'saved' ? (\n          <AuthIcon tone='done' />\n        ) : (\n          <AuthIcon>\n            <IconPlaceholder\n              lucide='LockIcon'\n              tabler='IconLock'\n              hugeicons='SquareLock02Icon'\n              phosphor='LockIcon'\n              remixicon='RiLockLine'\n              aria-hidden\n            />\n          </AuthIcon>\n        )\n      }\n      title={<RollingText text={title} wrap />}\n      description={<RollingText text={description} wrap />}\n    >\n      <div className='flex flex-col'>\n        <AuthReveal open={outcome === null}>\n          <form\n            method='post'\n            noValidate\n            onSubmit={(event) => void submit(event)}\n            className='flex flex-col gap-4'\n          >\n            <Field data-invalid={form.errors.password ? true : undefined}>\n              <FieldLabel htmlFor={form.getId('password')}>New password</FieldLabel>\n              <PasswordInput\n                autoComplete='new-password'\n                disabled={pending}\n                {...form.field('password')}\n                aria-describedby={\n                  [strengthId, form.field('password')['aria-describedby']]\n                    .filter(Boolean)\n                    .join(' ') || undefined\n                }\n              />\n              <FieldError {...form.error('password')} />\n              <PasswordStrength id={strengthId} password={form.values.password} />\n            </Field>\n            <Field data-invalid={form.errors.confirm ? true : undefined}>\n              <FieldLabel htmlFor={form.getId('confirm')}>Type it again</FieldLabel>\n              <PasswordInput\n                autoComplete='new-password'\n                disabled={pending}\n                {...form.field('confirm')}\n              />\n              <FieldError {...form.error('confirm')} />\n            </Field>\n            {message && (\n              <p role='alert' className='text-destructive text-sm text-pretty'>\n                {message}\n              </p>\n            )}\n            <Button\n              type='submit'\n              size='lg'\n              className='mt-1 aria-disabled:opacity-50'\n              aria-disabled={pending || undefined}\n            >\n              <RollingText text={pending ? 'Saving' : 'Save password'} />\n            </Button>\n          </form>\n        </AuthReveal>\n        <p role='status' className='sr-only'>\n          {outcome === 'saved' ? 'Password saved' : ''}\n        </p>\n      </div>\n      {outcome === 'expired' ? (\n        <AuthSwitch\n          href={forgotPasswordHref}\n          title='Send a new link'\n          description='We’ll email you another one.'\n        />\n      ) : (\n        <AuthSwitch\n          href={signInHref}\n          title={outcome === 'saved' ? 'Continue to sign in' : 'Remembered it?'}\n          description={\n            outcome === 'saved' && email\n              ? `Use ${email} and your new password.`\n              : 'Back to sign in.'\n          }\n        />\n      )}\n    </AuthLayout>\n  )\n}\n\nexport { Auth7, exampleProps as auth7ExampleProps, type Auth7Props, type Auth7Result }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/auth/auth-07.tsx"
    }
  ],
  "meta": {
    "shows": "A new password form with a strength meter and the rules it still needs, a done state that leads to sign-in, and an expired link state.",
    "size": "page",
    "usedWith": [
      "auth-06",
      "auth-05"
    ],
    "component": "Auth7",
    "props": "{ email?: string; forgotPasswordHref: string; linkExpired?: boolean; onSave?: (password: string) => Promise<void | { message: string; status: \"error\" } | { status: \"expired\" }>; signInHref: string }"
  },
  "type": "registry:component"
}
