From 6f599f7baf10ab7e40cadc829f99987e7b85915f Mon Sep 17 00:00:00 2001 From: renata_vl Date: Wed, 20 Nov 2024 16:27:22 +0200 Subject: [PATCH] Fixed logIn form validation --- .../guest-home-page/login-dialog/LoginDialog.jsx | 4 ++-- .../guest-home-page/login-form/LoginForm.tsx | 6 +++++- src/utils/validations/login.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/containers/guest-home-page/login-dialog/LoginDialog.jsx b/src/containers/guest-home-page/login-dialog/LoginDialog.jsx index 1b0dd36bb..d11681784 100644 --- a/src/containers/guest-home-page/login-dialog/LoginDialog.jsx +++ b/src/containers/guest-home-page/login-dialog/LoginDialog.jsx @@ -8,7 +8,7 @@ import useForm from '~/hooks/use-form' import { useLoginMutation } from '~/services/auth-service' import { useModalContext } from '~/context/modal-context' import { useAppDispatch } from '~/hooks/use-redux' -import { email } from '~/utils/validations/login' +import { email, logInPassword } from '~/utils/validations/login' import loginImg from '~/assets/img/login-dialog/login.svg' import { login, snackbarVariants } from '~/constants' @@ -47,7 +47,7 @@ const LoginDialog = () => { } }, initialValues: { email: '', password: '', rememberMe: false }, - validations: { email } + validations: { email, password: logInPassword } } ) diff --git a/src/containers/guest-home-page/login-form/LoginForm.tsx b/src/containers/guest-home-page/login-form/LoginForm.tsx index 09f4f89c1..f4c730a1c 100644 --- a/src/containers/guest-home-page/login-form/LoginForm.tsx +++ b/src/containers/guest-home-page/login-form/LoginForm.tsx @@ -108,7 +108,11 @@ const LoginForm: React.FC = ({ elem === '') + } loading={authLoading} sx={styles.loginButton} type='submit' diff --git a/src/utils/validations/login.js b/src/utils/validations/login.js index a294530a0..8205feda9 100644 --- a/src/utils/validations/login.js +++ b/src/utils/validations/login.js @@ -26,3 +26,14 @@ export const confirmPassword = (password, data) => { : '' }) } + +export const logInPassword = (password) => { + return emptyField({ + value: password, + emptyMessage: 'common.errorMessages.emptyField', + helperText: + password.length < 8 || password.length > 25 + ? 'common.errorMessages.passwordLength' + : '' + }) +}