Apply strictNullChecks to src/components/views/voip/* (#10692)

* change interface to discriminated union

* fix ts errors

* use definite assertion operator

* use | undefined, instead of assertion operator

* correct the button press arguments for dial button

* update props to have `Props` suffix

* add comment

* remove unnecessary default

* remove unnecessary comment

* make classname match filename

* setup test file

* export consts for testing

* add initial test

* add another DialPad test

* fix imports
This commit is contained in:
alunturner 2023-05-05 14:26:31 +01:00 committed by GitHub
parent b724cb5fd2
commit 01364ebf45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 12 deletions

View file

@ -1278,7 +1278,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
let title;
let helpText;
let buttonText;
let goButtonFn;
let goButtonFn: (() => Promise<void>) | null = null;
let consultConnectSection;
let extraSection;
let footer;

View file

@ -20,24 +20,36 @@ import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
import { _t } from "../../../languageHandler";
import { XOR } from "../../../@types/common";
const BUTTONS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#"];
const BUTTON_LETTERS = ["", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ", "", "+", ""];
export const BUTTONS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#"];
export const BUTTON_LETTERS = ["", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ", "", "+", ""];
enum DialPadButtonKind {
Digit,
Dial,
}
interface IButtonProps {
kind: DialPadButtonKind;
digit?: string;
digitSubtext?: string;
onButtonPress: (digit: string | undefined, ev: ButtonEvent) => void;
}
type DigitButtonProps = {
kind: DialPadButtonKind.Digit;
digit: string;
digitSubtext: string;
onButtonPress: (digit: string, ev: ButtonEvent) => void;
};
class DialPadButton extends React.PureComponent<IButtonProps> {
type DialButtonProps = {
kind: DialPadButtonKind.Dial;
onButtonPress: () => void;
};
class DialPadButton extends React.PureComponent<DigitButtonProps | DialButtonProps> {
public onClick = (ev: ButtonEvent): void => {
this.props.onButtonPress(this.props.digit, ev);
switch (this.props.kind) {
case DialPadButtonKind.Digit:
this.props.onButtonPress(this.props.digit, ev);
break;
case DialPadButtonKind.Dial:
this.props.onButtonPress();
break;
}
};
public render(): React.ReactNode {
@ -76,7 +88,7 @@ interface IDialProps extends IBaseProps {
onDialPress: () => void;
}
export default class Dialpad extends React.PureComponent<XOR<IProps, IDialProps>> {
export default class DialPad extends React.PureComponent<XOR<IProps, IDialProps>> {
public render(): React.ReactNode {
const buttonNodes: JSX.Element[] = [];