Apply strictNullChecks
to src/components/views/auth/*
(#10299
* Apply `strictNullChecks` to src/components/views/auth/* * Iterate PR
This commit is contained in:
parent
c79eff2292
commit
32aa18ff2e
16 changed files with 127 additions and 122 deletions
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { BaseSyntheticEvent } from "react";
|
||||
import React, { BaseSyntheticEvent, ReactNode } from "react";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
|
@ -82,7 +82,7 @@ interface IState {
|
|||
// Field error codes by field ID
|
||||
fieldValid: Partial<Record<RegistrationField, boolean>>;
|
||||
// The ISO2 country code selected in the phone number entry
|
||||
phoneCountry: string;
|
||||
phoneCountry?: string;
|
||||
username: string;
|
||||
email: string;
|
||||
phoneNumber: string;
|
||||
|
@ -95,11 +95,11 @@ interface IState {
|
|||
* A pure UI component which displays a registration form.
|
||||
*/
|
||||
export default class RegistrationForm extends React.PureComponent<IProps, IState> {
|
||||
private [RegistrationField.Email]: Field;
|
||||
private [RegistrationField.Password]: Field;
|
||||
private [RegistrationField.PasswordConfirm]: Field;
|
||||
private [RegistrationField.Username]: Field;
|
||||
private [RegistrationField.PhoneNumber]: Field;
|
||||
private [RegistrationField.Email]: Field | null;
|
||||
private [RegistrationField.Password]: Field | null;
|
||||
private [RegistrationField.PasswordConfirm]: Field | null;
|
||||
private [RegistrationField.Username]: Field | null;
|
||||
private [RegistrationField.PhoneNumber]: Field | null;
|
||||
|
||||
public static defaultProps = {
|
||||
onValidationChange: logger.error,
|
||||
|
@ -117,7 +117,6 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
phoneNumber: this.props.defaultPhoneNumber || "",
|
||||
password: this.props.defaultPassword || "",
|
||||
passwordConfirm: this.props.defaultPassword || "",
|
||||
passwordComplexity: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -138,7 +137,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
if (this.showEmail()) {
|
||||
Modal.createDialog(RegistrationEmailPromptDialog, {
|
||||
onFinished: async (confirmed: boolean, email?: string): Promise<void> => {
|
||||
if (confirmed) {
|
||||
if (confirmed && email !== undefined) {
|
||||
this.setState(
|
||||
{
|
||||
email,
|
||||
|
@ -265,7 +264,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
};
|
||||
|
||||
private onEmailValidate = (result: IValidationResult): void => {
|
||||
this.markFieldValid(RegistrationField.Email, result.valid);
|
||||
this.markFieldValid(RegistrationField.Email, !!result.valid);
|
||||
};
|
||||
|
||||
private validateEmailRules = withValidation({
|
||||
|
@ -294,7 +293,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
};
|
||||
|
||||
private onPasswordValidate = (result: IValidationResult): void => {
|
||||
this.markFieldValid(RegistrationField.Password, result.valid);
|
||||
this.markFieldValid(RegistrationField.Password, !!result.valid);
|
||||
};
|
||||
|
||||
private onPasswordConfirmChange = (ev: React.ChangeEvent<HTMLInputElement>): void => {
|
||||
|
@ -304,7 +303,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
};
|
||||
|
||||
private onPasswordConfirmValidate = (result: IValidationResult): void => {
|
||||
this.markFieldValid(RegistrationField.PasswordConfirm, result.valid);
|
||||
this.markFieldValid(RegistrationField.PasswordConfirm, !!result.valid);
|
||||
};
|
||||
|
||||
private onPhoneCountryChange = (newVal: PhoneNumberCountryDefinition): void => {
|
||||
|
@ -321,7 +320,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
|
||||
private onPhoneNumberValidate = async (fieldState: IFieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validatePhoneNumberRules(fieldState);
|
||||
this.markFieldValid(RegistrationField.PhoneNumber, result.valid);
|
||||
this.markFieldValid(RegistrationField.PhoneNumber, !!result.valid);
|
||||
return result;
|
||||
};
|
||||
|
||||
|
@ -352,14 +351,14 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
|
||||
private onUsernameValidate = async (fieldState: IFieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validateUsernameRules(fieldState);
|
||||
this.markFieldValid(RegistrationField.Username, result.valid);
|
||||
this.markFieldValid(RegistrationField.Username, !!result.valid);
|
||||
return result;
|
||||
};
|
||||
|
||||
private validateUsernameRules = withValidation<this, UsernameAvailableStatus>({
|
||||
description: (_, results) => {
|
||||
// omit the description if the only failing result is the `available` one as it makes no sense for it.
|
||||
if (results.every(({ key, valid }) => key === "available" || valid)) return;
|
||||
if (results.every(({ key, valid }) => key === "available" || valid)) return null;
|
||||
return _t("Use lowercase letters, numbers, dashes and underscores only");
|
||||
},
|
||||
hideDescriptionIfValid: true,
|
||||
|
@ -448,7 +447,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
return true;
|
||||
}
|
||||
|
||||
private renderEmail(): JSX.Element {
|
||||
private renderEmail(): ReactNode {
|
||||
if (!this.showEmail()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -492,7 +491,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
);
|
||||
}
|
||||
|
||||
public renderPhoneNumber(): JSX.Element {
|
||||
public renderPhoneNumber(): ReactNode {
|
||||
if (!this.showPhoneNumber()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -518,7 +517,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
);
|
||||
}
|
||||
|
||||
public renderUsername(): JSX.Element {
|
||||
public renderUsername(): ReactNode {
|
||||
return (
|
||||
<Field
|
||||
id="mx_RegistrationForm_username"
|
||||
|
@ -534,12 +533,12 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
);
|
||||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
public render(): ReactNode {
|
||||
const registerButton = (
|
||||
<input className="mx_Login_submit" type="submit" value={_t("Register")} disabled={!this.props.canSubmit} />
|
||||
);
|
||||
|
||||
let emailHelperText = null;
|
||||
let emailHelperText: JSX.Element | undefined;
|
||||
if (this.showEmail()) {
|
||||
if (this.showPhoneNumber()) {
|
||||
emailHelperText = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue