Skip to content

Commit 68c4c3d

Browse files
Fix: Forgot password error should be handled properly (ohcnetwork#9707)
* forgot password mutation * updated
1 parent d521adb commit 68c4c3d

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

src/components/Auth/Login.tsx

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Link } from "raviger";
44
import { useEffect, useState } from "react";
55
import ReCaptcha from "react-google-recaptcha";
66
import { useTranslation } from "react-i18next";
7+
import { toast } from "sonner";
78

89
import { cn } from "@/lib/utils";
910

@@ -98,20 +99,10 @@ const Login = (props: { forgot?: boolean }) => {
9899
});
99100

100101
// Forgot Password Mutation
101-
const forgotPasswordMutation = useMutation({
102-
mutationFn: async (data: { username: string }) => {
103-
const response = await request(routes.forgotPassword, {
104-
body: data,
105-
});
106-
return response;
107-
},
102+
const { mutate: submitForgetPassword } = useMutation({
103+
mutationFn: mutate(routes.forgotPassword),
108104
onSuccess: () => {
109-
Notification.Success({
110-
msg: t("password_sent"),
111-
});
112-
},
113-
onError: (error: any) => {
114-
setErrors(error);
105+
toast.success(t("password_sent"));
115106
},
116107
});
117108

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

295-
forgotPasswordMutation.mutate(valid);
286+
submitForgetPassword(valid);
296287
};
297288

298289
const onCaptchaChange = (value: any) => {
@@ -322,10 +313,7 @@ const Login = (props: { forgot?: boolean }) => {
322313

323314
// Loading state derived from mutations
324315
const isLoading =
325-
staffLoginMutation.isPending ||
326-
forgotPasswordMutation.isPending ||
327-
sendOtpPending ||
328-
verifyOtpPending;
316+
staffLoginMutation.isPending || sendOtpPending || verifyOtpPending;
329317

330318
const logos = [stateLogo, customLogo].filter(
331319
(logo) => logo?.light || logo?.dark,

0 commit comments

Comments
 (0)