@@ -19,6 +19,7 @@ limitations under the License.
19
19
import React , { ReactNode } from 'react' ;
20
20
import { logger } from 'matrix-js-sdk/src/logger' ;
21
21
import { createClient } from "matrix-js-sdk/src/matrix" ;
22
+ import { sleep } from 'matrix-js-sdk/src/utils' ;
22
23
23
24
import { _t , _td } from '../../../languageHandler' ;
24
25
import Modal from "../../../Modal" ;
@@ -43,6 +44,8 @@ import Spinner from '../../views/elements/Spinner';
43
44
import { formatSeconds } from '../../../DateUtils' ;
44
45
import AutoDiscoveryUtils from '../../../utils/AutoDiscoveryUtils' ;
45
46
47
+ const emailCheckInterval = 2000 ;
48
+
46
49
enum Phase {
47
50
// Show email input
48
51
EnterEmail = 1 ,
@@ -83,6 +86,10 @@ interface State {
83
86
}
84
87
85
88
export default class ForgotPassword extends React . Component < Props , State > {
89
+ public static defaultProps : Partial < Props > = {
90
+ onLoginClick : ( ) => { } ,
91
+ } ;
92
+
86
93
private reset : PasswordReset ;
87
94
private fieldPassword : Field | null = null ;
88
95
private fieldPasswordConfirm : Field | null = null ;
@@ -277,22 +284,43 @@ export default class ForgotPassword extends React.Component<Props, State> {
277
284
{
278
285
email : this . state . email ,
279
286
errorText : this . state . errorText ,
287
+ onCloseClick : ( ) => {
288
+ modal . close ( ) ;
289
+ this . setState ( { phase : Phase . PasswordInput } ) ;
290
+ } ,
291
+ onReEnterEmailClick : ( ) => {
292
+ modal . close ( ) ;
293
+ this . setState ( { phase : Phase . EnterEmail } ) ;
294
+ } ,
280
295
onResendClick : this . sendVerificationMail ,
281
296
} ,
282
297
"mx_VerifyEMailDialog" ,
283
298
false ,
284
299
false ,
285
300
{
286
- // this modal cannot be dismissed except reset is done or forced
287
301
onBeforeClose : async ( reason ?: string ) => {
288
- return this . state . phase === Phase . Done || reason === "force" ;
302
+ if ( reason === "backgroundClick" ) {
303
+ // Modal dismissed by clicking the background.
304
+ // Go one phase back.
305
+ this . setState ( { phase : Phase . PasswordInput } ) ;
306
+ }
307
+
308
+ return true ;
289
309
} ,
290
310
} ,
291
311
) ;
292
312
293
- await this . reset . retrySetNewPassword ( this . state . password ) ;
294
- this . phase = Phase . Done ;
295
- modal . close ( ) ;
313
+ // Don't retry if the phase changed. For example when going back to email input.
314
+ while ( this . state . phase === Phase . ResettingPassword ) {
315
+ try {
316
+ await this . reset . setNewPassword ( this . state . password ) ;
317
+ this . setState ( { phase : Phase . Done } ) ;
318
+ modal . close ( ) ;
319
+ } catch ( e ) {
320
+ // Email not confirmed, yet. Retry after a while.
321
+ await sleep ( emailCheckInterval ) ;
322
+ }
323
+ }
296
324
}
297
325
298
326
private onSubmitForm = async ( ev : React . FormEvent ) : Promise < void > => {
@@ -339,6 +367,7 @@ export default class ForgotPassword extends React.Component<Props, State> {
339
367
homeserver = { this . props . serverConfig . hsName }
340
368
loading = { this . state . phase === Phase . SendingEmail }
341
369
onInputChanged = { this . onInputChanged }
370
+ onLoginClick = { this . props . onLoginClick ! } // set by default props
342
371
onSubmitForm = { this . onSubmitForm }
343
372
/> ;
344
373
}
@@ -374,6 +403,7 @@ export default class ForgotPassword extends React.Component<Props, State> {
374
403
return < CheckEmail
375
404
email = { this . state . email }
376
405
errorText = { this . state . errorText }
406
+ onReEnterEmailClick = { ( ) => this . setState ( { phase : Phase . EnterEmail } ) }
377
407
onResendClick = { this . sendVerificationMail }
378
408
onSubmitForm = { this . onSubmitForm }
379
409
/> ;
0 commit comments