From 3afc455f3caaaebc4d54359d308acd50bab9145b Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 6 Feb 2019 16:46:49 +0000 Subject: [PATCH] Extract each phase to a separate function --- .../structures/auth/ForgotPassword.js | 208 ++++++++++-------- 1 file changed, 116 insertions(+), 92 deletions(-) diff --git a/src/components/structures/auth/ForgotPassword.js b/src/components/structures/auth/ForgotPassword.js index 1fbcd8dfd4..2db13624c3 100644 --- a/src/components/structures/auth/ForgotPassword.js +++ b/src/components/structures/auth/ForgotPassword.js @@ -61,7 +61,7 @@ module.exports = React.createClass({ return { enteredHsUrl: this.props.customHsUrl || this.props.defaultHsUrl, enteredIsUrl: this.props.customIsUrl || this.props.defaultIsUrl, - phase: null, + phase: PHASE_FORGOT, password: null, password2: null, errorText: null, @@ -187,103 +187,127 @@ module.exports = React.createClass({ }); }, + renderServerDetails() { + return null; + }, + + renderForgot() { + const ServerConfig = sdk.getComponent("auth.ServerConfig"); + + let serverConfigSection; + if (!SdkConfig.get()['disable_custom_urls']) { + serverConfigSection = ( + + ); + } + + let errorText = null; + const err = this.state.errorText || this.props.defaultServerDiscoveryError; + if (err) { + errorText =
{ err }
; + } + + let yourMatrixAccountText = _t('Your account'); + try { + const parsedHsUrl = new URL(this.state.enteredHsUrl); + yourMatrixAccountText = _t('Your account on %(serverName)s', { + serverName: parsedHsUrl.hostname, + }); + } catch (e) { + // ignore + } + + return
+

+ {yourMatrixAccountText} +

+
+
+ +
+
+ + +
+ {_t( + 'A verification email will be sent to your inbox to confirm ' + + 'setting your new password.', + )} + +
+ {serverConfigSection} + {errorText} + + {_t('Sign in instead')} + +
; + }, + + renderSendingEmail() { + const Spinner = sdk.getComponent("elements.Spinner"); + return ; + }, + + renderEmailSent() { + return
+ {_t("An email has been sent to %(emailAddress)s. Once you've followed the " + + "link it contains, click below.", { emailAddress: this.state.email })} +
+ +
; + }, + + renderDone() { + return
+

{_t('Your password has been reset')}.

+

{_t('You have been logged out of all devices and will no longer receive push notifications. ' + + 'To re-enable notifications, sign in again on each device')}.

+ +
; + }, + render: function() { const AuthPage = sdk.getComponent("auth.AuthPage"); const AuthHeader = sdk.getComponent("auth.AuthHeader"); const AuthBody = sdk.getComponent("auth.AuthBody"); - const ServerConfig = sdk.getComponent("auth.ServerConfig"); - const Spinner = sdk.getComponent("elements.Spinner"); let resetPasswordJsx; - - if (this.state.phase === PHASE_SENDING_EMAIL) { - resetPasswordJsx = ; - } else if (this.state.phase === PHASE_EMAIL_SENT) { - resetPasswordJsx = ( -
- { _t("An email has been sent to %(emailAddress)s. Once you've followed the link it contains, " + - "click below.", { emailAddress: this.state.email }) } -
- -
- ); - } else if (this.state.phase === PHASE_DONE) { - resetPasswordJsx = ( -
-

{ _t('Your password has been reset') }.

-

{ _t('You have been logged out of all devices and will no longer receive push notifications. ' + - 'To re-enable notifications, sign in again on each device') }.

- -
- ); - } else { - let serverConfigSection; - if (!SdkConfig.get()['disable_custom_urls']) { - serverConfigSection = ( - - ); - } - - let errorText = null; - const err = this.state.errorText || this.props.defaultServerDiscoveryError; - if (err) { - errorText =
{ err }
; - } - - let yourMatrixAccountText = _t('Your account'); - try { - const parsedHsUrl = new URL(this.state.enteredHsUrl); - yourMatrixAccountText = _t('Your account on %(serverName)s', { - serverName: parsedHsUrl.hostname, - }); - } catch (e) { - // ignore - } - - resetPasswordJsx =
-

- {yourMatrixAccountText} -

-
-
- -
-
- - -
- {_t( - 'A verification email will be sent to your inbox to confirm ' + - 'setting your new password.', - )} - -
- {serverConfigSection} - {errorText} - - {_t('Sign in instead')} - -
; + switch (this.state.phase) { + case PHASE_SERVER_DETAILS: + resetPasswordJsx = this.renderServerDetails(); + break; + case PHASE_FORGOT: + resetPasswordJsx = this.renderForgot(); + break; + case PHASE_SENDING_EMAIL: + resetPasswordJsx = this.renderSendingEmail(); + break; + case PHASE_EMAIL_SENT: + resetPasswordJsx = this.renderEmailSent(); + break; + case PHASE_DONE: + resetPasswordJsx = this.renderDone(); + break; } return (