Newer
Older
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
'& > *': {
margin: theme.spacing(0),
},
},
form: {
width: '100%', // Fix IE 11 issue.
marginTop: theme.spacing(1),
},
submit: {
margin: theme.spacing(3, 0, 2),
},
}),
);
export const SignInForm: React.FC = () => {
interface formData {
email: string;
password: string;
}
const defaultValues: formData = {
email: '',
password: '',
};
const [formValues, setFormValues] = useState<formData>(defaultValues);
const handleSubmit = (event: React.FormEvent): void => {
if (!isEmailValid(formValues.email)) errors.push('email');
<form className={classes.form} onSubmit={handleSubmit} data-testid="Form">
<TextField
variant="outlined"
margin="normal"
required
fullWidth
id="email"
label="Email Address"
name="email"
autoComplete="email"
autoFocus
onChange={(event) =>
setFormValues({ ...formValues, email: String(event.target.value) })
}
/>
<TextField
variant="outlined"
margin="normal"
required
fullWidth
name="password"
label="Password"
type="password"
id="password"
autoComplete="current-password"
onChange={(event) =>
setFormValues({ ...formValues, password: String(event.target.value) })
}
/>
<Button
type="submit"
fullWidth
variant="contained"
color="primary"
className={classes.submit}
>
Sign In
</Button>
</form>
);
};