Convert EmailAddress to TS
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
39f92c4ddc
commit
2ebbda482d
1 changed files with 31 additions and 27 deletions
|
@ -16,14 +16,15 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
|
|
||||||
import { _t } from "../../../../languageHandler";
|
import { _t } from "../../../../languageHandler";
|
||||||
import { MatrixClientPeg } from "../../../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../../MatrixClientPeg";
|
||||||
import * as sdk from '../../../../index';
|
|
||||||
import Modal from '../../../../Modal';
|
import Modal from '../../../../Modal';
|
||||||
import AddThreepid from '../../../../AddThreepid';
|
import AddThreepid from '../../../../AddThreepid';
|
||||||
import { replaceableComponent } from "../../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../../utils/replaceableComponent";
|
||||||
|
import { IThreepid } from "matrix-js-sdk/src/@types/threepids";
|
||||||
|
import ErrorDialog from "../../dialogs/ErrorDialog";
|
||||||
|
import AccessibleButton from "../../elements/AccessibleButton";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: Improve the UX for everything in here.
|
TODO: Improve the UX for everything in here.
|
||||||
|
@ -41,12 +42,19 @@ that is available.
|
||||||
TODO: Reduce all the copying between account vs. discovery components.
|
TODO: Reduce all the copying between account vs. discovery components.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export class EmailAddress extends React.Component {
|
interface IEmailAddressProps {
|
||||||
static propTypes = {
|
email: IThreepid;
|
||||||
email: PropTypes.object.isRequired,
|
}
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props) {
|
interface IEmailAddressState {
|
||||||
|
verifying: boolean;
|
||||||
|
addTask: any; // FIXME: When AddThreepid is TSfied
|
||||||
|
continueDisabled: boolean;
|
||||||
|
bound: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class EmailAddress extends React.Component<IEmailAddressProps, IEmailAddressState> {
|
||||||
|
constructor(props: IEmailAddressProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const { bound } = props.email;
|
const { bound } = props.email;
|
||||||
|
@ -60,17 +68,17 @@ export class EmailAddress extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
|
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
|
||||||
UNSAFE_componentWillReceiveProps(nextProps) { // eslint-disable-line camelcase
|
// eslint-disable-next-line @typescript-eslint/naming-convention, camelcase
|
||||||
|
public UNSAFE_componentWillReceiveProps(nextProps: IEmailAddressProps): void {
|
||||||
const { bound } = nextProps.email;
|
const { bound } = nextProps.email;
|
||||||
this.setState({ bound });
|
this.setState({ bound });
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeBinding({ bind, label, errorTitle }) {
|
private async changeBinding({ bind, label, errorTitle }): Promise<void> {
|
||||||
if (!await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind()) {
|
if (!await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind()) {
|
||||||
return this.changeBindingTangledAddBind({ bind, label, errorTitle });
|
return this.changeBindingTangledAddBind({ bind, label, errorTitle });
|
||||||
}
|
}
|
||||||
|
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
||||||
const { medium, address } = this.props.email;
|
const { medium, address } = this.props.email;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -103,8 +111,7 @@ export class EmailAddress extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeBindingTangledAddBind({ bind, label, errorTitle }) {
|
private async changeBindingTangledAddBind({ bind, label, errorTitle }): Promise<void> {
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
||||||
const { medium, address } = this.props.email;
|
const { medium, address } = this.props.email;
|
||||||
|
|
||||||
const task = new AddThreepid();
|
const task = new AddThreepid();
|
||||||
|
@ -139,7 +146,7 @@ export class EmailAddress extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onRevokeClick = (e) => {
|
private onRevokeClick = (e: React.MouseEvent): void => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.changeBinding({
|
this.changeBinding({
|
||||||
|
@ -147,9 +154,9 @@ export class EmailAddress extends React.Component {
|
||||||
label: "revoke",
|
label: "revoke",
|
||||||
errorTitle: _t("Unable to revoke sharing for email address"),
|
errorTitle: _t("Unable to revoke sharing for email address"),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
onShareClick = (e) => {
|
private onShareClick = (e: React.MouseEvent): void => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.changeBinding({
|
this.changeBinding({
|
||||||
|
@ -157,9 +164,9 @@ export class EmailAddress extends React.Component {
|
||||||
label: "share",
|
label: "share",
|
||||||
errorTitle: _t("Unable to share email address"),
|
errorTitle: _t("Unable to share email address"),
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
onContinueClick = async (e) => {
|
private onContinueClick = async (e: React.MouseEvent): Promise<void> => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
@ -173,7 +180,6 @@ export class EmailAddress extends React.Component {
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ continueDisabled: false });
|
this.setState({ continueDisabled: false });
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
||||||
if (err.errcode === 'M_THREEPID_AUTH_FAILED') {
|
if (err.errcode === 'M_THREEPID_AUTH_FAILED') {
|
||||||
Modal.createTrackedDialog("E-mail hasn't been verified yet", "", ErrorDialog, {
|
Modal.createTrackedDialog("E-mail hasn't been verified yet", "", ErrorDialog, {
|
||||||
title: _t("Your email address hasn't been verified yet"),
|
title: _t("Your email address hasn't been verified yet"),
|
||||||
|
@ -188,10 +194,9 @@ export class EmailAddress extends React.Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
public render(): JSX.Element {
|
||||||
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
|
||||||
const { address } = this.props.email;
|
const { address } = this.props.email;
|
||||||
const { verifying, bound } = this.state;
|
const { verifying, bound } = this.state;
|
||||||
|
|
||||||
|
@ -234,14 +239,13 @@ export class EmailAddress extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
interface IProps {
|
||||||
|
emails: IThreepid[];
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.settings.discovery.EmailAddresses")
|
@replaceableComponent("views.settings.discovery.EmailAddresses")
|
||||||
export default class EmailAddresses extends React.Component {
|
export default class EmailAddresses extends React.Component<IProps> {
|
||||||
static propTypes = {
|
public render(): JSX.Element {
|
||||||
emails: PropTypes.array.isRequired,
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
let content;
|
let content;
|
||||||
if (this.props.emails.length > 0) {
|
if (this.props.emails.length > 0) {
|
||||||
content = this.props.emails.map((e) => {
|
content = this.props.emails.map((e) => {
|
Loading…
Reference in a new issue