Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Forgot password error should be handled properly #9707

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading