@@ -24,6 +24,7 @@ interface RegisterSchema {
2424interface RegisterState {
2525 accepted : boolean ,
2626 password : string ,
27+ passwordValid : boolean ,
2728 confirmPassword : string ,
2829 confirmPasswordValid : boolean ,
2930 name : string ,
@@ -46,6 +47,7 @@ export class Register extends Component<{}, RegisterState> {
4647 this . state = {
4748 accepted : false ,
4849 password : "" ,
50+ passwordValid : true ,
4951 confirmPassword : "" ,
5052 confirmPasswordValid : true ,
5153 name : "" ,
@@ -72,6 +74,13 @@ export class Register extends Component<{}, RegisterState> {
7274
7375 const state = this . state as RegisterState ;
7476
77+ if ( this . state . password . length < 8 ) {
78+ state . passwordValid = false ;
79+ res = false ;
80+ } else {
81+ state . passwordValid = true ;
82+ }
83+
7584 const passwordsMatch = this . state . password === this . state . confirmPassword ;
7685 if ( ! passwordsMatch ) {
7786 state . confirmPasswordValid = false ;
@@ -211,7 +220,11 @@ export class Register extends Component<{}, RegisterState> {
211220 < Form . Group className = "mb-3" controlId = "registerName" >
212221 < Form . Label > { t ( "name" ) } </ Form . Label >
213222 < Form . Control name = "Name" type = "text" placeholder = "John Doe" value = { this . state . name } isInvalid = { ! this . state . nameValid } onChange = { ( e ) => {
214- this . setState ( { name : ( e . target as HTMLInputElement ) . value } )
223+ const newName = ( e . target as HTMLInputElement ) . value ;
224+ this . setState ( {
225+ name : newName ,
226+ nameValid : newName . length > 0
227+ } ) ;
215228 } } />
216229 < Form . Control . Feedback type = "invalid" >
217230 { t ( "name_error_message" ) }
@@ -220,7 +233,11 @@ export class Register extends Component<{}, RegisterState> {
220233 < Form . Group className = "mb-3" controlId = "registerEmail" >
221234 < Form . Label > { t ( "email" ) } </ Form . Label >
222235 < Form . Control type = "email" placeholder = { t ( "email" ) } value = { this . state . email } isInvalid = { ! this . state . emailValid } onChange = { ( e ) => {
223- this . setState ( { email : ( e . target as HTMLInputElement ) . value } )
236+ const newEmail = ( e . target as HTMLInputElement ) . value ;
237+ this . setState ( {
238+ email : newEmail ,
239+ emailValid : newEmail . length > 0
240+ } ) ;
224241 } } />
225242 < Form . Control . Feedback type = "invalid" >
226243 { t ( "email_error_message" ) }
@@ -233,12 +250,12 @@ export class Register extends Component<{}, RegisterState> {
233250 showStrength = { true }
234251 onChange = { ( e ) => {
235252 this . setState ( { password : e } , async ( ) => {
236- if ( ! this . state . confirmPasswordValid ) {
253+ if ( ! this . state . confirmPasswordValid || ! this . state . passwordValid ) {
237254 await this . checkPassword ( ) ;
238255 }
239256 } ) ;
240257 } }
241- isInvalid = { this . state . password . length < 8 }
258+ isInvalid = { ! this . state . passwordValid }
242259 invalidMessage = { t ( "password_error_message" ) } />
243260 </ Form . Group >
244261 < Form . Group className = "mb-3" controlId = "registerConfirmPassword" >
@@ -252,10 +269,22 @@ export class Register extends Component<{}, RegisterState> {
252269 } }
253270 invalidMessage = { t ( "confirm_password_error_message" ) } />
254271 </ Form . Group >
255- < Form . Group className = "mb-3" onClick = { ( ) => this . setState ( { acceptPrivacyChecked : ! this . state . acceptPrivacyChecked } ) } >
272+ < Form . Group className = "mb-3" onClick = { ( ) => {
273+ const newChecked = ! this . state . acceptPrivacyChecked ;
274+ this . setState ( {
275+ acceptPrivacyChecked : newChecked ,
276+ acceptPrivacyValid : newChecked
277+ } ) ;
278+ } } >
256279 < Form . Check checked = { this . state . acceptPrivacyChecked } type = "checkbox" label = { < Trans i18nKey = "register.accept_privacy_notice" > < a target = "__blank" href = { privacy_notice } > link</ a > </ Trans > } isInvalid = { ! this . state . acceptPrivacyValid } />
257280 </ Form . Group >
258- < Form . Group className = "mb-3" onClick = { ( ) => this . setState ( { termsAndConditionsChecked : ! this . state . termsAndConditionsChecked } ) } >
281+ < Form . Group className = "mb-3" onClick = { ( ) => {
282+ const newChecked = ! this . state . termsAndConditionsChecked ;
283+ this . setState ( {
284+ termsAndConditionsChecked : newChecked ,
285+ termsAndConditionsValid : newChecked
286+ } ) ;
287+ } } >
259288 < Form . Check checked = { this . state . termsAndConditionsChecked } type = "checkbox" label = { < Trans i18nKey = "register.accept_terms_and_conditions" > < a target = "__blank" href = { terms_of_use } > link</ a > </ Trans > } isInvalid = { ! this . state . termsAndConditionsValid } />
260289 </ Form . Group >
261290 < Button variant = "primary" type = "submit" >
0 commit comments