This repository has been archived by the owner on Aug 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
SignInForm.js
69 lines (63 loc) · 1.65 KB
/
SignInForm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from "react";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import FormHelperText from "@material-ui/core/FormHelperText";
import { useMaterialUIForm } from "hooks/forms";
import ButtonWithProgress from "./ButtonWithProgress";
const styles = theme => ({
submit: {
marginTop: theme.spacing.unit * 2
}
});
const SignInForm = ({ classes, serverError, loading, userSignIn }) => {
const validate = values => {
let errors = {};
if (!values.email) {
errors.email = "Email address is required.";
}
if (!values.password) {
errors.password = "Password is required.";
}
return errors;
};
const { handleSubmit, attachValidation } = useMaterialUIForm(
userSignIn,
validate
);
return (
<form onSubmit={handleSubmit}>
{serverError ? (
<FormHelperText error={true}>{serverError.message}</FormHelperText>
) : null}
<TextField
id="email"
type="email"
label="Email address"
name="email"
autoComplete="email"
fullWidth
margin="normal"
{...attachValidation("email")}
/>
<TextField
id="password"
type="password"
label="Password"
name="password"
fullWidth
margin="normal"
{...attachValidation("password")}
/>
<ButtonWithProgress
variant="contained"
color="primary"
type="submit"
loading={loading || false}
className={classes.submit}
>
Sign In
</ButtonWithProgress>
</form>
);
};
export default withStyles(styles)(SignInForm);