import React, { useState, useRef } from 'react'; import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { TextField, Button, FormControlLabel, Switch } from '@material-ui/core'; import { useAuth } from '../../hooks/useAuth'; 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 LoginPage: React.FC = () => { const [error, setError] = useState(false); const [remember, setRemember] = useState(true); const classes = useStyles(); const nameRef = useRef(); const passwordRef = useRef(); const { login } = useAuth(); const history = useHistory(); const handleCheck = () => { setRemember(!remember); }; const handleSubmit = async () => { const name = nameRef.current?.value?.toLowerCase(); const password = passwordRef.current?.value; if (name && password) { login(name, password, remember).then(success => { if (success) history.push(`/profile/${name}`); else setError(true); }); } }; const handleRegistration = () => { history.push('/registration'); }; return ( <>
Sign In
} label="Remember me" />
{'Don\'t have an account?'}
Sign up
); }; export default LoginPage;