Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 0f84216

Browse files
committed
Grey out login form when no valid HS
1 parent fa24b4b commit 0f84216

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

src/components/views/elements/Dropdown.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export default class Dropdown extends React.Component {
302302

303303
const dropdownClasses = {
304304
mx_Dropdown: true,
305+
mx_Dropdown_disabled: this.props.disabled,
305306
};
306307
if (this.props.className) {
307308
dropdownClasses[this.props.className] = true;

src/components/views/login/CountryDropdown.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default class CountryDropdown extends React.Component {
123123
return <Dropdown className={this.props.className + " left_aligned"}
124124
onOptionChange={this._onOptionChange} onSearchChange={this._onSearchChange}
125125
menuWidth={298} getShortOption={this._getShortOption}
126-
value={value} searchEnabled={true}
126+
value={value} searchEnabled={true} disabled={this.props.disabled}
127127
>
128128
{options}
129129
</Dropdown>;
@@ -137,4 +137,5 @@ CountryDropdown.propTypes = {
137137
showPrefix: React.PropTypes.bool,
138138
onOptionChange: React.PropTypes.func.isRequired,
139139
value: React.PropTypes.string,
140+
disabled: React.PropTypes.bool,
140141
};

src/components/views/login/PasswordLogin.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,32 +116,43 @@ class PasswordLogin extends React.Component {
116116
this.props.onPasswordChanged(ev.target.value);
117117
}
118118

119-
renderLoginField(loginType) {
119+
renderLoginField(loginType, disabled) {
120+
const classes = {
121+
mx_Login_field: true,
122+
mx_Login_field_disabled: disabled,
123+
};
124+
120125
switch(loginType) {
121126
case PasswordLogin.LOGIN_FIELD_EMAIL:
127+
classes.mx_Login_email = true;
122128
return <input
123-
className="mx_Login_field mx_Login_email"
129+
className={classNames(classes)}
124130
key="email_input"
125131
type="text"
126132
name="username" // make it a little easier for browser's remember-password
127133
onChange={this.onUsernameChanged}
128134
placeholder="[email protected]"
129135
value={this.state.username}
130136
autoFocus
137+
disabled={disabled}
131138
/>;
132139
case PasswordLogin.LOGIN_FIELD_MXID:
140+
classes.mx_Login_username = true;
133141
return <input
134-
className="mx_Login_field mx_Login_username"
142+
className={classNames(classes)}
135143
key="username_input"
136144
type="text"
137145
name="username" // make it a little easier for browser's remember-password
138146
onChange={this.onUsernameChanged}
139147
placeholder={_t('User name')}
140148
value={this.state.username}
141149
autoFocus
150+
disabled={disabled}
142151
/>;
143152
case PasswordLogin.LOGIN_FIELD_PHONE:
144153
const CountryDropdown = sdk.getComponent('views.login.CountryDropdown');
154+
classes.mx_Login_phoneNumberField = true;
155+
classes.mx_Login_field_has_prefix = true;
145156
return <div className="mx_Login_phoneSection">
146157
<CountryDropdown
147158
className="mx_Login_phoneCountry mx_Login_field_prefix"
@@ -150,9 +161,10 @@ class PasswordLogin extends React.Component {
150161
value={this.state.phoneCountry}
151162
isSmall={true}
152163
showPrefix={true}
164+
disabled={disabled}
153165
/>
154166
<input
155-
className="mx_Login_phoneNumberField mx_Login_field mx_Login_field_has_prefix"
167+
className={classNames(classes)}
156168
ref="phoneNumber"
157169
key="phone_input"
158170
type="text"
@@ -161,6 +173,7 @@ class PasswordLogin extends React.Component {
161173
placeholder={_t("Mobile phone number")}
162174
value={this.state.phoneNumber}
163175
autoFocus
176+
disabled={disabled}
164177
/>
165178
</div>;
166179
}
@@ -177,15 +190,6 @@ class PasswordLogin extends React.Component {
177190
);
178191
}
179192

180-
const pwFieldClass = classNames({
181-
mx_Login_field: true,
182-
error: this.props.loginIncorrect,
183-
});
184-
185-
const Dropdown = sdk.getComponent('elements.Dropdown');
186-
187-
const loginField = this.renderLoginField(this.state.loginType);
188-
189193
let matrixIdText = '';
190194
if (this.props.hsUrl) {
191195
try {
@@ -196,6 +200,16 @@ class PasswordLogin extends React.Component {
196200
}
197201
}
198202

203+
const pwFieldClass = classNames({
204+
mx_Login_field: true,
205+
mx_Login_field_disabled: matrixIdText === '',
206+
error: this.props.loginIncorrect,
207+
});
208+
209+
const Dropdown = sdk.getComponent('elements.Dropdown');
210+
211+
const loginField = this.renderLoginField(this.state.loginType, matrixIdText === '');
212+
199213
return (
200214
<div>
201215
<form onSubmit={this.onSubmitForm}>
@@ -215,10 +229,12 @@ class PasswordLogin extends React.Component {
215229
<input className={pwFieldClass} ref={(e) => {this._passwordField = e;}} type="password"
216230
name="password"
217231
value={this.state.password} onChange={this.onPasswordChanged}
218-
placeholder={ _t('Password') } />
232+
placeholder={ _t('Password') }
233+
disabled={matrixIdText === ''}
234+
/>
219235
<br />
220236
{forgotPasswordJsx}
221-
<input className="mx_Login_submit" type="submit" value={ _t('Sign in') } />
237+
<input className="mx_Login_submit" type="submit" value={ _t('Sign in') } disabled={matrixIdText === ''} />
222238
</form>
223239
</div>
224240
);

0 commit comments

Comments
 (0)