@@ -2,36 +2,38 @@ import PropTypes from 'prop-types';
2
2
import React from 'react' ;
3
3
import { withTranslation } from 'react-i18next' ;
4
4
import { Form , Field } from 'react-final-form' ;
5
+ import { browserHistory } from 'react-router' ;
5
6
import { useDispatch , useSelector } from 'react-redux' ;
6
7
import Button from '../../../common/Button' ;
7
-
8
8
import { validateLogin } from '../../../utils/reduxFormUtils' ;
9
9
import { loginUser , loginUserSuccess , setPreferences } from '../actions' ;
10
10
import { setLanguage } from '../../IDE/actions/preferences' ;
11
11
import { justOpenedProject } from '../../IDE/actions/ide' ;
12
12
13
- function validateAndLoginUser ( ) {
14
- return new Promise ( ( resolve , reject ) => {
15
- loginUser ( formProps )
16
- . then ( ( response ) => {
17
- dispatch ( loginUserSuccess ( response . data ) ) ;
18
- dispatch ( setPreferences ( response . data . preferences ) ) ;
19
- dispatch ( setLanguage ( response . data . preferences . language , { persistPreference : false } ) ) ;
20
- dispatch ( justOpenedProject ( ) ) ;
21
- browserHistory . push ( props . previousPath ) ;
22
- resolve ( ) ;
23
- } )
24
- . catch ( error =>
25
- reject ( { password : error . response . data . message , _error : 'Login failed!' } ) ) ; // eslint-disable-line
26
- } ) ;
27
- }
28
-
29
13
function LoginForm ( props ) {
14
+ const dispatch = useDispatch ( ) ;
15
+ const previousPath = useSelector ( state => state . ide . previousPath ) ;
16
+ function validateAndLoginUser ( formProps ) {
17
+ return new Promise ( ( resolve , reject ) => {
18
+ loginUser ( formProps )
19
+ . then ( ( response ) => {
20
+ dispatch ( loginUserSuccess ( response . data ) ) ;
21
+ dispatch ( setPreferences ( response . data . preferences ) ) ;
22
+ dispatch ( setLanguage ( response . data . preferences . language , { persistPreference : false } ) ) ;
23
+ dispatch ( justOpenedProject ( ) ) ;
24
+ browserHistory . push ( previousPath ) ;
25
+ resolve ( ) ;
26
+ } )
27
+ . catch ( error =>
28
+ reject ( { password : error . response . data . message , _error : 'Login failed!' } ) ) ; // eslint-disable-line
29
+ } ) ;
30
+ }
31
+
30
32
return (
31
33
< Form
32
34
fields = { [ 'email' , 'password' ] }
33
35
validate = { validateLogin }
34
- onSubmit = { props . validateAndLoginUser . bind ( this , props . previousPath ) }
36
+ onSubmit = { validateAndLoginUser }
35
37
>
36
38
{ ( {
37
39
handleSubmit, pristine, submitting
@@ -86,18 +88,7 @@ function LoginForm(props) {
86
88
}
87
89
88
90
LoginForm . propTypes = {
89
- validateAndLoginUser : PropTypes . func . isRequired ,
90
- submitting : PropTypes . bool ,
91
- pristine : PropTypes . bool ,
92
- invalid : PropTypes . bool ,
93
- previousPath : PropTypes . string . isRequired ,
94
91
t : PropTypes . func . isRequired
95
92
} ;
96
93
97
- LoginForm . defaultProps = {
98
- submitting : false ,
99
- pristine : true ,
100
- invalid : false ,
101
- } ;
102
-
103
94
export default withTranslation ( ) ( LoginForm ) ;
0 commit comments