@@ -33,6 +33,7 @@ class SignInForm extends PureComponent {
3333 noAccount : false ,
3434 password : '' ,
3535 pending : false ,
36+ pendingForGoogle : false ,
3637 signInErrorId : ''
3738 } ;
3839
@@ -117,7 +118,7 @@ class SignInForm extends PureComponent {
117118 url = `/auth/google/sign-up/${ JSON . stringify ( data ) } ` ;
118119 }
119120
120- this . setState ( { pending : true } ) ;
121+ this . setState ( { pendingForGoogle : true } ) ;
121122
122123 window . location = url ;
123124 } ;
@@ -130,21 +131,19 @@ class SignInForm extends PureComponent {
130131 this . setState ( { pending : true } ) ;
131132 this . pendingPromise = makeAbortablePromise ( signIn ( email , password ) ) ;
132133
133- return this . pendingPromise . promise
134- . then ( ( ) => this . setState ( { pending : false } ) )
135- . catch ( err => {
136- if ( ! ( err instanceof AbortPromiseException ) ) {
137- const newState = { pending : false } ;
138-
139- if ( err instanceof UnauthorizedException ) {
140- newState . signInErrorId = 'user.actions.sign-in.invalid-credentials' ;
141- } else {
142- newState . signInErrorId = 'common.something-went-wrong' ;
143- }
134+ return this . pendingPromise . promise . catch ( err => {
135+ if ( ! ( err instanceof AbortPromiseException ) ) {
136+ const newState = { pending : false } ;
144137
145- this . setState ( newState ) ;
138+ if ( err instanceof UnauthorizedException ) {
139+ newState . signInErrorId = 'user.actions.sign-in.invalid-credentials' ;
140+ } else {
141+ newState . signInErrorId = 'common.something-went-wrong' ;
146142 }
147- } ) ;
143+
144+ this . setState ( newState ) ;
145+ }
146+ } ) ;
148147 } ;
149148
150149 renderSignInError = ( ) => {
@@ -180,11 +179,13 @@ class SignInForm extends PureComponent {
180179 isPolicyAccepted,
181180 noAccount,
182181 pending,
182+ pendingForGoogle,
183183 signInErrorId
184184 } = this . state ;
185185 const { isCookieSet } = this . props ;
186186 const hasSignUpFailed = signInErrorId . length > 0 ;
187- const isDisabled = ! isCookieSet || pending ;
187+ const isGoogleSignInDisabled = ! isCookieSet || pending || pendingForGoogle ;
188+ const isSignInDisabled = isGoogleSignInDisabled || ! isFormValid ;
188189 const cookieLink = (
189190 < Link className = "sign-up-form__link" to = "/cookie-policy" >
190191 < FormattedMessage id = "app.footer.cookie-policy" />
@@ -232,7 +233,7 @@ class SignInForm extends PureComponent {
232233 < form
233234 className = "sign-in__form"
234235 noValidate
235- onSubmit = { isFormValid && ! pending ? this . handleSignIn : null }
236+ onSubmit = { isSignInDisabled ? null : this . handleSignIn }
236237 >
237238 < AuthInput
238239 disabled = { pending }
@@ -259,7 +260,7 @@ class SignInForm extends PureComponent {
259260 </ Link >
260261 < PendingButton
261262 className = "primary-button sign-in__confirm"
262- disabled = { ! isFormValid }
263+ disabled = { isSignInDisabled }
263264 onClick = { this . handleSignIn }
264265 type = "submit"
265266 >
@@ -285,8 +286,9 @@ class SignInForm extends PureComponent {
285286 < div className = "sign-in__buttons" >
286287 < button
287288 className = { classNames ( 'primary-button google-button' , {
288- 'disabled-google-button' : isDisabled
289+ 'disabled-google-button' : isGoogleSignInDisabled
289290 } ) }
291+ disabled = { isGoogleSignInDisabled }
290292 onClick = { this . handleSignInWithGoogle }
291293 type = "submit"
292294 >
@@ -296,7 +298,7 @@ class SignInForm extends PureComponent {
296298 ) : (
297299 < FormattedMessage id = "user.auth.sign-in-with-google" />
298300 ) }
299- { pending && < Preloader size = { PreloaderSize . SMALL } /> }
301+ { pendingForGoogle && < Preloader size = { PreloaderSize . SMALL } /> }
300302 </ button >
301303 </ div >
302304 </ form >
0 commit comments