From 292758e507bdf64d2273d496fe29e2c07824d3be Mon Sep 17 00:00:00 2001 From: abhimanyurajeesh Date: Fri, 3 Jan 2025 20:04:17 +0530 Subject: [PATCH 1/2] forgot password mutation --- src/components/Auth/Login.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index 392fe43db70..1837e457e4e 100644 --- a/src/components/Auth/Login.tsx +++ b/src/components/Auth/Login.tsx @@ -105,13 +105,17 @@ const Login = (props: { forgot?: boolean }) => { }); return response; }, - onSuccess: () => { - Notification.Success({ - msg: t("password_sent"), - }); + onSuccess: (response) => { + if (response.res && response.res.ok) { + Notification.Success({ + msg: t("password_sent"), + }); + } }, onError: (error: any) => { - setErrors(error); + Notification.Error({ + msg: error.message || t("password_reset_failure"), + }); }, }); From 3f03b580b138d9ee23291aa6c1e98affb340bd50 Mon Sep 17 00:00:00 2001 From: abhimanyurajeesh Date: Fri, 3 Jan 2025 22:10:13 +0530 Subject: [PATCH 2/2] updated --- src/components/Auth/Login.tsx | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index 1837e457e4e..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,24 +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; - }, - onSuccess: (response) => { - if (response.res && response.res.ok) { - Notification.Success({ - msg: t("password_sent"), - }); - } - }, - onError: (error: any) => { - Notification.Error({ - msg: error.message || t("password_reset_failure"), - }); + const { mutate: submitForgetPassword } = useMutation({ + mutationFn: mutate(routes.forgotPassword), + onSuccess: () => { + toast.success(t("password_sent")); }, }); @@ -296,7 +283,7 @@ const Login = (props: { forgot?: boolean }) => { const valid = validateForgetData(); if (!valid) return; - forgotPasswordMutation.mutate(valid); + submitForgetPassword(valid); }; const onCaptchaChange = (value: any) => { @@ -326,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,