Refactor PasswordPanel to pass navigation context via state to ForgotPassword using TextLink | Update ForgotPassword and CheckEmail to handle navigation context for Back links, ensuring users return to the correct page after password reset | Fix TextLink prop usage to avoid warnings by passing state and href correctly | Ensure error messages and navigation links use translation keys for localization

This commit is contained in:
llpingll committed 2026-01-25 22:57:36 +00:00
1 parent f564636cb4
commit 4ce4a124d6
5 files changed
+41 -11

No files matched your search

+10 -3
View File
@@ -2,7 +2,7 @@ import { Box, Button, Stack, Typography } from "@mui/material";
import { useEffect, useState } from "react";
import { useTheme } from "@emotion/react";
import { useDispatch } from "react-redux";
import { useNavigate } from "react-router-dom";
import { useNavigate, useLocation } from "react-router-dom";
import { createToast } from "../../Utils/toastUtils.jsx";
import { forgotPassword } from "../../Features/Auth/authSlice.js";
import { Trans, useTranslation } from "react-i18next";
@@ -17,6 +17,7 @@ const CheckEmail = () => {
const navigate = useNavigate();
const dispatch = useDispatch();
const { t } = useTranslation();
const location = useLocation();
const [email, setEmail] = useState();
const [disabled, setDisabled] = useState(false);
@@ -83,7 +84,9 @@ const CheckEmail = () => {
const handleNavigate = () => {
sessionStorage.removeItem("email");
navigate("/login");
location.state?.from
? navigate(location.state.from, { replace: true })
: navigate("/login");
};
return (
@@ -219,7 +222,11 @@ const CheckEmail = () => {
>
<Typography display="inline-block">
<Trans
i18nKey="auth.forgotPassword.links.login"
i18nKey={
location.state?.from === "/account/password"
? "auth.forgotPassword.links.accountPassword"
: "auth.forgotPassword.links.login"
}
components={{
a: (
<Typography
+14 -5
View File
@@ -5,7 +5,7 @@ import { useDispatch, useSelector } from "react-redux";
import { forgotPassword } from "../../Features/Auth/authSlice.js";
import { useEffect, useState } from "react";
import { newOrChangedCredentials } from "../../Validation/validation.js";
import { useNavigate } from "react-router-dom";
import { useNavigate, useLocation } from "react-router-dom";
import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx";
import Logo from "@/assets/icons/checkmate-icon.svg?react";
import Background from "@/assets/Images/background-grid.svg?react";
@@ -18,6 +18,7 @@ const ForgotPassword = () => {
const navigate = useNavigate();
const dispatch = useDispatch();
const theme = useTheme();
const location = useLocation();
const { isLoading } = useSelector((state) => state.auth);
const [errors, setErrors] = useState({});
@@ -51,11 +52,13 @@ const ForgotPassword = () => {
const action = await dispatch(forgotPassword(form));
if (action.payload.success) {
sessionStorage.setItem("email", form.email);
navigate("/check-email");
navigate("/check-email", {
state: location.state || { from: "/login" } // Preserve original from, fallback to login
});
createToast({
body: t("auth.forgotPassword.toasts.sent").replace("<email/>", form.email),
});
} else {
} else {
if (action.payload) {
// dispatch errors
createToast({
@@ -86,7 +89,9 @@ const ForgotPassword = () => {
const handleNavigate = () => {
sessionStorage.removeItem("email");
navigate("/login");
location.state?.from
? navigate(location.state.from, { replace: true })
: navigate("/login");
};
return (
@@ -212,7 +217,11 @@ const ForgotPassword = () => {
>
<Typography display="inline-block">
<Trans
i18nKey="auth.forgotPassword.links.login"
i18nKey={
location.state?.from
? "auth.forgotPassword.links.accountPassword"
: "auth.forgotPassword.links.login"
}
components={{
a: (
<Typography