A full-featured CRM built with React, shadcn/ui, and Supabase.
feat(auth): show password recovery email sent notification
Anibal Svarcas1c909fa6c752
diff --git a/src/components/atomic-crm/login/LoginPage.tsx b/src/components/atomic-crm/login/LoginPage.tsxindex 7def1317..48382401 100644--- a/src/components/atomic-crm/login/LoginPage.tsx+++ b/src/components/atomic-crm/login/LoginPage.tsx@@ -1,7 +1,7 @@-import { useState } from "react";+import { useEffect, useRef, 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 { Link, useLocation, useNavigate } from "react-router";import { Button } from "@/components/ui/button";import { TextInput } from "@/components/admin/text-input";import { Notification } from "@/components/admin/notification";@@ -26,8 +26,39 @@ export const LoginPage = (props: { redirectTo?: string }) => {} = useConfigurationContext();const { redirectTo } = props;const [loading, setLoading] = useState(false);+ const hasDisplayedRecoveryNotification = useRef(false);+ const location = useLocation();+ const navigate = useNavigate();const login = useLogin();const notify = useNotify();++ useEffect(() => {+ const searchParams = new URLSearchParams(location.search);+ const shouldNotify = searchParams.get("passwordRecoveryEmailSent") === "1";++ if (!shouldNotify || hasDisplayedRecoveryNotification.current) {+ return;+ }++ hasDisplayedRecoveryNotification.current = true;+ notify(+ "If you're a registered user, you should receive an password recovery email shortly.",+ {+ type: "success",+ },+ );++ searchParams.delete("passwordRecoveryEmailSent");+ const nextSearch = searchParams.toString();+ navigate(+ {+ pathname: location.pathname,+ search: nextSearch ? `?${nextSearch}` : "",+ },+ { replace: true },+ );+ }, [location.pathname, location.search, navigate, notify]);+const handleSubmit: SubmitHandler<FieldValues> = (values) => {setLoading(true);login(values, redirectTo)diff --git a/src/components/supabase/forgot-password-page.tsx b/src/components/supabase/forgot-password-page.tsxindex d3f6ecca..53321295 100644--- a/src/components/supabase/forgot-password-page.tsx+++ b/src/components/supabase/forgot-password-page.tsx@@ -1,6 +1,6 @@import { useState } from "react";import { useResetPassword } from "ra-supabase-core";-import { Form, required, useNotify, useTranslate } from "ra-core";+import { Form, required, useNotify, useRedirect, useTranslate } from "ra-core";import { Layout } from "@/components/supabase/layout";import type { FieldValues, SubmitHandler } from "react-hook-form";import { TextInput } from "@/components/admin/text-input";@@ -14,8 +14,14 @@ export const ForgotPasswordPage = () => {const [loading, setLoading] = useState(false);const notify = useNotify();+ const redirect = useRedirect();const translate = useTranslate();- const [, { mutateAsync: resetPassword }] = useResetPassword();+ const [, { mutateAsync: resetPassword }] = useResetPassword({+ onSuccess: () => {+ redirect("/login?passwordRecoveryEmailSent=1");+ },+ onError: () => undefined,+ });const submit = async (values: FormData) => {try {