@@ -31,21 +31,29 @@ class CreateUserModal extends React.Component {
3131
3232 this . setState ( { wasValidated : true , isLoading : true } ) ;
3333
34- if ( e . target . checkValidity ( ) && ( ! this . state . setPassword || ( this . state . password1 === this . state . password2 ) ) ) {
35- this . props . onCreate ( {
36- firstName : this . state . firstName ,
37- lastName : this . state . lastName ,
38- email : this . state . email ,
39- role : this . state . role ,
40- setPassword : this . state . setPassword ,
41- password : this . state . password1
42- } , ( ) => this . handleClose ( ( ) => { } ) , ( ) => this . setState ( { isLoading : false } ) ) ;
34+ if ( e . target . checkValidity ( ) && ( ! this . state . setPassword || ( this . state . password1 === this . state . password2 && this . state . password1 . length > 5 ) ) ) {
35+ this . props . onCreate (
36+ {
37+ firstName : this . state . firstName ,
38+ lastName : this . state . lastName ,
39+ email : this . state . email ,
40+ role : this . state . role ,
41+ setPassword : this . state . setPassword ,
42+ password : this . state . password1
43+ } ,
44+ this . handleClose ,
45+ ( ) => this . setState ( { isLoading : false } )
46+ ) ;
4347 } else {
4448 this . setState ( { isLoading : false } ) ;
4549 }
4650 }
4751
4852 handleClose ( onClose ) {
53+ if ( ! onClose ) {
54+ onClose = _ . noop ;
55+ }
56+
4957 this . setState ( {
5058 firstName : '' ,
5159 lastName : '' ,
@@ -150,62 +158,60 @@ class CreateUserModal extends React.Component {
150158
151159 < Collapse in = { this . state . setPassword } >
152160 < div className = "mt-3 mb-2" >
153- {
154- this . state . setPassword ?
155- < >
156- < Form . Group className = "mb-3" controlId = "password1" >
157- < Form . Label > Password</ Form . Label >
158- < Form . Control
159- type = "password"
160- placeholder = "Enter Password"
161- onChange = { ( e ) => this . setState ( { password1 : e . target . value } ) }
162- className = { ( this . state . password1 !== this . state . password2 && this . state . password1 . length > 5 && this . state . password2 . length > 5 )
163- ? 'is-invalid'
164- : null }
165- required
166- disabled = { this . state . isLoading }
167- />
168- < Form . Control . Feedback type = "invalid" className = { ( this . state . password1 !== this . state . password2 ) ? 'd-none' : null } > Password is
169- required.
170- </ Form . Control . Feedback >
171- </ Form . Group >
172-
173- < Form . Group controlId = "password2" >
174- < Form . Label > Verify Password</ Form . Label >
175- < Form . Control
176- type = "password"
177- placeholder = "Verify Password"
178- onChange = { ( e ) => this . setState ( { password2 : e . target . value } ) }
179- className = { ( this . state . password1 !== this . state . password2 && this . state . password1 . length > 5 && this . state . password2 . length > 5 )
180- ? 'is-invalid'
181- : null }
182- required
183- disabled = { this . state . isLoading }
184- />
185- {
186- ( this . state . password1 !== '' ) ?
187- < Form . Control . Feedback type = "invalid" >
188- {
189- ( this . state . password1 !== this . state . password2 )
190- ? 'Passwords do not match.'
191- : 'Must verify password.'
192- }
193- </ Form . Control . Feedback >
194- :
195- null
196- }
197- </ Form . Group >
198- </ >
199- : null
200- }
161+ < Form . Group className = "mb-3" controlId = "password1" >
162+ < Form . Label > Password</ Form . Label >
163+ < Form . Control
164+ type = "password"
165+ placeholder = "Enter Password"
166+ onChange = { ( e ) => this . setState ( { password1 : e . target . value } ) }
167+ className = {
168+ ( this . state . wasValidated && this . state . password1 . length < 6 )
169+ ? 'is-invalid'
170+ : null
171+ }
172+ required
173+ disabled = { this . state . isLoading || ! this . state . setPassword }
174+ minLength = "6"
175+ maxLength = "72"
176+ />
177+ < Form . Control . Feedback type = "invalid" className = { ( ! this . state . wasValidated || this . state . password1 . length > 5 ) ? 'd-none' : null } >
178+ {
179+ ( this . state . password1 . length )
180+ ? 'Password is too short.'
181+ : 'Password is required.'
182+ }
183+ </ Form . Control . Feedback >
184+ </ Form . Group >
185+
186+ < Form . Group controlId = "password2" >
187+ < Form . Label > Verify Password</ Form . Label >
188+ < Form . Control
189+ type = "password"
190+ placeholder = "Verify Password"
191+ onChange = { ( e ) => this . setState ( { password2 : e . target . value } ) }
192+ className = {
193+ ( this . state . wasValidated && this . state . password1 !== this . state . password2 && this . state . password2 . length )
194+ ? 'is-invalid'
195+ : null
196+ }
197+ required
198+ disabled = { this . state . isLoading || ! this . state . setPassword }
199+ minLength = "6"
200+ />
201+ {
202+ ( this . state . wasValidated && this . state . password1 . length && this . state . password2 . length )
203+ ? < Form . Control . Feedback type = "invalid" > Passwords do not match.</ Form . Control . Feedback >
204+ : null
205+ }
206+ </ Form . Group >
201207 </ div >
202208 </ Collapse >
203209 </ Modal . Body >
204210
205211 < Modal . Footer className = "justify-content-between" >
206212 < Button variant = "secondary" onClick = { ( ) => this . handleClose ( this . props . onClose ) } disabled = { this . state . isLoading } > Cancel</ Button >
207213 < Button variant = "primary" type = "submit" disabled = { this . state . isLoading } >
208- { this . state . isLoading ? 'Loading...' : 'Create' }
214+ { this . state . isLoading ? 'Loading...' : 'Create' }
209215 </ Button >
210216 </ Modal . Footer >
211217 </ Form >
0 commit comments