@@ -59,10 +59,26 @@ class SignupView extends React.Component {
59
59
}
60
60
}
61
61
62
+ function asyncErrorsSelector ( formName , state ) {
63
+ const form = state . form [ formName ] ;
64
+ if ( ! form ) {
65
+ return { } ;
66
+ }
67
+
68
+ const fieldNames = Object . keys ( form ) . filter ( key => ! key . startsWith ( '_' ) ) ;
69
+ return fieldNames . reduce ( ( asyncErrors , fieldName ) => {
70
+ if ( form [ fieldName ] . asyncError ) {
71
+ return { ...asyncErrors , [ fieldName ] : form [ fieldName ] . asyncError } ;
72
+ }
73
+ return asyncErrors ;
74
+ } , { } ) ;
75
+ }
76
+
62
77
function mapStateToProps ( state ) {
63
78
return {
64
79
user : state . user ,
65
- previousPath : state . ide . previousPath
80
+ previousPath : state . ide . previousPath ,
81
+ asyncErrors : asyncErrorsSelector ( 'signup' , state )
66
82
} ;
67
83
}
68
84
@@ -71,21 +87,29 @@ function mapDispatchToProps(dispatch) {
71
87
}
72
88
73
89
function asyncValidate ( formProps , dispatch , props ) {
74
- const fieldToValidate = props . form . _active ;
75
- if ( fieldToValidate ) {
76
- const queryParams = { } ;
77
- queryParams [ fieldToValidate ] = formProps [ fieldToValidate ] ;
78
- queryParams . check_type = fieldToValidate ;
79
- return axios . get ( '/api/signup/duplicate_check' , { params : queryParams } )
80
- . then ( ( response ) => {
81
- if ( response . data . exists ) {
82
- const error = { } ;
83
- error [ fieldToValidate ] = response . data . message ;
84
- throw error ;
85
- }
86
- } ) ;
87
- }
88
- return Promise . resolve ( true ) . then ( ( ) => { } ) ;
90
+ const errors = { } ;
91
+ return Promise . resolve ( true )
92
+ . then ( ( ) => {
93
+ const fieldToValidate = props . form . _active ;
94
+ if ( fieldToValidate ) {
95
+ const queryParams = { } ;
96
+ queryParams [ fieldToValidate ] = formProps [ fieldToValidate ] ;
97
+ queryParams . check_type = fieldToValidate ;
98
+ return axios . get ( '/api/signup/duplicate_check' , { params : queryParams } )
99
+ . then ( ( response ) => {
100
+ if ( response . data . exists ) {
101
+ errors [ fieldToValidate ] = response . data . message ;
102
+ }
103
+ } ) ;
104
+ }
105
+ return null ;
106
+ } )
107
+ . then ( ( ) => {
108
+ const err = { ...errors , ...props . asyncErrors } ;
109
+ if ( Object . keys ( err ) . length > 0 ) {
110
+ throw err ;
111
+ }
112
+ } ) ;
89
113
}
90
114
91
115
function onSubmitFail ( errors ) {
0 commit comments