|
|
|
|
@ -7,6 +7,8 @@ import { useState } from 'react' |
|
|
|
|
import { isValidEmail } from 'features/AuthServiceApp/helpers/isValidEmail' |
|
|
|
|
import { isValidPassword } from 'features/AuthServiceApp/helpers/isValidPassword' |
|
|
|
|
|
|
|
|
|
import { PAGES } from 'features/AuthServiceApp/config/pages' |
|
|
|
|
|
|
|
|
|
export const useAuthFields = (page: 'login'|'registration') => { |
|
|
|
|
const [email, setEmail] = useState('') |
|
|
|
|
const [password, setPassword] = useState('') |
|
|
|
|
@ -20,7 +22,7 @@ export const useAuthFields = (page: 'login'|'registration') => { |
|
|
|
|
const onEmailChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => { |
|
|
|
|
setError('') |
|
|
|
|
setEmail(value) |
|
|
|
|
const isRegisterPage = page === 'registration' |
|
|
|
|
const isRegisterPage = page === PAGES.registration |
|
|
|
|
if (password.length && !checkPassword(password) && isRegisterPage) { |
|
|
|
|
setError('check_password') |
|
|
|
|
} |
|
|
|
|
@ -29,7 +31,7 @@ export const useAuthFields = (page: 'login'|'registration') => { |
|
|
|
|
const onPasswordChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => { |
|
|
|
|
setError('') |
|
|
|
|
setPassword(value) |
|
|
|
|
const isRegisterPage = page === 'registration' |
|
|
|
|
const isRegisterPage = page === PAGES.registration |
|
|
|
|
if (!checkPassword(value) && isRegisterPage) { |
|
|
|
|
setError('check_password') |
|
|
|
|
} |
|
|
|
|
|