Merge pull request #2551 from jryans/auth-reg-optional-fields

Hide registration fields that aren't used by any flow
This commit is contained in:
J. Ryan Stinnett 2019-02-01 08:59:31 -06:00 committed by GitHub
commit 5841f0520f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -270,11 +270,27 @@ module.exports = React.createClass({
this.validateField(FIELD_USERNAME, ev.type);
},
/**
* A step is required if all flows include that step.
*
* @param {string} step A stage name to check
* @returns {boolean} Whether it is required
*/
_authStepIsRequired(step) {
// A step is required if no flow exists which does not include that step
// (Notwithstanding setups like either email or msisdn being required)
return !this.props.flows.some((flow) => {
return !flow.stages.includes(step);
return this.props.flows.every((flow) => {
return flow.stages.includes(step);
});
},
/**
* A step is used if any flows include that step.
*
* @param {string} step A stage name to check
* @returns {boolean} Whether it is used
*/
_authStepIsUsed(step) {
return this.props.flows.some((flow) => {
return flow.stages.includes(step);
});
},
@ -298,11 +314,13 @@ module.exports = React.createClass({
</a>;
}
let emailSection;
if (this._authStepIsUsed('m.login.email.identity')) {
const emailPlaceholder = this._authStepIsRequired('m.login.email.identity') ?
_t("Email") :
_t("Email (optional)");
const emailSection = (
emailSection = (
<div>
<input type="text" ref="email"
placeholder={emailPlaceholder}
@ -312,10 +330,12 @@ module.exports = React.createClass({
value={this.state.email} />
</div>
);
}
const threePidLogin = !SdkConfig.get().disable_3pid_login;
const CountryDropdown = sdk.getComponent('views.auth.CountryDropdown');
let phoneSection;
if (!SdkConfig.get().disable_3pid_login) {
if (threePidLogin && this._authStepIsUsed('m.login.msisdn')) {
const phonePlaceholder = this._authStepIsRequired('m.login.msisdn') ?
_t("Phone") :
_t("Phone (optional)");