From be765bb98e19fdc755418cdf4d2eb19d0aa15ecd Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Fri, 28 Aug 2020 19:41:42 +0300 Subject: fix eslint errors --- src/containers/Registration/Registration.tsx | 42 +++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/containers/Registration/Registration.tsx b/src/containers/Registration/Registration.tsx index e250397..955d900 100644 --- a/src/containers/Registration/Registration.tsx +++ b/src/containers/Registration/Registration.tsx @@ -1,4 +1,9 @@ -import React, {useState, useRef, FormEvent, useMemo} from 'react'; +import React, { + useState, + useRef, + FormEvent, + useMemo +} from 'react'; import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { @@ -7,7 +12,7 @@ import { InputAdornment, IconButton } from '@material-ui/core'; -import { CheckCircle, Visibility, VisibilityOff } from '@material-ui/icons'; +import { Visibility, VisibilityOff } from '@material-ui/icons'; import { post } from '../../requests'; import { useAuth } from '../../hooks/useAuth'; @@ -46,9 +51,9 @@ interface ErrorStates { const Registration: React.FC = () => { const [values, setValues] = useState({ - username: undefined, - email: undefined, - password: undefined, + username: false, + email: false, + password: false }); const [showPassword, setShowPassword] = useState(false); @@ -60,16 +65,15 @@ const Registration: React.FC = () => { const history = useHistory(); const isValid = useMemo(() => { - return values.username && values.email && values.password; - },[values]); + return !values.username && !values.email && !values.password; + }, [values]); - const handleSubmit = (event: FormEvent) => { + const handleSubmit = (event:FormEvent) => { event.preventDefault(); const username = usernameRef.current?.value?.toLowerCase(); const password = passwordRef.current?.value; const email = emailRef.current?.value; if (username && password && isValid) { - console.log('yes'); post('/users', { username, password, email }) .then(() => login(username, password)) .then(() => history.push(`/profile/${username}`)); @@ -88,19 +92,19 @@ const Registration: React.FC = () => { const handleUsernameChange = (e: React.FocusEvent) => { setValues({ ...values, - username: e.currentTarget.value.length > 0 + username: e.currentTarget.value.length === 0 }); }; const handleEmailChange = (e: React.FocusEvent) => { setValues({ ...values, - email: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(e.currentTarget.value) + email: !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(e.currentTarget.value) }); }; const handlePasswordChange = (e: React.FocusEvent) => { setValues({ ...values, - password: e.currentTarget.value.length > 6 + password: e.currentTarget.value.length < 6 }); }; @@ -111,24 +115,24 @@ const Registration: React.FC = () => { { ) }} /> - +
Already have an account?
-- cgit v1.2.3