Skip to content

Commit

Permalink
Fix: Forgot password error should be handled properly (#9707)
Browse files Browse the repository at this point in the history
* forgot password mutation

* updated
  • Loading branch information
abhimanyurajeesh authored Jan 3, 2025
1 parent d521adb commit 68c4c3d
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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"));
},
});

Expand Down Expand Up @@ -292,7 +283,7 @@ const Login = (props: { forgot?: boolean }) => {
const valid = validateForgetData();
if (!valid) return;

forgotPasswordMutation.mutate(valid);
submitForgetPassword(valid);
};

const onCaptchaChange = (value: any) => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 68c4c3d

Please sign in to comment.