From b196b345e11db3cc7dc30dfe2bc250c93131ecef Mon Sep 17 00:00:00 2001 From: VividTruthKeeper Date: Fri, 11 Feb 2022 14:03:39 +0500 Subject: [PATCH] adopted input validation in sign in page --- src/components/sign/SignForm.js | 51 ++++++++++++++++++++++++++++++--- src/styles/_global.scss | 6 ++++ src/styles/_sing-in.scss | 11 +++++++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/components/sign/SignForm.js b/src/components/sign/SignForm.js index 9a37f85..c5215b3 100644 --- a/src/components/sign/SignForm.js +++ b/src/components/sign/SignForm.js @@ -1,5 +1,5 @@ // IMPORT MODULES -import React from "react"; +import React, { useState, useEffect, useRef } from "react"; import { Link } from "react-router-dom"; // IMPORT IMAGES @@ -7,6 +7,19 @@ import logout from "../../icons/logout.svg"; import up from "../../icons/clipboard.svg"; const SignForm = ({ setRecoveryOpen }) => { + const [inputValid, setInputValid] = useState({ + login: false, + password: false, + }); + const [btnEnabled, setBtnEnabled] = useState(false); + + useEffect(() => { + if (inputValid.login === true && inputValid.password === true) { + setBtnEnabled(true); + } else { + setBtnEnabled(false); + } + }, [inputValid]); return (
@@ -16,11 +29,41 @@ const SignForm = ({ setRecoveryOpen }) => {
- + { + if (e.target.value !== "") { + setInputValid({ ...inputValid, login: true }); + } else { + setInputValid({ ...inputValid, login: false }); + } + }} + />
- + { + if (e.target.value.length >= 8) { + setInputValid({ ...inputValid, password: true }); + } else { + setInputValid({ ...inputValid, password: false }); + } + }} + /> + + Пароль должен содержать не менее 8 символов +

CAPTCHA

@@ -36,7 +79,7 @@ const SignForm = ({ setRecoveryOpen }) => {
-