Skip to content

Commit

Permalink
Fixed logIn form validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Renatavl committed Nov 20, 2024
1 parent ff1cf99 commit 6f599f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/containers/guest-home-page/login-dialog/LoginDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -47,7 +47,7 @@ const LoginDialog = () => {
}
},
initialValues: { email: '', password: '', rememberMe: false },
validations: { email }
validations: { email, password: logInPassword }
}
)

Expand Down
6 changes: 5 additions & 1 deletion src/containers/guest-home-page/login-form/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ const LoginForm: React.FC<LoginFormProps> = ({
</Box>

<AppButton
disabled={!data.email || !data.password}
disabled={
!data.email ||
!data.password ||
!Object.values(errors).every((elem) => elem === '')
}
loading={authLoading}
sx={styles.loginButton}
type='submit'
Expand Down
11 changes: 11 additions & 0 deletions src/utils/validations/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
: ''
})
}

0 comments on commit 6f599f7

Please sign in to comment.