From 91d84d975c96d77ddcea9b0d1c5a5ec55b9d58b3 Mon Sep 17 00:00:00 2001 From: Diego Vidal Lopez Date: Sun, 21 Jul 2024 18:46:26 -0600 Subject: [PATCH] feat/Signup: Implement validations for all fields --- src/pages/Signup.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/Signup.jsx b/src/pages/Signup.jsx index 84d9d8a..cef5d1a 100644 --- a/src/pages/Signup.jsx +++ b/src/pages/Signup.jsx @@ -9,13 +9,18 @@ const Signup = () => { const userStatus = useSelector((state) => state.user.status); const successMessage = useSelector((state) => state.user.details.status.message); const errorMessage = useSelector((state) => state.user.details.status.error); + const [ validationError, setValidationError ] = useState(''); const [userData, setUserData] = useState({ name: '', email: '', password: '', }); const handleSignup = () => { - dispatch(registerUser(userData)); + if(userData.name && userData.email && userData.password){ + dispatch(registerUser(userData)); + } else { + setValidationError('Please fill in all fields'); + } }; useEffect(() => { @@ -58,6 +63,7 @@ const Signup = () => { {userStatus === 'loading' && } {errorMessage &&
{errorMessage}
} {successMessage &&
{successMessage}
} + {validationError &&
{validationError}
} );