From 100b3f5493bc24e9889c376dcfc797564582c41c Mon Sep 17 00:00:00 2001 From: Andrei Dekterev <57942757+dekterev@users.noreply.github.com> Date: Mon, 29 Nov 2021 18:12:39 +0400 Subject: [PATCH] fix(fix-checkpass): fix checkpassword in register page (#576) --- src/features/AuthServiceApp/components/Login/hooks.tsx | 2 +- .../AuthServiceApp/components/Registration/hooks.tsx | 2 +- src/features/AuthServiceApp/hooks/useAuthFields.tsx | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/features/AuthServiceApp/components/Login/hooks.tsx b/src/features/AuthServiceApp/components/Login/hooks.tsx index 8ca1649f..8d5b9102 100644 --- a/src/features/AuthServiceApp/components/Login/hooks.tsx +++ b/src/features/AuthServiceApp/components/Login/hooks.tsx @@ -28,7 +28,7 @@ export const useLoginForm = () => { onPasswordBlur, onPasswordChange, password, - } = useAuthFields() + } = useAuthFields('login') const isSubmitDisabled = ( !email diff --git a/src/features/AuthServiceApp/components/Registration/hooks.tsx b/src/features/AuthServiceApp/components/Registration/hooks.tsx index 945b0b18..fef571be 100644 --- a/src/features/AuthServiceApp/components/Registration/hooks.tsx +++ b/src/features/AuthServiceApp/components/Registration/hooks.tsx @@ -17,7 +17,7 @@ export const useRegistrationForm = () => { onPasswordBlur, onPasswordChange, password, - } = useAuthFields() + } = useAuthFields('registration') const isSubmitDisabled = ( !email diff --git a/src/features/AuthServiceApp/hooks/useAuthFields.tsx b/src/features/AuthServiceApp/hooks/useAuthFields.tsx index 3bc5b3f1..89831b9a 100644 --- a/src/features/AuthServiceApp/hooks/useAuthFields.tsx +++ b/src/features/AuthServiceApp/hooks/useAuthFields.tsx @@ -7,7 +7,7 @@ import { useState } from 'react' import { isValidEmail } from 'features/AuthServiceApp/helpers/isValidEmail' import { isValidPassword } from 'features/AuthServiceApp/helpers/isValidPassword' -export const useAuthFields = () => { +export const useAuthFields = (page: 'login'|'registration') => { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') @@ -25,7 +25,8 @@ export const useAuthFields = () => { const onPasswordChange = ({ target: { value } }: ChangeEvent) => { setError('') setPassword(value) - if (!checkPassword(value)) { + const isRegisterPage = page === 'registration' + if (!checkPassword(value) && isRegisterPage) { setError('check_password') } }