-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): forgot-password-template
- Loading branch information
Showing
2 changed files
with
17 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "forgot-password-template", | ||
"type": "registry:block", | ||
"category": "generators", | ||
"subcategory": "dbAuth", | ||
"registryDependencies": ["button", "card", "input", "label"], | ||
"files": [ | ||
{ | ||
"path": "dbAuth/forgotPassword.tsx.template", | ||
"content": "import { useEffect, useRef } from 'react'\n\nimport { FieldError, Form, Label, TextField } from '@redwoodjs/forms'\nimport { navigate, routes } from '@redwoodjs/router'\nimport { Metadata } from '@redwoodjs/web'\nimport { toast, Toaster } from '@redwoodjs/web/toast'\n\nimport { useAuth } from 'src/auth'\nimport { Button } from '@/registry/default/ui/Button'\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@/registry/default/ui/Card'\n\nconst ForgotPasswordPage = () => {\n const { isAuthenticated, forgotPassword } = useAuth()\n\n useEffect(() => {\n if (isAuthenticated) {\n navigate(routes.home())\n }\n }, [isAuthenticated])\n\n const ${usernameCamelCase}Ref = useRef<HTMLInputElement>(null)\n useEffect(() => {\n ${usernameCamelCase}Ref?.current?.focus()\n }, [])\n\n const onSubmit = async (data: { ${usernameCamelCase}: string }) => {\n const response = await forgotPassword(data.${usernameCamelCase})\n\n if (response.error) {\n toast.error(response.error)\n } else {\n // The function `forgotPassword.handler` in api/src/functions/auth.js has\n // been invoked, let the user know how to get the link to reset their\n // password (sent in email, perhaps?)\n // toast.success(\n // 'A link to reset your ${passwordLowerCase} was sent to ' + response.email\n // )\n navigate(routes.login())\n }\n }\n\n return (\n <>\n <Metadata title=\"Forgot ${passwordTitleCase}\" />\n\n <main>\n <Toaster toastOptions={{ className: 'rw-toast', duration: 6000 }} />\n <Card className=\"mx-auto mt-14 max-w-sm\">\n <CardHeader>\n <CardTitle className=\"text-2xl\">Forgot ${passwordTitleCase}</CardTitle>\n <CardDescription>\n Enter your ${usernameTitleCase} below and click Submit\n </CardDescription>\n </CardHeader>\n <CardContent>\n <Form onSubmit={onSubmit}>\n <div className=\"grid gap-4\">\n <div className=\"grid gap-2\">\n <Label\n name=\"${usernameCamelCase}\"\n className=\"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\"\n errorClassName=\"text-sm text-red-800 font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70\"\n >\n ${usernameTitleCase}\n </Label>\n <TextField\n name=\"${usernameCamelCase}\"\n className=\"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50\"\n errorClassName=\"flex text-red-800 h-10 w-full rounded-md border border-red-800 border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50\"\n ref={${usernameCamelCase}Ref}\n validation={{\n required: {\n value: true,\n message: '${usernameTitleCase} is required',\n },\n }}\n />\n\n <FieldError name=\"${usernameCamelCase}\" className=\"rw-field-error\" />\n </div>\n\n <Button type=\"submit\" className=\"w-full\">\n Submit\n </Button>\n </div>\n </Form>\n </CardContent>\n </Card>\n </main>\n </>\n )\n}\n\nexport default ForgotPasswordPage\n", | ||
"type": "registry:page" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters