{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "openlmis-reset-password-page",
  "title": "Reset Password Page",
  "description": "Mock password reset page with validation and link-status presentation.",
  "dependencies": [
    "@tanstack/react-form@^1",
    "@base-ui/react@^1"
  ],
  "registryDependencies": [
    "card",
    "https://registry.soldevelo.com/r/openlmis-auth-card.json",
    "https://registry.soldevelo.com/r/openlmis-form-dialog.json",
    "https://registry.soldevelo.com/r/openlmis-form-fields.json",
    "https://registry.soldevelo.com/r/openlmis-password-requirements.json"
  ],
  "files": [
    {
      "path": "registry/templates/openlmis/reset-password-page/components/reset-password-form/reset-password-form.tsx",
      "content": "\"use client\"\n\nimport { revalidateLogic } from \"@tanstack/react-form\"\nimport { type ReactNode, useId, useState } from \"react\"\n\nimport { CardContent, CardDescription } from \"@/components/ui/card\"\nimport { newPasswordSchema } from \"@/components/openlmis/password-requirements/password-schema\"\nimport {\n  AuthButtonLink,\n  AuthForm,\n  AuthHeader,\n  AuthLink,\n  AuthSubmit,\n  AuthTitle,\n} from \"@/components/blocks/openlmis/auth-card\"\nimport { FormDialogError } from \"@/components/openlmis/form-dialog/form-dialog\"\nimport { useAppForm } from \"@/components/openlmis/form-fields/form\"\nimport { PasswordRequirements } from \"@/components/openlmis/password-requirements/password-requirements\"\n\n/** `invalid` and `expired` are the link itself failing; `changed` once the new password is saved. */\nexport type ResetLinkStatus = \"ready\" | \"invalid\" | \"expired\" | \"changed\"\n\n// The link does not say whose password it is, so the names rule is left out.\nconst schema = newPasswordSchema()\n\ntype ResetPasswordFormProps = {\n  status?: ResetLinkStatus\n  logo?: ReactNode\n  signInHref?: string\n  forgotPasswordHref?: string\n  /** Called with the new password; save it, then set `status` to `changed`. */\n  onSubmit: (password: string) => void\n  pending?: boolean\n  /** A failure the form can retry, such as a password the server finds too weak. */\n  error?: ReactNode\n}\n\nconst LINK_PROBLEMS = {\n  invalid: {\n    title: \"Link Not Valid\",\n    description:\n      \"This reset link does not work. It may have been used already, or a newer one was sent. Request a new link to carry on.\",\n  },\n  expired: {\n    title: \"Link Expired\",\n    description:\n      \"This reset link has expired. Links work for 12 hours. Request a new link to carry on.\",\n  },\n} as const\n\n/** The reset-password card's content; render it inside `AuthPage`. */\nexport function ResetPasswordForm({\n  status = \"ready\",\n  logo,\n  signInHref = \"/login\",\n  forgotPasswordHref = \"/forgot-password\",\n  onSubmit,\n  pending = false,\n  error,\n}: ResetPasswordFormProps) {\n  // Focus moves to a result card only when it replaces the form, not when it renders first.\n  const [initialStatus] = useState(status)\n  const focus = status !== initialStatus\n  if (status === \"changed\") {\n    return (\n      <>\n        <AuthHeader logo={logo}>\n          <AuthTitle focus={focus}>Password Changed</AuthTitle>\n          <CardDescription>Sign in with your new password.</CardDescription>\n        </AuthHeader>\n        <CardContent>\n          <AuthButtonLink href={signInHref}>Back To Sign In</AuthButtonLink>\n        </CardContent>\n      </>\n    )\n  }\n  if (status !== \"ready\") {\n    const problem = LINK_PROBLEMS[status]\n    return (\n      <>\n        <AuthHeader logo={logo}>\n          <AuthTitle focus={focus}>{problem.title}</AuthTitle>\n          <CardDescription>{problem.description}</CardDescription>\n        </AuthHeader>\n        <CardContent>\n          <div className=\"grid gap-2\">\n            <AuthButtonLink href={forgotPasswordHref}>\n              Request A New Link\n            </AuthButtonLink>\n            <AuthButtonLink href={signInHref} variant=\"outline\">\n              Back To Sign In\n            </AuthButtonLink>\n          </div>\n        </CardContent>\n      </>\n    )\n  }\n\n  return (\n    <NewPasswordForm\n      error={error}\n      logo={logo}\n      onSubmit={onSubmit}\n      pending={pending}\n      signInHref={signInHref}\n    />\n  )\n}\n\nfunction NewPasswordForm({\n  logo,\n  signInHref,\n  onSubmit,\n  pending,\n  error,\n}: Pick<ResetPasswordFormProps, \"logo\" | \"onSubmit\" | \"error\"> & {\n  signInHref: string\n  pending: boolean\n}) {\n  const requirementsId = useId()\n  const [visible, setVisible] = useState(false)\n  const form = useAppForm({\n    defaultValues: { password: \"\", confirm: \"\" },\n    validationLogic: revalidateLogic({\n      mode: \"submit\",\n      modeAfterSubmission: \"change\",\n    }),\n    validators: { onDynamic: schema },\n    onSubmit: ({ value }) => onSubmit(value.password),\n  })\n\n  return (\n    <>\n      <AuthHeader logo={logo}>\n        <AuthTitle>Reset Password</AuthTitle>\n        <CardDescription>\n          Choose a new password for your account.\n        </CardDescription>\n      </AuthHeader>\n\n      <CardContent>\n        <AuthForm onSubmit={form.handleSubmit}>\n          {error && (\n            <FormDialogError\n              description={error}\n              title=\"Could Not Change Password\"\n            />\n          )}\n          <form.AppField name=\"password\">\n            {(field) => (\n              <div className=\"grid gap-3\">\n                <field.PasswordField\n                  describedBy={requirementsId}\n                  label=\"New Password\"\n                  onVisibleChange={setVisible}\n                  required\n                  visible={visible}\n                />\n                <PasswordRequirements\n                  id={requirementsId}\n                  password={field.state.value}\n                />\n              </div>\n            )}\n          </form.AppField>\n          <form.AppField name=\"confirm\">\n            {(field) => (\n              <field.PasswordField\n                label=\"Confirm New Password\"\n                onVisibleChange={setVisible}\n                required\n                visible={visible}\n              />\n            )}\n          </form.AppField>\n          <AuthSubmit pending={pending}>\n            {pending ? \"Changing...\" : \"Change Password\"}\n          </AuthSubmit>\n          <p className=\"text-center\">\n            <AuthLink href={signInHref}>Back To Sign In</AuthLink>\n          </p>\n        </AuthForm>\n      </CardContent>\n    </>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/reset-password-page/reset-password-form.tsx"
    },
    {
      "path": "registry/templates/openlmis/reset-password-page/components/reset-password-page.tsx",
      "content": "\"use client\"\n\nimport { useState } from \"react\"\n\nimport {\n  type ResetLinkStatus,\n  ResetPasswordForm,\n} from \"@/components/openlmis/reset-password-page/reset-password-form\"\nimport { AuthPage } from \"@/components/blocks/openlmis/auth-card\"\n\n// oxlint-disable-next-line next/no-img-element -- items are framework-neutral\nconst logo = <img alt=\"OpenLMIS\" src=\"https://registry.soldevelo.com/projects/openlmis.png\" />\n\ntype ResetPasswordPageProps = {\n  /** Whether the link still works; check the token from the URL before rendering. */\n  status?: Exclude<ResetLinkStatus, \"changed\">\n}\n\nexport function ResetPasswordPage({\n  status = \"ready\",\n}: ResetPasswordPageProps) {\n  const [changed, setChanged] = useState(false)\n\n  return (\n    <AuthPage>\n      <ResetPasswordForm\n        logo={logo}\n        onSubmit={() => setChanged(true)}\n        status={changed ? \"changed\" : status}\n      />\n    </AuthPage>\n  )\n}",
      "type": "registry:component",
      "target": "components/openlmis/reset-password-page/reset-password-page.tsx"
    },
    {
      "path": "registry/templates/openlmis/reset-password-page/page.tsx",
      "content": "import { ResetPasswordPage } from \"@/components/openlmis/reset-password-page/reset-password-page\"\n\n// A Next.js App Router route; in any other React app, render ResetPasswordPage from your own route.\nexport default function Page() {\n  return <ResetPasswordPage />\n}",
      "type": "registry:page",
      "target": "app/reset-password-page/page.tsx"
    }
  ],
  "cssVars": {
    "light": {
      "destructive": "oklch(0.577 0.245 27.325)",
      "destructive-foreground": "oklch(0.985 0 0)",
      "success": "oklch(0.596 0.145 163.225)",
      "success-foreground": "oklch(0.985 0 0)",
      "warning": "oklch(0.666 0.179 58.318)",
      "warning-foreground": "oklch(0.985 0 0)",
      "info": "oklch(0.55 0.13 237)",
      "info-foreground": "oklch(0.985 0 0)"
    },
    "dark": {
      "destructive": "oklch(0.704 0.191 22.216)",
      "destructive-foreground": "oklch(0.21 0.04 25)",
      "success": "oklch(0.696 0.17 162.48)",
      "success-foreground": "oklch(0.21 0.04 163)",
      "warning": "oklch(0.769 0.188 70.08)",
      "warning-foreground": "oklch(0.22 0.04 60)",
      "info": "oklch(0.7 0.14 237)",
      "info-foreground": "oklch(0.2 0.04 240)"
    }
  },
  "meta": {
    "project": "openlmis",
    "height": "603px"
  },
  "categories": [
    "auth"
  ],
  "type": "registry:page"
}
