From 6010da0fe4c9d9a07ac290fd794e17edc892b664 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Wed, 26 Aug 2020 01:42:35 +0300 Subject: fix validate bugs --- src/containers/Registration/Registration.tsx | 66 +++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 7 deletions(-) (limited to 'src/containers/Registration/Registration.tsx') diff --git a/src/containers/Registration/Registration.tsx b/src/containers/Registration/Registration.tsx index c681329..9bcea8e 100644 --- a/src/containers/Registration/Registration.tsx +++ b/src/containers/Registration/Registration.tsx @@ -3,6 +3,8 @@ import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import TextField from '@material-ui/core/TextField'; import Button from '@material-ui/core/Button'; +import CheckCircleIcon from '@material-ui/icons/CheckCircle'; +import InputAdornment from '@material-ui/core/InputAdornment'; import { post } from '../../requests'; import { useAuth } from '../../hooks/useAuth'; @@ -33,8 +35,19 @@ const useStyles = makeStyles(theme => ({ } })); +const inputStyle = { WebkitBoxShadow: '0 0 0 1000px snow inset' }; + + const Registration: React.FC = () => { - const [error, setError] = useState(false); + const errorOutputs = { + usernameError: 'Username is required', + emailError: 'Invalid email address', + passwordError: 'Should be at least 6 characters' + }; + const [errorPassword, setErrorPassword] = useState(false); + const [errorEmail, setErrorEmail] = useState(false); + const [errorUsername, setErrorUsername] = useState(false); + const classes = useStyles(); const usernameRef = useRef(); const emailRef = useRef(); @@ -50,13 +63,23 @@ const Registration: React.FC = () => { post('/users', { username, password, email }) .then(() => login(username, password)) .then(() => history.push(`/profile/${username}`)); - } else setError(true); + } }; const handleLogin = () => { history.push('/login'); }; + const handleLoginChange = (e: React.ChangeEvent) => { + setErrorUsername(e.currentTarget.value.length === 0); + }; + const handleEmailChange = (e: React.ChangeEvent) => { + setErrorEmail(!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(e.currentTarget.value)); + }; + const handlePasswordChange = (e: React.ChangeEvent) => { + setErrorPassword(e.currentTarget.value.length < 6); + }; + return ( <>
Sign Up
@@ -64,18 +87,47 @@ const Registration: React.FC = () => { + + + + ), + inputProps: { + style: inputStyle + } + }} /> - + + + ), + inputProps: { + style: inputStyle + } + }} /> -- cgit v1.2.3