@@ -4,9 +4,9 @@ import { Formik, Form, withFormik } from 'formik';
4
4
import * as Yup from 'yup' ;
5
5
import { Grid , TextField , Button , Link , withStyles } from '@material-ui/core' ;
6
6
7
- import { Auth as AuthLayout } from '../../layouts' ;
8
7
import * as NavigationUtils from '../../../utils/Navigation' ;
9
8
import * as UrlUtils from '../../../utils/URL' ;
9
+ import { Auth as AuthLayout } from '../../layouts' ;
10
10
11
11
class PasswordRequest extends Component {
12
12
state = {
@@ -37,22 +37,20 @@ class PasswordRequest extends Component {
37
37
routeSuffix,
38
38
} ) ;
39
39
40
- if ( response . status === 200 ) {
41
- this . setState ( {
42
- loading : false ,
43
- message : {
44
- type : 'success' ,
45
- title : 'Link Sent' ,
46
- body : (
47
- < h4 >
48
- Check your email to reset your account.
49
- < br /> Thank you.
50
- </ h4 >
51
- ) ,
52
- action : ( ) => history . push ( `/signin?username=${ email } ` ) ,
53
- } ,
54
- } ) ;
55
- }
40
+ this . setState ( {
41
+ loading : false ,
42
+ message : {
43
+ type : 'success' ,
44
+ title : 'Link Sent' ,
45
+ body : (
46
+ < h4 >
47
+ Check your email to reset your account.
48
+ < br /> Thank you.
49
+ </ h4 >
50
+ ) ,
51
+ action : ( ) => history . push ( `/signin?username=${ email } ` ) ,
52
+ } ,
53
+ } ) ;
56
54
} catch ( error ) {
57
55
if ( ! error . response ) {
58
56
this . setState ( {
@@ -95,8 +93,7 @@ class PasswordRequest extends Component {
95
93
}
96
94
97
95
render ( ) {
98
- const { classes, location, setErrors, errors : formErrors } = this . props ;
99
-
96
+ const { classes, location } = this . props ;
100
97
const { loading, message, email } = this . state ;
101
98
102
99
return (
@@ -114,88 +111,78 @@ class PasswordRequest extends Component {
114
111
: email ,
115
112
} }
116
113
onSubmit = { this . handleRequestPasswordSubmit }
117
- validate = { values => {
118
- setErrors ( { } ) ;
119
- } }
120
114
validationSchema = { Yup . object ( ) . shape ( {
121
115
email : Yup . string ( ) . required (
122
- `The email field is required` ,
116
+ Lang . get ( 'validation.required' , {
117
+ attribute : 'email' ,
118
+ } ) ,
123
119
) ,
124
120
} ) }
125
121
>
126
- { ( { values, handleChange, errors, isSubmitting } ) => {
127
- if ( formErrors && Object . keys ( formErrors ) . length > 0 ) {
128
- errors = formErrors ;
129
- }
130
-
131
- return (
132
- < Form >
133
- < Grid container direction = "column" >
134
- < Grid item className = { classes . formGroup } >
135
- < TextField
136
- id = "email"
137
- type = "email"
138
- label = "Email"
139
- value = { values . email }
140
- onChange = { handleChange }
141
- variant = "outlined"
142
- fullWidth
143
- error = { errors . hasOwnProperty (
144
- 'email' ,
145
- ) }
146
- helperText = {
147
- errors . hasOwnProperty (
148
- 'email' ,
149
- ) && errors . email
150
- }
151
- />
152
- </ Grid >
153
-
154
- < Grid item className = { classes . formGroup } >
155
- < Link
156
- component = { props => (
157
- < RouterLink
158
- { ...props }
159
- to = { {
160
- search : UrlUtils . _queryString (
161
- {
162
- username : email ,
163
- } ,
164
- ) ,
165
- pathname : NavigationUtils . _route (
166
- 'auth.signin' ,
167
- ) ,
168
- } }
169
- />
170
- ) }
171
- >
172
- { Lang . get ( 'navigation.signin' ) }
173
- </ Link >
174
- </ Grid >
122
+ { ( { values, handleChange, errors, isSubmitting } ) => (
123
+ < Form >
124
+ < Grid container direction = "column" >
125
+ < Grid item className = { classes . formGroup } >
126
+ < TextField
127
+ id = "email"
128
+ type = "email"
129
+ label = "Email"
130
+ value = { values . email }
131
+ onChange = { handleChange }
132
+ variant = "outlined"
133
+ fullWidth
134
+ error = { errors . hasOwnProperty ( 'email' ) }
135
+ helperText = {
136
+ errors . hasOwnProperty ( 'email' ) &&
137
+ errors . email
138
+ }
139
+ />
175
140
</ Grid >
176
141
177
- < Grid container justify = "space-between" >
178
- < Grid item />
179
-
180
- < Grid item className = { classes . formGroup } >
181
- < Button
182
- type = "submit"
183
- variant = "contained"
184
- color = "primary"
185
- disabled = {
186
- ( errors &&
187
- Object . keys ( errors ) . length >
188
- 0 ) ||
189
- isSubmitting
190
- }
191
- >
192
- { Lang . get ( 'navigation.send_link' ) }
193
- </ Button >
194
- </ Grid >
142
+ < Grid item className = { classes . formGroup } >
143
+ < Link
144
+ component = { props => (
145
+ < RouterLink
146
+ { ...props }
147
+ to = { {
148
+ search : UrlUtils . _queryString (
149
+ {
150
+ username : email ,
151
+ } ,
152
+ ) ,
153
+ pathname : NavigationUtils . _route (
154
+ 'auth.signin' ,
155
+ ) ,
156
+ } }
157
+ />
158
+ ) }
159
+ >
160
+ { Lang . get ( 'navigation.signin' ) }
161
+ </ Link >
195
162
</ Grid >
196
- </ Form >
197
- ) ;
198
- } }
163
+ </ Grid >
164
+
165
+ < Grid container justify = "space-between" >
166
+ < Grid item />
167
+
168
+ < Grid item className = { classes . formGroup } >
169
+ < Button
170
+ type = "submit"
171
+ variant = "contained"
172
+ color = "primary"
173
+ disabled = {
174
+ ( errors &&
175
+ Object . keys ( errors ) . length >
176
+ 0 ) ||
177
+ isSubmitting
178
+ }
179
+ >
180
+ { Lang . get ( 'navigation.send_link' ) }
181
+ </ Button >
182
+ </ Grid >
183
+ </ Grid >
184
+ </ Form >
185
+ ) }
199
186
</ Formik >
200
187
</ AuthLayout >
201
188
) ;
0 commit comments