4
4
*
5
5
*/
6
6
7
- import React from " react" ;
8
- import { Form , InputNumber , Input , Icon , Checkbox , Button } from " antd" ;
7
+ import React from ' react' ;
8
+ import { Form , InputNumber , Input , Icon , Checkbox , Button } from ' antd' ;
9
9
10
- import PropTypes from " prop-types" ;
11
- import { connect } from " react-redux" ;
12
- import { Link } from " react-router-dom" ;
13
- import { push } from " react-router-redux" ;
14
- import { createStructuredSelector } from " reselect" ;
15
- import { compose } from " redux" ;
10
+ import PropTypes from ' prop-types' ;
11
+ import { connect } from ' react-redux' ;
12
+ import { Link } from ' react-router-dom' ;
13
+ import { push } from ' react-router-redux' ;
14
+ import { createStructuredSelector } from ' reselect' ;
15
+ import { compose } from ' redux' ;
16
16
17
- import injectSaga from " utils/injectSaga" ;
18
- import injectReducer from " utils/injectReducer" ;
19
- import makeSelectLoginPage , { makeSelectLogin } from " ./selectors" ;
20
- import reducer from " ./reducer" ;
21
- import saga from " ./saga" ;
17
+ import injectSaga from ' utils/injectSaga' ;
18
+ import injectReducer from ' utils/injectReducer' ;
19
+ import makeSelectLoginPage , { makeSelectLogin } from ' ./selectors' ;
20
+ import reducer from ' ./reducer' ;
21
+ import saga from ' ./saga' ;
22
22
23
23
// Css
24
- import " ./login-page.css" ;
24
+ import ' ./login-page.css' ;
25
25
26
26
// Constants
27
27
const FormItem = Form . Item ;
28
-
28
+ const formItemLayout = {
29
+ labelCol : {
30
+ xs : { span : 24 } ,
31
+ sm : { span : 24 }
32
+ } ,
33
+ wrapperCol : {
34
+ xs : { span : 24 } ,
35
+ sm : { span : 24 }
36
+ }
37
+ } ;
29
38
30
39
class LoginPage extends React . Component {
31
40
state = { } ;
@@ -34,11 +43,20 @@ class LoginPage extends React.Component {
34
43
e . preventDefault ( ) ;
35
44
this . props . form . validateFields ( ( err , values ) => {
36
45
if ( ! err ) {
37
- console . log ( " Received values of form: " , values ) ;
46
+ console . log ( ' Received values of form: ' , values ) ;
38
47
this . props . dispatchRoute ( '/dashboard' ) ;
39
48
}
40
49
} ) ;
41
50
} ;
51
+
52
+ checkConfirm = ( rule , value , callback ) => {
53
+ const form = this . props . form ;
54
+ if ( value && this . state . confirmDirty ) {
55
+ form . validateFields ( [ "confirm" ] , { force : true } ) ;
56
+ }
57
+ callback ( ) ;
58
+ } ;
59
+
42
60
render ( ) {
43
61
const { getFieldDecorator } = this . props . form ;
44
62
return (
@@ -52,26 +70,39 @@ class LoginPage extends React.Component {
52
70
</ div >
53
71
</ div >
54
72
< div className = "login-main" >
55
- < Form onSubmit = { this . handleSubmit } className = "login-form" >
56
- < FormItem >
57
- { getFieldDecorator ( "userName" , {
73
+ < Form onSubmit = { this . handleSubmit } >
74
+ < FormItem { ... formItemLayout } >
75
+ { getFieldDecorator ( 'email' , {
58
76
rules : [
59
- { required : true , message : "Please input your username!" }
77
+ {
78
+ type : 'email' ,
79
+ message : 'The input is not valid E-mail!'
80
+ } ,
81
+ {
82
+ required : true ,
83
+ message : 'Please input your E-mail!'
84
+ }
60
85
]
61
86
} ) (
62
87
< Input
63
88
size = "large"
64
89
prefix = {
65
90
< Icon type = "user" style = { { color : "rgba(0,0,0,.25)" } } />
66
91
}
67
- placeholder = "Username "
92
+ placeholder = "Email "
68
93
/>
69
94
) }
70
95
</ FormItem >
71
- < FormItem >
72
- { getFieldDecorator ( " password" , {
96
+ < FormItem { ... formItemLayout } >
97
+ { getFieldDecorator ( ' password' , {
73
98
rules : [
74
- { required : true , message : "Please input your Password!" }
99
+ {
100
+ required : true ,
101
+ message : 'Please input your password!'
102
+ } ,
103
+ {
104
+ validator : this . checkConfirm
105
+ }
75
106
]
76
107
} ) (
77
108
< Input
@@ -85,8 +116,8 @@ class LoginPage extends React.Component {
85
116
) }
86
117
</ FormItem >
87
118
< FormItem >
88
- { getFieldDecorator ( " remember" , {
89
- valuePropName : " checked" ,
119
+ { getFieldDecorator ( ' remember' , {
120
+ valuePropName : ' checked' ,
90
121
initialValue : true
91
122
} ) ( < Checkbox > Remember me</ Checkbox > ) }
92
123
< Link className = "login-form-forgot" to = "/forgot-password" >
@@ -122,7 +153,7 @@ const withForm = Form.create();
122
153
123
154
const withConnect = connect ( mapStateToProps , mapDispatchToProps ) ;
124
155
125
- const withReducer = injectReducer ( { key : " loginPage" , reducer } ) ;
126
- const withSaga = injectSaga ( { key : " loginPage" , saga } ) ;
156
+ const withReducer = injectReducer ( { key : ' loginPage' , reducer } ) ;
157
+ const withSaga = injectSaga ( { key : ' loginPage' , saga } ) ;
127
158
128
159
export default compose ( withReducer , withSaga , withConnect , withForm ) ( LoginPage ) ;
0 commit comments