import React, { useState } from 'react'; import { useHistory } from 'react-router-dom'; import { Formik, Form, Field } from 'formik'; import { makeStyles } from '@material-ui/core/styles'; import { TextField, Button, FormControlLabel, Switch, InputAdornment, IconButton } from '@material-ui/core'; import { Visibility, VisibilityOff } from '@material-ui/icons'; import { useAuth } from '../../hooks/useAuth'; interface Fields { username: string; password: string; remember: boolean; } const useStyles = makeStyles(theme => ({ root: { '& > *': { margin: theme.spacing(1), width: theme.spacing(35) }, display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center' }, formHeader: { textAlign: 'center', fontSize: 25 }, formTransfer: { display: 'flex', justifyContent: 'center' }, transferButton: { marginLeft: 10, color: 'green', cursor: 'pointer' } })); const Login: React.FC = () => { const [error, setError] = useState(false); const [showPassword, setShowPassword] = useState(false); const classes = useStyles(); const { login } = useAuth(); const history = useHistory(); const handleSubmit = async ({ username, password, remember }: Fields) => { if (username && password) { login(username, password, remember).then(success => { if (success) history.push(`/profile/${username}`); else setError(true); }); } else setError(true); }; const handleRegistration = () => { history.push('/registration'); }; const toggleShowPassword = () => { setShowPassword(prevState => !prevState); }; return ( <>
Sign In
{({ values, isSubmitting }) => (
{showPassword ? : } ) }} /> } /> )}
{'Don\'t have an account?'}
Sign up
); }; export default Login;