From 564b2e6f5894a4c249f0237f49abc916408c5618 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Sat, 13 Apr 2024 21:36:02 +0200 Subject: [PATCH] Small fix --- .../Components/Inputs/ProjectNameInput.tsx | 2 +- frontend/src/Components/Register.tsx | 46 +++++++++---------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/frontend/src/Components/Inputs/ProjectNameInput.tsx b/frontend/src/Components/Inputs/ProjectNameInput.tsx index af7ce9f..de28c12 100644 --- a/frontend/src/Components/Inputs/ProjectNameInput.tsx +++ b/frontend/src/Components/Inputs/ProjectNameInput.tsx @@ -36,7 +36,7 @@ export default function ProjectNameInput(props: {

)} {alphanumeric.test(props.name) && - name.length >= projNameHighLimit && + name.length >= projNameLowLimit && name.length <= projNameHighLimit && (

Valid project name! diff --git a/frontend/src/Components/Register.tsx b/frontend/src/Components/Register.tsx index 281042f..7310e4f 100644 --- a/frontend/src/Components/Register.tsx +++ b/frontend/src/Components/Register.tsx @@ -17,34 +17,30 @@ import { * @returns The JSX element representing the registration form. */ export default function Register(): JSX.Element { - const [username, setUsername] = useState(); - const [password, setPassword] = useState(); - const [errMessage, setErrMessage] = useState(); + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + const [errMessage, setErrMessage] = useState(""); const handleRegister = async (): Promise => { - if (username !== undefined) { - if ( - username.length > usernameUpLimit || - username.length < usernameLowLimit || - !alphanumeric.test(username) - ) { - alert( - "Please provide valid username: \n-Between 5-10 characters \n-No special characters (.-!?/*)", - ); - return; - } + if ( + username.length > usernameUpLimit || + username.length < usernameLowLimit || + !alphanumeric.test(username) + ) { + alert( + "Please provide valid username: \n-Between 5-10 characters \n-No special characters (.-!?/*)", + ); + return; } - if (password !== undefined) { - if (password.length !== passwordLength || !lowercase.test(password)) { - alert( - "Please provide valid password: \n-Exactly 6 characters \n-No uppercase letters \n-No numbers \n-No special characters (.-!?/*)", - ); - return; - } + if (password.length !== passwordLength || !lowercase.test(password)) { + alert( + "Please provide valid password: \n-Exactly 6 characters \n-No uppercase letters \n-No numbers \n-No special characters (.-!?/*)", + ); + return; } const newUser: NewUser = { - username: username?.replace(/ /g, "") ?? "", - password: password ?? "", + username: username, + password: password, }; const response = await api.registerUser(newUser); if (response.success) { @@ -78,14 +74,14 @@ export default function Register(): JSX.Element { { setUsername(e.target.value); }} />

{ setPassword(e.target.value); }}