From 5d64ee0f30d86a874f71f18ae8e4fcc6a3105b42 Mon Sep 17 00:00:00 2001 From: Daniel Zhang Date: Tue, 12 Nov 2024 20:02:23 -0500 Subject: [PATCH] Change error message location --- .../responsive/ResponsiveAuthContainer.tsx | 2 +- .../components/pages/CreatePasswordPage.tsx | 71 ++++++++++--------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/frontend/src/components/common/responsive/ResponsiveAuthContainer.tsx b/frontend/src/components/common/responsive/ResponsiveAuthContainer.tsx index 169e2f2..d407382 100644 --- a/frontend/src/components/common/responsive/ResponsiveAuthContainer.tsx +++ b/frontend/src/components/common/responsive/ResponsiveAuthContainer.tsx @@ -22,7 +22,7 @@ const ResponsiveAuthContainer = ({ display="inline-flex" flexDirection="column" gap={{ base: "1.12rem", md: "1rem" }} - width={{ md: "16rem" }} + width={{ md: "16rem" }} justifyContent="center" > {children} diff --git a/frontend/src/components/pages/CreatePasswordPage.tsx b/frontend/src/components/pages/CreatePasswordPage.tsx index 136f5e5..09313f4 100644 --- a/frontend/src/components/pages/CreatePasswordPage.tsx +++ b/frontend/src/components/pages/CreatePasswordPage.tsx @@ -9,12 +9,11 @@ import { Text, FormLabel, FormControl, - FormErrorMessage, } from "@chakra-ui/react"; import ResponsiveLogo from "../common/responsive/ResponsiveLogo"; import ResponsivePasswordInput from "../common/responsive/ResponsivePasswordInput"; -import ResponsiveModalWindow from "../common/responsive/ResponsiveModalWindow"; import ResponsiveAuthContainer from "../common/responsive/ResponsiveAuthContainer"; +import ResponsiveModalWindow from "../common/responsive/ResponsiveModalWindow"; import background from "../assets/background.png"; import backgroundMobile from "../assets/background_mobile.png"; @@ -22,8 +21,7 @@ const CreatePasswordPage = (): React.ReactElement => { const [showModal, setShowModal] = React.useState(false); const [password, setPassword] = React.useState(""); const [confirmPassword, setConfirmPassword] = React.useState(""); - const [confirmPasswordError, setConfirmPasswordError] = React.useState(""); - const [passwordError, setPasswordError] = React.useState(""); + const [errorMessage, setErrorMessage] = React.useState(""); const handlePasswordChange = (event: React.ChangeEvent) => { setPassword(event.target.value); @@ -35,22 +33,22 @@ const CreatePasswordPage = (): React.ReactElement => { }; const validatePasswords = () => { - setPasswordError(""); - setConfirmPasswordError(""); - let hasErrors: boolean = false; + setErrorMessage(""); if (password.length < 8) { - hasErrors = true; - setPasswordError("Password must be at least 8 characters."); - } - if (confirmPassword && password !== confirmPassword) { - hasErrors = true; - setConfirmPasswordError("Passwords do not match."); + setErrorMessage("Password must be at least 8 characters."); + return true; } if (confirmPassword.length < 8) { - hasErrors = true; - setConfirmPasswordError("Password must be at least 8 characters."); + setErrorMessage("Password must be at least 8 characters."); + return true; + } + if (confirmPassword && password !== confirmPassword) { + setErrorMessage( + "Your new password cannot be your previous password. Please try again.", + ); + return true; } - return hasErrors; + return false; }; const handleCreateAccount = () => { @@ -124,14 +122,11 @@ const CreatePasswordPage = (): React.ReactElement => { > Create Password: - + - - {passwordError} - @@ -142,28 +137,34 @@ const CreatePasswordPage = (): React.ReactElement => { > Confirm Password: - + - - {confirmPasswordError} - - + + + {errorMessage && ( + + + {errorMessage} + + + )} +