Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…awa-admin into group2
  • Loading branch information
GlenDsza committed Nov 2, 2024
2 parents deade9f + c49a58c commit c3ca420
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/screens/LoginPage/LoginPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const MOCKS = [
request: {
query: SIGNUP_MUTATION,
variables: {
firstName: 'John',
lastName: 'Doe',
firstName: 'John Patrick ',
lastName: 'Doe ',
email: '[email protected]',
password: 'johnDoe',
},
Expand Down
21 changes: 12 additions & 9 deletions src/screens/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const loginPage = (): JSX.Element => {
});

return data.recaptcha;
} catch (error) {
} catch {
/* istanbul ignore next */
toast.error(t('captchaError') as string);
}
Expand Down Expand Up @@ -204,8 +204,11 @@ const loginPage = (): JSX.Element => {
toast.error(t('Please_check_the_captcha') as string);
return;
}
const isValidatedString = (value: string): boolean =>
/^[a-zA-Z]+$/.test(value);

const isValidName = (value: string): boolean => {
// Allow letters, spaces, and hyphens, but not consecutive spaces or hyphens
return /^[a-zA-Z]+(?:[-\s][a-zA-Z]+)*$/.test(value.trim());
};

const validatePassword = (password: string): boolean => {
const lengthCheck = new RegExp('^.{6,}$');
Expand All @@ -219,10 +222,10 @@ const loginPage = (): JSX.Element => {
};

if (
isValidatedString(signfirstName) &&
isValidatedString(signlastName) &&
signfirstName.length > 1 &&
signlastName.length > 1 &&
isValidName(signfirstName) &&
isValidName(signlastName) &&
signfirstName.trim().length > 1 &&
signlastName.trim().length > 1 &&
signEmail.length >= 8 &&
signPassword.length > 1 &&
validatePassword(signPassword)
Expand Down Expand Up @@ -264,10 +267,10 @@ const loginPage = (): JSX.Element => {
toast.warn(t('passwordMismatches') as string);
}
} else {
if (!isValidatedString(signfirstName)) {
if (!isValidName(signfirstName)) {
toast.warn(t('firstName_invalid') as string);
}
if (!isValidatedString(signlastName)) {
if (!isValidName(signlastName)) {
toast.warn(t('lastName_invalid') as string);
}
if (!validatePassword(signPassword)) {
Expand Down

0 comments on commit c3ca420

Please sign in to comment.