From 68c4c3dde372261cdf50953742b709f6196a2425 Mon Sep 17 00:00:00 2001 From: Abhimanyu Rajeesh <63541653+abhimanyurajeesh@users.noreply.github.com> Date: Sat, 4 Jan 2025 02:16:40 +0530 Subject: [PATCH] Fix: Forgot password error should be handled properly (#9707) * forgot password mutation * updated --- src/components/Auth/Login.tsx | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index 392fe43db70..531093588e4 100644 --- a/src/components/Auth/Login.tsx +++ b/src/components/Auth/Login.tsx @@ -4,6 +4,7 @@ import { Link } from "raviger"; import { useEffect, useState } from "react"; import ReCaptcha from "react-google-recaptcha"; import { useTranslation } from "react-i18next"; +import { toast } from "sonner"; import { cn } from "@/lib/utils"; @@ -98,20 +99,10 @@ const Login = (props: { forgot?: boolean }) => { }); // Forgot Password Mutation - const forgotPasswordMutation = useMutation({ - mutationFn: async (data: { username: string }) => { - const response = await request(routes.forgotPassword, { - body: data, - }); - return response; - }, + const { mutate: submitForgetPassword } = useMutation({ + mutationFn: mutate(routes.forgotPassword), onSuccess: () => { - Notification.Success({ - msg: t("password_sent"), - }); - }, - onError: (error: any) => { - setErrors(error); + toast.success(t("password_sent")); }, }); @@ -292,7 +283,7 @@ const Login = (props: { forgot?: boolean }) => { const valid = validateForgetData(); if (!valid) return; - forgotPasswordMutation.mutate(valid); + submitForgetPassword(valid); }; const onCaptchaChange = (value: any) => { @@ -322,10 +313,7 @@ const Login = (props: { forgot?: boolean }) => { // Loading state derived from mutations const isLoading = - staffLoginMutation.isPending || - forgotPasswordMutation.isPending || - sendOtpPending || - verifyOtpPending; + staffLoginMutation.isPending || sendOtpPending || verifyOtpPending; const logos = [stateLogo, customLogo].filter( (logo) => logo?.light || logo?.dark,