@@ -66,69 +66,79 @@ export class Register extends Component<{}, RegisterState> {
6666
6767 showModal : Signal < boolean > ;
6868
69- checkPassword ( ) {
69+ async checkPassword ( ) {
7070 let res = true ;
7171
72+ const state = this . state as RegisterState ;
7273 const passwordPatternValid = PASSWORD_PATTERN . test ( this . state . password ) ;
7374 if ( ! passwordPatternValid ) {
74- this . setState ( { passwordValid : false } ) ;
75+ state . passwordValid = false ;
7576 res = false ;
7677 } else {
77- this . setState ( { passwordValid : true } ) ;
78+ state . passwordValid = true ;
7879 }
7980
8081 const passwordsMatch = this . state . password === this . state . confirmPassword ;
8182 if ( ! passwordsMatch ) {
82- this . setState ( { confirmPasswordValid : false } ) ;
83+ state . confirmPasswordValid = false ;
8384 res = false ;
8485 } else {
85- this . setState ( { confirmPasswordValid : true } ) ;
86+ state . confirmPasswordValid = true ;
8687 }
8788
88- return res ;
89+ const promise = new Promise < boolean > ( ( resolve ) => {
90+ this . setState ( state , ( ) => {
91+ resolve ( res ) ;
92+ } ) ;
93+ } ) ;
94+
95+ return promise ;
8996 }
9097
91- checkForm ( ) {
98+ async checkForm ( ) {
9299 let ret = true ;
93- if ( ! this . checkPassword ( ) ) {
100+ if ( ! await this . checkPassword ( ) ) {
94101 ret = false ;
95102 }
96103
97- if ( this . state . email . length === 0 ) {
98- this . setState ( { emailValid : false } ) ;
104+ const state = this . state as RegisterState ;
105+ if ( state . email . length === 0 ) {
106+ state . emailValid = false ;
99107 ret = false ;
100108 } else {
101- this . setState ( { emailValid : true } ) ;
109+ state . emailValid = true ;
102110 }
103111
104- if ( this . state . name . length === 0 ) {
105- this . setState ( { nameValid : false } ) ;
112+ if ( state . name . length === 0 ) {
113+ state . nameValid = false ;
106114 ret = false ;
107115 } else {
108- this . setState ( { nameValid : true } ) ;
116+ state . nameValid = true ;
109117 }
110118
111- if ( ! this . state . acceptPrivacyChecked ) {
112- this . setState ( { acceptPrivacyValid : false } ) ;
119+ if ( ! state . acceptPrivacyChecked ) {
120+ state . acceptPrivacyValid = false ;
113121 ret = false ;
114122 } else {
115- this . setState ( { acceptPrivacyValid : true } ) ;
123+ state . acceptPrivacyValid = true ;
116124 }
117125
118- if ( ! this . state . termsAndConditionsChecked ) {
119- this . setState ( { termsAndConditionsValid : false } ) ;
126+ if ( ! state . termsAndConditionsChecked ) {
127+ state . termsAndConditionsValid = false ;
120128 ret = false ;
121129 } else {
122- this . setState ( { termsAndConditionsValid : true } ) ;
130+ state . termsAndConditionsValid = true ;
123131 }
124132
133+ this . setState ( state ) ;
134+
125135 return ret ;
126136 }
127137
128138 async onSubmit ( e : SubmitEvent ) {
129139 e . preventDefault ( )
130140
131- if ( ! this . checkForm ( ) ) {
141+ if ( ! await this . checkForm ( ) ) {
132142 e . stopPropagation ( ) ;
133143 return ;
134144 }
@@ -206,7 +216,7 @@ export class Register extends Component<{}, RegisterState> {
206216 < Form onSubmit = { ( e : SubmitEvent ) => this . onSubmit ( e ) } noValidate >
207217 < Form . Group className = "mb-3" controlId = "registerName" >
208218 < Form . Label > { t ( "name" ) } </ Form . Label >
209- < Form . Control type = "text" placeholder = "John Doe" value = { this . state . name } isInvalid = { ! this . state . nameValid } onChange = { ( e ) => {
219+ < Form . Control name = "Name" type = "text" placeholder = "John Doe" value = { this . state . name } isInvalid = { ! this . state . nameValid } onChange = { ( e ) => {
210220 this . setState ( { name : ( e . target as HTMLInputElement ) . value } )
211221 } } />
212222 < Form . Control . Feedback type = "invalid" >
@@ -225,9 +235,9 @@ export class Register extends Component<{}, RegisterState> {
225235 < Form . Group className = "mb-3" controlId = "registerPassword" >
226236 < Form . Label > { t ( "password" ) } </ Form . Label >
227237 < PasswordComponent isInvalid = { ! this . state . passwordValid } onChange = { ( e ) => {
228- this . setState ( { password : e } , ( ) => {
238+ this . setState ( { password : e } , async ( ) => {
229239 if ( ! this . state . confirmPasswordValid || ! this . state . passwordValid ) {
230- this . checkPassword ( ) ;
240+ await this . checkPassword ( ) ;
231241 }
232242 } ) ;
233243 } }
0 commit comments