@@ -4,9 +4,9 @@ import React from "react"
4
4
import * as Yup from "yup"
5
5
6
6
import { Welcome } from "./Welcome"
7
- import { FormTextField } from "../Form"
8
7
import FormHelperText from "@material-ui/core/FormHelperText"
9
8
import { LoadingButton } from "./../Button"
9
+ import TextField from "@material-ui/core/TextField"
10
10
11
11
/**
12
12
* BuiltInAuthFormValues describes a form using built-in (email/password)
@@ -18,8 +18,14 @@ interface BuiltInAuthFormValues {
18
18
password : string
19
19
}
20
20
21
+ export const LANGUAGE = {
22
+ emailInvalid : "Please enter a valid email address." ,
23
+ emailRequired : "Please enter an email address." ,
24
+ authErrorMessage : "Incorrect email or password."
25
+ }
26
+
21
27
const validationSchema = Yup . object ( {
22
- email : Yup . string ( ) . required ( "Email is required." ) ,
28
+ email : Yup . string ( ) . trim ( ) . email ( LANGUAGE . emailInvalid ) . required ( LANGUAGE . emailRequired ) ,
23
29
password : Yup . string ( ) ,
24
30
} )
25
31
@@ -59,52 +65,38 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess
59
65
< >
60
66
< Welcome />
61
67
< form onSubmit = { form . handleSubmit } >
62
- < div >
63
- < FormTextField
64
- label = "Email"
65
- autoComplete = "email"
66
- autoFocus
67
- className = { styles . loginTextField }
68
- eventTransform = { ( email : string ) => email . trim ( ) }
69
- form = { form }
70
- formFieldName = "email"
71
- fullWidth
72
- inputProps = { {
73
- id : "signin-form-inpt-email" ,
74
- } }
75
- variant = "outlined"
76
- />
77
- < FormTextField
78
- label = "Password"
79
- autoComplete = "current-password"
80
- className = { styles . loginTextField }
81
- form = { form }
82
- formFieldName = "password"
83
- fullWidth
84
- inputProps = { {
85
- id : "signin-form-inpt-password" ,
86
- } }
87
- isPassword
88
- variant = "outlined"
89
- />
90
- { authErrorMessage && (
91
- < FormHelperText data-testid = "sign-in-error" error >
92
- { authErrorMessage }
93
- </ FormHelperText >
94
- ) }
95
- </ div >
96
- < div className = { styles . submitBtn } >
97
- < LoadingButton
98
- color = "primary"
99
- loading = { isLoading }
100
- fullWidth
101
- id = "signin-form-submit"
102
- type = "submit"
103
- variant = "contained"
104
- >
105
- { isLoading ? "" : "Sign In" }
106
- </ LoadingButton >
107
- </ div >
68
+ < TextField
69
+ { ...form . getFieldProps ( "email" ) }
70
+ autoFocus
71
+ autoComplete = "email"
72
+ className = { styles . loginTextField }
73
+ error = { form . touched . email && Boolean ( form . errors . email ) }
74
+ fullWidth
75
+ helperText = { form . touched . email && form . errors . email }
76
+ id = "email"
77
+ label = "Email"
78
+ variant = "outlined"
79
+ />
80
+ < TextField
81
+ { ...form . getFieldProps ( "password" ) }
82
+ autoComplete = "current-password"
83
+ className = { styles . loginTextField }
84
+ fullWidth
85
+ id = "password"
86
+ label = "Password"
87
+ type = "password"
88
+ variant = "outlined"
89
+ />
90
+ { authErrorMessage && (
91
+ < FormHelperText data-testid = "sign-in-error" error >
92
+ { LANGUAGE . authErrorMessage }
93
+ </ FormHelperText >
94
+ ) }
95
+ < div className = { styles . submitBtn } >
96
+ < LoadingButton color = "primary" loading = { isLoading } fullWidth type = "submit" variant = "contained" >
97
+ { isLoading ? "" : "Sign In" }
98
+ </ LoadingButton >
99
+ </ div >
108
100
</ form >
109
101
</ >
110
102
)
0 commit comments