diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js
index 6b578f0f68..04570df868 100644
--- a/src/components/structures/auth/Registration.js
+++ b/src/components/structures/auth/Registration.js
@@ -94,7 +94,7 @@ module.exports = React.createClass({
// If we've been given a session ID, we're resuming
// straight back into UI auth
doingUIAuth: Boolean(this.props.sessionId),
- serverType: null,
+ serverType: ServerType.getTypeFromHsUrl(this.props.customHsUrl),
hsUrl: this.props.customHsUrl,
isUrl: this.props.customIsUrl,
// Phase of the overall registration dialog.
@@ -122,7 +122,7 @@ module.exports = React.createClass({
});
},
- onServerTypeChange(type, initial) {
+ onServerTypeChange(type) {
this.setState({
serverType: type,
});
@@ -148,15 +148,10 @@ module.exports = React.createClass({
hsUrl: this.props.defaultHsUrl,
isUrl: this.props.defaultIsUrl,
});
- // if this is the initial value from the control and we're
- // already in the registration phase, don't go back to the
- // server details phase (but do if it's actually a change resulting
- // from user interaction).
- if (!initial || !this.state.phase === PHASE_REGISTRATION) {
- this.setState({
- phase: PHASE_SERVER_DETAILS,
- });
- }
+ // Reset back to server details on type change.
+ this.setState({
+ phase: PHASE_SERVER_DETAILS,
+ });
break;
}
},
@@ -389,12 +384,9 @@ module.exports = React.createClass({
// If we're on a different phase, we only show the server type selector,
// which is always shown if we allow custom URLs at all.
if (PHASES_ENABLED && this.state.phase !== PHASE_SERVER_DETAILS) {
- // if we've been given a custom HS URL we should actually pass that, so
- // that the appropriate section is selected at the start to match the
- // homeserver URL we're using
return
;
@@ -436,7 +428,7 @@ module.exports = React.createClass({
return
{serverDetails}
diff --git a/src/components/views/auth/ServerTypeSelector.js b/src/components/views/auth/ServerTypeSelector.js
index 25f5dcee66..a9311acd7b 100644
--- a/src/components/views/auth/ServerTypeSelector.js
+++ b/src/components/views/auth/ServerTypeSelector.js
@@ -56,12 +56,12 @@ export const TYPES = {
},
};
-function getDefaultType(defaultHsUrl) {
- if (!defaultHsUrl) {
+export function getTypeFromHsUrl(hsUrl) {
+ if (!hsUrl) {
return null;
- } else if (defaultHsUrl === TYPES.FREE.hsUrl) {
+ } else if (hsUrl === TYPES.FREE.hsUrl) {
return FREE;
- } else if (new URL(defaultHsUrl).hostname.endsWith('.modular.im')) {
+ } else if (new URL(hsUrl).hostname.endsWith('.modular.im')) {
// This is an unlikely case to reach, as Modular defaults to hiding the
// server type selector.
return PREMIUM;
@@ -72,8 +72,8 @@ function getDefaultType(defaultHsUrl) {
export default class ServerTypeSelector extends React.PureComponent {
static propTypes = {
- // The default HS URL as another way to set the initially selected type.
- defaultHsUrl: PropTypes.string,
+ // The default selected type.
+ selected: PropTypes.string,
// Handler called when the selected type changes.
onChange: PropTypes.func.isRequired,
}
@@ -82,20 +82,12 @@ export default class ServerTypeSelector extends React.PureComponent {
super(props);
const {
- defaultHsUrl,
- onChange,
+ selected,
} = props;
- const type = getDefaultType(defaultHsUrl);
+
this.state = {
- selected: type,
+ selected,
};
- if (onChange) {
- // FIXME: Supply a second 'initial' param here to flag that this is
- // initialising the value rather than from user interaction
- // (which sometimes we'll want to ignore). Must be a better way
- // to do this.
- onChange(type, true);
- }
}
updateSelectedType(type) {