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

Add support for deleting threepids #597

Merged
merged 3 commits into from
Dec 22, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/components/structures/UserSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,31 @@ module.exports = React.createClass({
this.setState({email_add_pending: true});
},

onRemoveThreepidClicked: function(threepid) {
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
Modal.createDialog(QuestionDialog, {
title: "Remove Contact Information?",
description: "Remove " + threepid.address + "?",
button: 'Remove',
onFinished: (submit) => {
if (submit) {
this.setState({
phase: "UserSettings.LOADING",
});
MatrixClientPeg.get().deleteThreePid(threepid.medium, threepid.address).then(() => {
return this._refreshFromServer();
}).catch((e) => {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will creating a modal from within an existing modal work? I vaguely remember having to put the second create into a setTimeout(0) to let the other one first disappear...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empirically it seems to be fine (although I did get the variable name wrong)

title: "Unable to remove contact information",
description: err.toString(),
});
}).done();
}
},
});
},

onEmailDialogFinished: function(ok) {
if (ok) {
this.verifyEmailAddress();
Expand Down Expand Up @@ -483,7 +508,6 @@ module.exports = React.createClass({
},

render: function() {
var self = this;
var Loader = sdk.getComponent("elements.Spinner");
switch (this.state.phase) {
case "UserSettings.LOADING":
Expand All @@ -507,7 +531,7 @@ module.exports = React.createClass({
this.state.avatarUrl ? MatrixClientPeg.get().mxcUrlToHttp(this.state.avatarUrl) : null
);

var threepidsSection = this.state.threepids.map(function(val, pidIndex) {
var threepidsSection = this.state.threepids.map((val, pidIndex) => {
var id = "email-" + val.address;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3pid- ?

return (
<div className="mx_UserSettings_profileTableRow" key={pidIndex}>
Expand All @@ -517,6 +541,9 @@ module.exports = React.createClass({
<div className="mx_UserSettings_profileInputCell">
<input key={val.address} id={id} value={val.address} disabled />
</div>
<div className="mx_UserSettings_threepidButton">
<img src="img/icon_context_delete.svg" width="14" height="14" alt="Remove" onClick={this.onRemoveThreepidClicked.bind(this, val)} />
</div>
</div>
);
});
Expand All @@ -537,7 +564,7 @@ module.exports = React.createClass({
blurToCancel={ false }
onValueChanged={ this.onAddThreepidClicked } />
</div>
<div className="mx_UserSettings_addThreepid">
<div className="mx_UserSettings_threepidButton">
<img src="img/plus.svg" width="14" height="14" alt="Add" onClick={ this.onAddThreepidClicked.bind(this, undefined, true) }/>
</div>
</div>
Expand Down