A full-featured CRM built with React, shadcn/ui, and Supabase.
Add forgot password page.
Matthieu Hochlander14c07ca1cbc6
diff --git a/src/components/admin/login-page.tsx b/src/components/admin/login-page.tsxindex 0f132212..251753bc 100644--- a/src/components/admin/login-page.tsx+++ b/src/components/admin/login-page.tsx@@ -1,6 +1,7 @@import { useState } from "react";import { Form, required, useLogin, useNotify } from "ra-core";import type { SubmitHandler, FieldValues } from "react-hook-form";+import { Link } from "react-router";import { Button } from "@/components/ui/button";import { TextInput } from "@/components/admin/text-input";import { Notification } from "@/components/admin/notification";@@ -78,6 +79,13 @@ export const LoginPage = (props: { redirectTo?: string }) => {Sign in</Button></Form>++ <Link+ to={"/forgot-password"}+ className="text-sm text-center hover:underline"+ >+ Forgot your password?+ </Link></div></div></div>diff --git a/src/components/supabase/forgot-password-page.tsx b/src/components/supabase/forgot-password-page.tsxindex ef19e4eb..85b63715 100644--- a/src/components/supabase/forgot-password-page.tsx+++ b/src/components/supabase/forgot-password-page.tsx@@ -1,5 +1,86 @@-export function ForgotPasswordPage() {- return null;+import { useState } from "react";+import { useResetPassword } from "ra-supabase-core";+import { Form, required, useNotify, useTranslate } from "ra-core";+import { Layout } from "@/components/supabase/layout.tsx";+import { FieldValues, SubmitHandler } from "react-hook-form";+import { TextInput } from "@/components/admin";+import { Button } from "@/components/ui/button.tsx";++interface FormData {+ email: string;}+export const ForgotPasswordPage = () => {+ const [loading, setLoading] = useState(false);++ const notify = useNotify();+ const translate = useTranslate();+ const [, { mutateAsync: resetPassword }] = useResetPassword();++ const submit = async (values: FormData) => {+ try {+ setLoading(true);+ await resetPassword({+ email: values.email,+ });+ } catch (error: any) {+ notify(+ typeof error === "string"+ ? error+ : typeof error === "undefined" || !error.message+ ? "ra.auth.sign_in_error"+ : error.message,+ {+ type: "warning",+ messageArgs: {+ _:+ typeof error === "string"+ ? error+ : error && error.message+ ? error.message+ : undefined,+ },+ },+ );+ } finally {+ setLoading(false);+ }+ };++ return (+ <Layout>+ <div className="flex flex-col space-y-2 text-center">+ <h1 className="text-2xl font-semibold tracking-tight">+ {translate("ra-supabase.reset_password.forgot_password", {+ _: "Forgot password?",+ })}+ </h1>+ <p>+ {translate("ra-supabase.reset_password.forgot_password_details", {+ _: "Enter your email to receive a reset password link.",+ })}+ </p>+ </div>+ <Form<FormData>+ className="space-y-8"+ onSubmit={submit as SubmitHandler<FieldValues>}+ >+ <TextInput+ source="email"+ label={translate("ra.auth.email", {+ _: "Email",+ })}+ autoComplete="email"+ validate={required()}+ />+ <Button type="submit" className="cursor-pointer" disabled={loading}>+ {translate("ra.action.reset_password", {+ _: "Reset password",+ })}+ </Button>+ </Form>+ </Layout>+ );+};+ForgotPasswordPage.path = "forgot-password";diff --git a/src/components/supabase/set-password-page.tsx b/src/components/supabase/set-password-page.tsxindex 7a12f950..03a71432 100644--- a/src/components/supabase/set-password-page.tsx+++ b/src/components/supabase/set-password-page.tsx@@ -52,7 +52,6 @@ export const SetPasswordPage = () => {refresh_token,password: values.password,});- setLoading(false);} catch (error: any) {notify(typeof error === "string"@@ -72,6 +71,8 @@ export const SetPasswordPage = () => {},},);+ } finally {+ setLoading(false);}};