Refactor "Next" button into ServerConfig components

TODO still remains about making ModularServerConfig extend ServerConfig instead of duplicating everything.

See https://github.com/vector-im/riot-web/issues/9290
This commit is contained in:
Travis Ralston 2019-05-13 16:30:34 -06:00
parent 83737654ff
commit ee33a4e9ba
5 changed files with 125 additions and 96 deletions

View file

@ -20,11 +20,11 @@ limitations under the License.
import React from 'react';
import PropTypes from 'prop-types';
import { _t, _td } from '../../../languageHandler';
import {_t, _td} from '../../../languageHandler';
import sdk from '../../../index';
import Login from '../../../Login';
import SdkConfig from '../../../SdkConfig';
import { messageForResourceLimitError } from '../../../utils/ErrorUtils';
import {messageForResourceLimitError} from '../../../utils/ErrorUtils';
import {ValidatedServerConfig} from "../../../utils/AutoDiscoveryUtils";
// For validating phone numbers without country codes
@ -283,13 +283,7 @@ module.exports = React.createClass({
this.props.onRegisterClick();
},
async onServerDetailsNextPhaseClick(ev) {
ev.stopPropagation();
// TODO: TravisR - Capture the user's input somehow else
if (this._serverConfigRef) {
// Just to make sure the user's input gets captured
await this._serverConfigRef.validateServer();
}
async onServerDetailsNextPhaseClick() {
this.setState({
phase: PHASE_LOGIN,
});
@ -421,7 +415,6 @@ module.exports = React.createClass({
renderServerComponent() {
const ServerConfig = sdk.getComponent("auth.ServerConfig");
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
if (SdkConfig.get()['disable_custom_urls']) {
return null;
@ -431,26 +424,19 @@ module.exports = React.createClass({
return null;
}
const serverDetails = <ServerConfig
ref={r => this._serverConfigRef = r}
const serverDetailsProps = {};
if (PHASES_ENABLED) {
serverDetailsProps.onAfterSubmit = this.onServerDetailsNextPhaseClick;
serverDetailsProps.submitText = _t("Next");
serverDetailsProps.submitClass = "mx_Login_submit";
}
return <ServerConfig
serverConfig={this.props.serverConfig}
onServerConfigChange={this.props.onServerConfigChange}
delayTimeMs={250}
{...serverDetailsProps}
/>;
let nextButton = null;
if (PHASES_ENABLED) {
// TODO: TravisR - Pull out server discovery from ServerConfig to disable the next button?
nextButton = <AccessibleButton className="mx_Login_submit"
onClick={this.onServerDetailsNextPhaseClick}>
{_t("Next")}
</AccessibleButton>;
}
return <div>
{serverDetails}
{nextButton}
</div>;
},
renderLoginComponentForStep() {