Enable @typescript-eslint/explicit-function-return-type
in /src (#9788)
* Enable `@typescript-eslint/explicit-member-accessibility` on /src * Prettier * Enable `@typescript-eslint/explicit-function-return-type` in /src * Fix types * tsc strict fixes * Delint * Fix test * Fix bad merge
This commit is contained in:
parent
7a36ba0fde
commit
030b7e90bf
683 changed files with 3459 additions and 3013 deletions
|
@ -22,6 +22,6 @@ interface Props {
|
|||
flex?: boolean;
|
||||
}
|
||||
|
||||
export default function AuthBody({ flex, className, children }: PropsWithChildren<Props>) {
|
||||
export default function AuthBody({ flex, className, children }: PropsWithChildren<Props>): JSX.Element {
|
||||
return <main className={classNames("mx_AuthBody", className, { mx_AuthBody_flex: flex })}>{children}</main>;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
};
|
||||
}
|
||||
|
||||
public componentDidMount() {
|
||||
public componentDidMount(): void {
|
||||
// Just putting a script tag into the returned jsx doesn't work, annoyingly,
|
||||
// so we do this instead.
|
||||
if (this.isRecaptchaReady()) {
|
||||
|
@ -69,7 +69,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
}
|
||||
}
|
||||
|
||||
public componentWillUnmount() {
|
||||
public componentWillUnmount(): void {
|
||||
this.resetRecaptcha();
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
);
|
||||
}
|
||||
|
||||
private renderRecaptcha(divId: string) {
|
||||
private renderRecaptcha(divId: string): void {
|
||||
if (!this.isRecaptchaReady()) {
|
||||
logger.error("grecaptcha not loaded!");
|
||||
throw new Error("Recaptcha did not load successfully");
|
||||
|
@ -101,13 +101,13 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
});
|
||||
}
|
||||
|
||||
private resetRecaptcha() {
|
||||
private resetRecaptcha(): void {
|
||||
if (this.captchaWidgetId) {
|
||||
global?.grecaptcha?.reset(this.captchaWidgetId);
|
||||
}
|
||||
}
|
||||
|
||||
private onCaptchaLoaded() {
|
||||
private onCaptchaLoaded(): void {
|
||||
logger.log("Loaded recaptcha script.");
|
||||
try {
|
||||
this.renderRecaptcha(DIV_ID);
|
||||
|
@ -122,7 +122,7 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
|
|||
}
|
||||
}
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
let error = null;
|
||||
if (this.state.errorText) {
|
||||
error = <div className="error">{this.state.errorText}</div>;
|
||||
|
|
|
@ -60,7 +60,7 @@ class EmailField extends PureComponent<IProps> {
|
|||
],
|
||||
});
|
||||
|
||||
public onValidate = async (fieldState: IFieldState) => {
|
||||
public onValidate = async (fieldState: IFieldState): Promise<IValidationResult> => {
|
||||
let validate = this.validate;
|
||||
if (this.props.validationRules) {
|
||||
validate = this.props.validationRules;
|
||||
|
@ -74,7 +74,7 @@ class EmailField extends PureComponent<IProps> {
|
|||
return result;
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
return (
|
||||
<Field
|
||||
id={this.props.id}
|
||||
|
|
|
@ -108,11 +108,11 @@ export class PasswordAuthEntry extends React.Component<IAuthEntryProps, IPasswor
|
|||
};
|
||||
}
|
||||
|
||||
public componentDidMount() {
|
||||
public componentDidMount(): void {
|
||||
this.props.onPhaseChange(DEFAULT_PHASE);
|
||||
}
|
||||
|
||||
private onSubmit = (e: FormEvent) => {
|
||||
private onSubmit = (e: FormEvent): void => {
|
||||
e.preventDefault();
|
||||
if (this.props.busy) return;
|
||||
|
||||
|
@ -129,14 +129,14 @@ export class PasswordAuthEntry extends React.Component<IAuthEntryProps, IPasswor
|
|||
});
|
||||
};
|
||||
|
||||
private onPasswordFieldChange = (ev: ChangeEvent<HTMLInputElement>) => {
|
||||
private onPasswordFieldChange = (ev: ChangeEvent<HTMLInputElement>): void => {
|
||||
// enable the submit button iff the password is non-empty
|
||||
this.setState({
|
||||
password: ev.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
const passwordBoxClass = classNames({
|
||||
error: this.props.errorText,
|
||||
});
|
||||
|
@ -196,18 +196,18 @@ interface IRecaptchaAuthEntryProps extends IAuthEntryProps {
|
|||
export class RecaptchaAuthEntry extends React.Component<IRecaptchaAuthEntryProps> {
|
||||
public static LOGIN_TYPE = AuthType.Recaptcha;
|
||||
|
||||
public componentDidMount() {
|
||||
public componentDidMount(): void {
|
||||
this.props.onPhaseChange(DEFAULT_PHASE);
|
||||
}
|
||||
|
||||
private onCaptchaResponse = (response: string) => {
|
||||
private onCaptchaResponse = (response: string): void => {
|
||||
this.props.submitAuthDict({
|
||||
type: AuthType.Recaptcha,
|
||||
response: response,
|
||||
});
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
if (this.props.busy) {
|
||||
return <Spinner />;
|
||||
}
|
||||
|
@ -320,11 +320,11 @@ export class TermsAuthEntry extends React.Component<ITermsAuthEntryProps, ITerms
|
|||
};
|
||||
}
|
||||
|
||||
public componentDidMount() {
|
||||
public componentDidMount(): void {
|
||||
this.props.onPhaseChange(DEFAULT_PHASE);
|
||||
}
|
||||
|
||||
private togglePolicy(policyId: string) {
|
||||
private togglePolicy(policyId: string): void {
|
||||
const newToggles = {};
|
||||
for (const policy of this.state.policies) {
|
||||
let checked = this.state.toggledPolicies[policy.id];
|
||||
|
@ -335,7 +335,7 @@ export class TermsAuthEntry extends React.Component<ITermsAuthEntryProps, ITerms
|
|||
this.setState({ toggledPolicies: newToggles });
|
||||
}
|
||||
|
||||
private trySubmit = () => {
|
||||
private trySubmit = (): void => {
|
||||
let allChecked = true;
|
||||
for (const policy of this.state.policies) {
|
||||
const checked = this.state.toggledPolicies[policy.id];
|
||||
|
@ -349,7 +349,7 @@ export class TermsAuthEntry extends React.Component<ITermsAuthEntryProps, ITerms
|
|||
}
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
if (this.props.busy) {
|
||||
return <Spinner />;
|
||||
}
|
||||
|
@ -434,11 +434,11 @@ export class EmailIdentityAuthEntry extends React.Component<
|
|||
};
|
||||
}
|
||||
|
||||
public componentDidMount() {
|
||||
public componentDidMount(): void {
|
||||
this.props.onPhaseChange(DEFAULT_PHASE);
|
||||
}
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
let errorSection;
|
||||
// ignore the error when errcode is M_UNAUTHORIZED as we expect that error until the link is clicked.
|
||||
if (this.props.errorText && this.props.errorCode !== "M_UNAUTHORIZED") {
|
||||
|
@ -508,7 +508,7 @@ export class EmailIdentityAuthEntry extends React.Component<
|
|||
? () => this.setState({ requested: false })
|
||||
: undefined
|
||||
}
|
||||
onClick={async () => {
|
||||
onClick={async (): Promise<void> => {
|
||||
this.setState({ requesting: true });
|
||||
try {
|
||||
await this.props.requestEmailToken?.();
|
||||
|
@ -565,7 +565,7 @@ export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsi
|
|||
};
|
||||
}
|
||||
|
||||
public componentDidMount() {
|
||||
public componentDidMount(): void {
|
||||
this.props.onPhaseChange(DEFAULT_PHASE);
|
||||
|
||||
this.setState({ requestingToken: true });
|
||||
|
@ -596,13 +596,13 @@ export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsi
|
|||
});
|
||||
}
|
||||
|
||||
private onTokenChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
private onTokenChange = (e: ChangeEvent<HTMLInputElement>): void => {
|
||||
this.setState({
|
||||
token: e.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
private onFormSubmit = async (e: FormEvent) => {
|
||||
private onFormSubmit = async (e: FormEvent): Promise<void> => {
|
||||
e.preventDefault();
|
||||
if (this.state.token == "") return;
|
||||
|
||||
|
@ -646,7 +646,7 @@ export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsi
|
|||
}
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
if (this.state.requestingToken) {
|
||||
return <Spinner />;
|
||||
} else {
|
||||
|
@ -729,11 +729,11 @@ export class SSOAuthEntry extends React.Component<ISSOAuthEntryProps, ISSOAuthEn
|
|||
};
|
||||
}
|
||||
|
||||
public componentDidMount() {
|
||||
public componentDidMount(): void {
|
||||
this.props.onPhaseChange(SSOAuthEntry.PHASE_PREAUTH);
|
||||
}
|
||||
|
||||
public componentWillUnmount() {
|
||||
public componentWillUnmount(): void {
|
||||
window.removeEventListener("message", this.onReceiveMessage);
|
||||
if (this.popupWindow) {
|
||||
this.popupWindow.close();
|
||||
|
@ -741,13 +741,13 @@ export class SSOAuthEntry extends React.Component<ISSOAuthEntryProps, ISSOAuthEn
|
|||
}
|
||||
}
|
||||
|
||||
public attemptFailed = () => {
|
||||
public attemptFailed = (): void => {
|
||||
this.setState({
|
||||
attemptFailed: true,
|
||||
});
|
||||
};
|
||||
|
||||
private onReceiveMessage = (event: MessageEvent) => {
|
||||
private onReceiveMessage = (event: MessageEvent): void => {
|
||||
if (event.data === "authDone" && event.origin === this.props.matrixClient.getHomeserverUrl()) {
|
||||
if (this.popupWindow) {
|
||||
this.popupWindow.close();
|
||||
|
@ -756,7 +756,7 @@ export class SSOAuthEntry extends React.Component<ISSOAuthEntryProps, ISSOAuthEn
|
|||
}
|
||||
};
|
||||
|
||||
private onStartAuthClick = () => {
|
||||
private onStartAuthClick = (): void => {
|
||||
// Note: We don't use PlatformPeg's startSsoAuth functions because we almost
|
||||
// certainly will need to open the thing in a new tab to avoid losing application
|
||||
// context.
|
||||
|
@ -766,11 +766,11 @@ export class SSOAuthEntry extends React.Component<ISSOAuthEntryProps, ISSOAuthEn
|
|||
this.props.onPhaseChange(SSOAuthEntry.PHASE_POSTAUTH);
|
||||
};
|
||||
|
||||
private onConfirmClick = () => {
|
||||
private onConfirmClick = (): void => {
|
||||
this.props.submitAuthDict({});
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
let continueButton = null;
|
||||
const cancelButton = (
|
||||
<AccessibleButton
|
||||
|
@ -834,24 +834,24 @@ export class FallbackAuthEntry extends React.Component<IAuthEntryProps> {
|
|||
window.addEventListener("message", this.onReceiveMessage);
|
||||
}
|
||||
|
||||
public componentDidMount() {
|
||||
public componentDidMount(): void {
|
||||
this.props.onPhaseChange(DEFAULT_PHASE);
|
||||
}
|
||||
|
||||
public componentWillUnmount() {
|
||||
public componentWillUnmount(): void {
|
||||
window.removeEventListener("message", this.onReceiveMessage);
|
||||
if (this.popupWindow) {
|
||||
this.popupWindow.close();
|
||||
}
|
||||
}
|
||||
|
||||
public focus = () => {
|
||||
public focus = (): void => {
|
||||
if (this.fallbackButton.current) {
|
||||
this.fallbackButton.current.focus();
|
||||
}
|
||||
};
|
||||
|
||||
private onShowFallbackClick = (e: MouseEvent) => {
|
||||
private onShowFallbackClick = (e: MouseEvent): void => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
|
@ -859,13 +859,13 @@ export class FallbackAuthEntry extends React.Component<IAuthEntryProps> {
|
|||
this.popupWindow = window.open(url, "_blank");
|
||||
};
|
||||
|
||||
private onReceiveMessage = (event: MessageEvent) => {
|
||||
private onReceiveMessage = (event: MessageEvent): void => {
|
||||
if (event.data === "authDone" && event.origin === this.props.matrixClient.getHomeserverUrl()) {
|
||||
this.props.submitAuthDict({});
|
||||
}
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
let errorSection;
|
||||
if (this.props.errorText) {
|
||||
errorSection = (
|
||||
|
|
|
@ -93,7 +93,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
|
|||
}
|
||||
}
|
||||
|
||||
private async updateMode(mode: Mode) {
|
||||
private async updateMode(mode: Mode): Promise<void> {
|
||||
this.setState({ phase: Phase.Loading });
|
||||
if (this.state.rendezvous) {
|
||||
const rendezvous = this.state.rendezvous;
|
||||
|
@ -150,7 +150,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
|
|||
}
|
||||
};
|
||||
|
||||
private generateCode = async () => {
|
||||
private generateCode = async (): Promise<void> => {
|
||||
let rendezvous: MSC3906Rendezvous;
|
||||
try {
|
||||
const transport = new MSC3886SimpleHttpRendezvousTransport<MSC3903ECDHPayload>({
|
||||
|
@ -190,12 +190,12 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
|
|||
}
|
||||
};
|
||||
|
||||
private onFailure = (reason: RendezvousFailureReason) => {
|
||||
private onFailure = (reason: RendezvousFailureReason): void => {
|
||||
logger.info(`Rendezvous failed: ${reason}`);
|
||||
this.setState({ phase: Phase.Error, failureReason: reason });
|
||||
};
|
||||
|
||||
public reset() {
|
||||
public reset(): void {
|
||||
this.setState({
|
||||
rendezvous: undefined,
|
||||
confirmationDigits: undefined,
|
||||
|
@ -203,7 +203,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
|
|||
});
|
||||
}
|
||||
|
||||
private onClick = async (type: Click) => {
|
||||
private onClick = async (type: Click): Promise<void> => {
|
||||
switch (type) {
|
||||
case Click.Cancel:
|
||||
await this.state.rendezvous?.cancel(RendezvousFailureReason.UserCancelled);
|
||||
|
@ -229,7 +229,7 @@ export default class LoginWithQR extends React.Component<IProps, IState> {
|
|||
}
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
return (
|
||||
<LoginWithQRFlow
|
||||
onClick={this.onClick}
|
||||
|
|
|
@ -45,14 +45,14 @@ export default class LoginWithQRFlow extends React.Component<IProps> {
|
|||
super(props);
|
||||
}
|
||||
|
||||
private handleClick = (type: Click) => {
|
||||
return async (e: React.FormEvent) => {
|
||||
private handleClick = (type: Click): ((e: React.FormEvent) => Promise<void>) => {
|
||||
return async (e: React.FormEvent): Promise<void> => {
|
||||
e.preventDefault();
|
||||
await this.props.onClick(type);
|
||||
};
|
||||
};
|
||||
|
||||
private cancelButton = () => (
|
||||
private cancelButton = (): JSX.Element => (
|
||||
<AccessibleButton data-testid="cancel-button" kind="primary_outline" onClick={this.handleClick(Click.Cancel)}>
|
||||
{_t("Cancel")}
|
||||
</AccessibleButton>
|
||||
|
@ -69,7 +69,7 @@ export default class LoginWithQRFlow extends React.Component<IProps> {
|
|||
);
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
let title = "";
|
||||
let titleIcon: JSX.Element | undefined;
|
||||
let main: JSX.Element | undefined;
|
||||
|
|
|
@ -56,7 +56,7 @@ class PassphraseConfirmField extends PureComponent<IProps> {
|
|||
],
|
||||
});
|
||||
|
||||
private onValidate = async (fieldState: IFieldState) => {
|
||||
private onValidate = async (fieldState: IFieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validate(fieldState);
|
||||
if (this.props.onValidate) {
|
||||
this.props.onValidate(result);
|
||||
|
@ -65,7 +65,7 @@ class PassphraseConfirmField extends PureComponent<IProps> {
|
|||
return result;
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
return (
|
||||
<Field
|
||||
id={this.props.id}
|
||||
|
|
|
@ -53,7 +53,7 @@ class PassphraseField extends PureComponent<IProps> {
|
|||
const score = complexity ? complexity.score : 0;
|
||||
return <progress className="mx_PassphraseField_progress" max={4} value={score} />;
|
||||
},
|
||||
deriveData: async ({ value }) => {
|
||||
deriveData: async ({ value }): Promise<zxcvbn.ZXCVBNResult> => {
|
||||
if (!value) return null;
|
||||
const { scorePassword } = await import("../../../utils/PasswordScorer");
|
||||
return scorePassword(value);
|
||||
|
@ -66,7 +66,7 @@ class PassphraseField extends PureComponent<IProps> {
|
|||
},
|
||||
{
|
||||
key: "complexity",
|
||||
test: async function ({ value }, complexity) {
|
||||
test: async function ({ value }, complexity): Promise<boolean> {
|
||||
if (!value) {
|
||||
return false;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ class PassphraseField extends PureComponent<IProps> {
|
|||
],
|
||||
});
|
||||
|
||||
public onValidate = async (fieldState: IFieldState) => {
|
||||
public onValidate = async (fieldState: IFieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validate(fieldState);
|
||||
if (this.props.onValidate) {
|
||||
this.props.onValidate(result);
|
||||
|
@ -102,7 +102,7 @@ class PassphraseField extends PureComponent<IProps> {
|
|||
return result;
|
||||
};
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
return (
|
||||
<Field
|
||||
id={this.props.id}
|
||||
|
|
|
@ -54,7 +54,7 @@ interface IState {
|
|||
password: "";
|
||||
}
|
||||
|
||||
enum LoginField {
|
||||
const enum LoginField {
|
||||
Email = "login_field_email",
|
||||
MatrixId = "login_field_mxid",
|
||||
Phone = "login_field_phone",
|
||||
|
@ -85,13 +85,13 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
};
|
||||
}
|
||||
|
||||
private onForgotPasswordClick = (ev) => {
|
||||
private onForgotPasswordClick = (ev): void => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this.props.onForgotPasswordClick();
|
||||
};
|
||||
|
||||
private onSubmitForm = async (ev) => {
|
||||
private onSubmitForm = async (ev): Promise<void> => {
|
||||
ev.preventDefault();
|
||||
|
||||
const allFieldsValid = await this.verifyFieldsBeforeSubmit();
|
||||
|
@ -117,33 +117,33 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
this.props.onSubmit(username, phoneCountry, phoneNumber, this.state.password);
|
||||
};
|
||||
|
||||
private onUsernameChanged = (ev) => {
|
||||
private onUsernameChanged = (ev): void => {
|
||||
this.props.onUsernameChanged(ev.target.value);
|
||||
};
|
||||
|
||||
private onUsernameBlur = (ev) => {
|
||||
private onUsernameBlur = (ev): void => {
|
||||
this.props.onUsernameBlur(ev.target.value);
|
||||
};
|
||||
|
||||
private onLoginTypeChange = (ev) => {
|
||||
private onLoginTypeChange = (ev): void => {
|
||||
const loginType = ev.target.value;
|
||||
this.setState({ loginType });
|
||||
this.props.onUsernameChanged(""); // Reset because email and username use the same state
|
||||
};
|
||||
|
||||
private onPhoneCountryChanged = (country) => {
|
||||
private onPhoneCountryChanged = (country): void => {
|
||||
this.props.onPhoneCountryChanged(country.iso2);
|
||||
};
|
||||
|
||||
private onPhoneNumberChanged = (ev) => {
|
||||
private onPhoneNumberChanged = (ev): void => {
|
||||
this.props.onPhoneNumberChanged(ev.target.value);
|
||||
};
|
||||
|
||||
private onPasswordChanged = (ev) => {
|
||||
private onPasswordChanged = (ev): void => {
|
||||
this.setState({ password: ev.target.value });
|
||||
};
|
||||
|
||||
private async verifyFieldsBeforeSubmit() {
|
||||
private async verifyFieldsBeforeSubmit(): Promise<boolean> {
|
||||
// Blur the active element if any, so we first run its blur validation,
|
||||
// which is less strict than the pass we're about to do below for all fields.
|
||||
const activeElement = document.activeElement as HTMLElement;
|
||||
|
@ -192,7 +192,7 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
return Object.values(this.state.fieldValid).every(Boolean);
|
||||
}
|
||||
|
||||
private findFirstInvalidField(fieldIDs: LoginField[]) {
|
||||
private findFirstInvalidField(fieldIDs: LoginField[]): Field | null {
|
||||
for (const fieldID of fieldIDs) {
|
||||
if (!this.state.fieldValid[fieldID] && this[fieldID]) {
|
||||
return this[fieldID];
|
||||
|
@ -201,7 +201,7 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
return null;
|
||||
}
|
||||
|
||||
private markFieldValid(fieldID: LoginField, valid: boolean) {
|
||||
private markFieldValid(fieldID: LoginField, valid: boolean): void {
|
||||
const { fieldValid } = this.state;
|
||||
fieldValid[fieldID] = valid;
|
||||
this.setState({
|
||||
|
@ -221,13 +221,13 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
],
|
||||
});
|
||||
|
||||
private onUsernameValidate = async (fieldState) => {
|
||||
private onUsernameValidate = async (fieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validateUsernameRules(fieldState);
|
||||
this.markFieldValid(LoginField.MatrixId, result.valid);
|
||||
return result;
|
||||
};
|
||||
|
||||
private onEmailValidate = (result: IValidationResult) => {
|
||||
private onEmailValidate = (result: IValidationResult): void => {
|
||||
this.markFieldValid(LoginField.Email, result.valid);
|
||||
};
|
||||
|
||||
|
@ -235,20 +235,20 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
rules: [
|
||||
{
|
||||
key: "required",
|
||||
test({ value, allowEmpty }) {
|
||||
test({ value, allowEmpty }): boolean {
|
||||
return allowEmpty || !!value;
|
||||
},
|
||||
invalid: () => _t("Enter phone number"),
|
||||
invalid: (): string => _t("Enter phone number"),
|
||||
},
|
||||
{
|
||||
key: "number",
|
||||
test: ({ value }) => !value || PHONE_NUMBER_REGEX.test(value),
|
||||
invalid: () => _t("That phone number doesn't look quite right, please check and try again"),
|
||||
test: ({ value }): boolean => !value || PHONE_NUMBER_REGEX.test(value),
|
||||
invalid: (): string => _t("That phone number doesn't look quite right, please check and try again"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
private onPhoneNumberValidate = async (fieldState) => {
|
||||
private onPhoneNumberValidate = async (fieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validatePhoneNumberRules(fieldState);
|
||||
this.markFieldValid(LoginField.Password, result.valid);
|
||||
return result;
|
||||
|
@ -258,21 +258,21 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
rules: [
|
||||
{
|
||||
key: "required",
|
||||
test({ value, allowEmpty }) {
|
||||
test({ value, allowEmpty }): boolean {
|
||||
return allowEmpty || !!value;
|
||||
},
|
||||
invalid: () => _t("Enter password"),
|
||||
invalid: (): string => _t("Enter password"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
private onPasswordValidate = async (fieldState) => {
|
||||
private onPasswordValidate = async (fieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validatePasswordRules(fieldState);
|
||||
this.markFieldValid(LoginField.Password, result.valid);
|
||||
return result;
|
||||
};
|
||||
|
||||
private renderLoginField(loginType: IState["loginType"], autoFocus: boolean) {
|
||||
private renderLoginField(loginType: IState["loginType"], autoFocus: boolean): JSX.Element {
|
||||
const classes = {
|
||||
error: false,
|
||||
};
|
||||
|
@ -295,7 +295,9 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
disabled={this.props.busy}
|
||||
autoFocus={autoFocus}
|
||||
onValidate={this.onEmailValidate}
|
||||
fieldRef={(field) => (this[LoginField.Email] = field)}
|
||||
fieldRef={(field): void => {
|
||||
this[LoginField.Email] = field;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
case LoginField.MatrixId:
|
||||
|
@ -316,7 +318,9 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
disabled={this.props.busy}
|
||||
autoFocus={autoFocus}
|
||||
onValidate={this.onUsernameValidate}
|
||||
ref={(field) => (this[LoginField.MatrixId] = field)}
|
||||
ref={(field): void => {
|
||||
this[LoginField.MatrixId] = field;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
case LoginField.Phone: {
|
||||
|
@ -346,14 +350,16 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
disabled={this.props.busy}
|
||||
autoFocus={autoFocus}
|
||||
onValidate={this.onPhoneNumberValidate}
|
||||
ref={(field) => (this[LoginField.Password] = field)}
|
||||
ref={(field): void => {
|
||||
this[LoginField.Password] = field;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private isLoginEmpty() {
|
||||
private isLoginEmpty(): boolean {
|
||||
switch (this.state.loginType) {
|
||||
case LoginField.Email:
|
||||
case LoginField.MatrixId:
|
||||
|
@ -363,7 +369,7 @@ export default class PasswordLogin extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
}
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
let forgotPasswordJsx;
|
||||
|
||||
if (this.props.onForgotPasswordClick) {
|
||||
|
|
|
@ -115,7 +115,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
};
|
||||
}
|
||||
|
||||
private onSubmit = async (ev) => {
|
||||
private onSubmit = async (ev): Promise<void> => {
|
||||
ev.preventDefault();
|
||||
ev.persist();
|
||||
|
||||
|
@ -129,7 +129,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
if (this.state.email === "") {
|
||||
if (this.showEmail()) {
|
||||
Modal.createDialog(RegistrationEmailPromptDialog, {
|
||||
onFinished: async (confirmed: boolean, email?: string) => {
|
||||
onFinished: async (confirmed: boolean, email?: string): Promise<void> => {
|
||||
if (confirmed) {
|
||||
this.setState(
|
||||
{
|
||||
|
@ -152,7 +152,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
}
|
||||
};
|
||||
|
||||
private doSubmit(ev) {
|
||||
private doSubmit(ev): void {
|
||||
PosthogAnalytics.instance.setAuthenticationType("Password");
|
||||
|
||||
const email = this.state.email.trim();
|
||||
|
@ -173,7 +173,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
}
|
||||
}
|
||||
|
||||
private async verifyFieldsBeforeSubmit() {
|
||||
private async verifyFieldsBeforeSubmit(): Promise<boolean> {
|
||||
// Blur the active element if any, so we first run its blur validation,
|
||||
// which is less strict than the pass we're about to do below for all fields.
|
||||
const activeElement = document.activeElement as HTMLElement;
|
||||
|
@ -231,7 +231,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
return Object.values(this.state.fieldValid).every(Boolean);
|
||||
}
|
||||
|
||||
private findFirstInvalidField(fieldIDs: RegistrationField[]) {
|
||||
private findFirstInvalidField(fieldIDs: RegistrationField[]): Field | null {
|
||||
for (const fieldID of fieldIDs) {
|
||||
if (!this.state.fieldValid[fieldID] && this[fieldID]) {
|
||||
return this[fieldID];
|
||||
|
@ -240,7 +240,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
return null;
|
||||
}
|
||||
|
||||
private markFieldValid(fieldID: RegistrationField, valid: boolean) {
|
||||
private markFieldValid(fieldID: RegistrationField, valid: boolean): void {
|
||||
const { fieldValid } = this.state;
|
||||
fieldValid[fieldID] = valid;
|
||||
this.setState({
|
||||
|
@ -248,13 +248,13 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
});
|
||||
}
|
||||
|
||||
private onEmailChange = (ev) => {
|
||||
private onEmailChange = (ev): void => {
|
||||
this.setState({
|
||||
email: ev.target.value.trim(),
|
||||
});
|
||||
};
|
||||
|
||||
private onEmailValidate = (result: IValidationResult) => {
|
||||
private onEmailValidate = (result: IValidationResult): void => {
|
||||
this.markFieldValid(RegistrationField.Email, result.valid);
|
||||
};
|
||||
|
||||
|
@ -277,39 +277,39 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
],
|
||||
});
|
||||
|
||||
private onPasswordChange = (ev) => {
|
||||
private onPasswordChange = (ev): void => {
|
||||
this.setState({
|
||||
password: ev.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
private onPasswordValidate = (result) => {
|
||||
private onPasswordValidate = (result: IValidationResult): void => {
|
||||
this.markFieldValid(RegistrationField.Password, result.valid);
|
||||
};
|
||||
|
||||
private onPasswordConfirmChange = (ev) => {
|
||||
private onPasswordConfirmChange = (ev): void => {
|
||||
this.setState({
|
||||
passwordConfirm: ev.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
private onPasswordConfirmValidate = (result: IValidationResult) => {
|
||||
private onPasswordConfirmValidate = (result: IValidationResult): void => {
|
||||
this.markFieldValid(RegistrationField.PasswordConfirm, result.valid);
|
||||
};
|
||||
|
||||
private onPhoneCountryChange = (newVal) => {
|
||||
private onPhoneCountryChange = (newVal): void => {
|
||||
this.setState({
|
||||
phoneCountry: newVal.iso2,
|
||||
});
|
||||
};
|
||||
|
||||
private onPhoneNumberChange = (ev) => {
|
||||
private onPhoneNumberChange = (ev): void => {
|
||||
this.setState({
|
||||
phoneNumber: ev.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
private onPhoneNumberValidate = async (fieldState) => {
|
||||
private onPhoneNumberValidate = async (fieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validatePhoneNumberRules(fieldState);
|
||||
this.markFieldValid(RegistrationField.PhoneNumber, result.valid);
|
||||
return result;
|
||||
|
@ -334,13 +334,13 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
],
|
||||
});
|
||||
|
||||
private onUsernameChange = (ev) => {
|
||||
private onUsernameChange = (ev): void => {
|
||||
this.setState({
|
||||
username: ev.target.value,
|
||||
});
|
||||
};
|
||||
|
||||
private onUsernameValidate = async (fieldState) => {
|
||||
private onUsernameValidate = async (fieldState): Promise<IValidationResult> => {
|
||||
const result = await this.validateUsernameRules(fieldState);
|
||||
this.markFieldValid(RegistrationField.Username, result.valid);
|
||||
return result;
|
||||
|
@ -384,7 +384,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
{
|
||||
key: "available",
|
||||
final: true,
|
||||
test: async ({ value }, usernameAvailable) => {
|
||||
test: async ({ value }, usernameAvailable): Promise<boolean> => {
|
||||
if (!value) {
|
||||
return true;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
* @param {string} step A stage name to check
|
||||
* @returns {boolean} Whether it is required
|
||||
*/
|
||||
private authStepIsRequired(step: string) {
|
||||
private authStepIsRequired(step: string): boolean {
|
||||
return this.props.flows.every((flow) => {
|
||||
return flow.stages.includes(step);
|
||||
});
|
||||
|
@ -417,20 +417,20 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
* @param {string} step A stage name to check
|
||||
* @returns {boolean} Whether it is used
|
||||
*/
|
||||
private authStepIsUsed(step: string) {
|
||||
private authStepIsUsed(step: string): boolean {
|
||||
return this.props.flows.some((flow) => {
|
||||
return flow.stages.includes(step);
|
||||
});
|
||||
}
|
||||
|
||||
private showEmail() {
|
||||
private showEmail(): boolean {
|
||||
if (!this.authStepIsUsed("m.login.email.identity")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private showPhoneNumber() {
|
||||
private showPhoneNumber(): boolean {
|
||||
const threePidLogin = !SdkConfig.get().disable_3pid_login;
|
||||
if (!threePidLogin || !this.authStepIsUsed("m.login.msisdn")) {
|
||||
return false;
|
||||
|
@ -438,7 +438,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
return true;
|
||||
}
|
||||
|
||||
private renderEmail() {
|
||||
private renderEmail(): JSX.Element {
|
||||
if (!this.showEmail()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
);
|
||||
}
|
||||
|
||||
private renderPassword() {
|
||||
private renderPassword(): JSX.Element {
|
||||
return (
|
||||
<PassphraseField
|
||||
id="mx_RegistrationForm_password"
|
||||
|
@ -468,7 +468,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
);
|
||||
}
|
||||
|
||||
public renderPasswordConfirm() {
|
||||
public renderPasswordConfirm(): JSX.Element {
|
||||
return (
|
||||
<PassphraseConfirmField
|
||||
id="mx_RegistrationForm_passwordConfirm"
|
||||
|
@ -482,7 +482,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
);
|
||||
}
|
||||
|
||||
public renderPhoneNumber() {
|
||||
public renderPhoneNumber(): JSX.Element {
|
||||
if (!this.showPhoneNumber()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -508,7 +508,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
);
|
||||
}
|
||||
|
||||
public renderUsername() {
|
||||
public renderUsername(): JSX.Element {
|
||||
return (
|
||||
<Field
|
||||
id="mx_RegistrationForm_username"
|
||||
|
@ -524,7 +524,7 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
|
|||
);
|
||||
}
|
||||
|
||||
public render() {
|
||||
public render(): JSX.Element {
|
||||
const registerButton = (
|
||||
<input className="mx_Login_submit" type="submit" value={_t("Register")} disabled={!this.props.canSubmit} />
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue