Use existing modal promises

pull/21833/head
J. Ryan Stinnett 2019-09-06 10:48:24 +01:00
parent d5552e4a17
commit 2ff592c542
1 changed files with 25 additions and 27 deletions

View File

@ -167,13 +167,14 @@ export default class SetIdServer extends React.Component {
// Double check that the identity server even has terms of service. // Double check that the identity server even has terms of service.
const terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl); const terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl);
if (!terms || !terms["policies"] || Object.keys(terms["policies"]).length <= 0) { if (!terms || !terms["policies"] || Object.keys(terms["policies"]).length <= 0) {
save &= await this._showNoTermsWarning(fullUrl); const [confirmed] = await this._showNoTermsWarning(fullUrl);
save &= confirmed;
} }
// Show a general warning, possibly with details about any bound // Show a general warning, possibly with details about any bound
// 3PIDs that would be left behind. // 3PIDs that would be left behind.
if (this.state.currentClientIdServer) { if (save && this.state.currentClientIdServer) {
save &= await this._showServerChangeWarning({ const [confirmed] = await this._showServerChangeWarning({
title: _t("Change identity server"), title: _t("Change identity server"),
unboundMessage: _t( unboundMessage: _t(
"Disconnect from the identity server <current /> and " + "Disconnect from the identity server <current /> and " +
@ -185,6 +186,7 @@ export default class SetIdServer extends React.Component {
), ),
button: _t("Continue"), button: _t("Continue"),
}); });
save &= confirmed;
} }
if (save) { if (save) {
@ -209,8 +211,7 @@ export default class SetIdServer extends React.Component {
_showNoTermsWarning(fullUrl) { _showNoTermsWarning(fullUrl) {
const QuestionDialog = sdk.getComponent("views.dialogs.QuestionDialog"); const QuestionDialog = sdk.getComponent("views.dialogs.QuestionDialog");
return new Promise(resolve => { const { finished } = Modal.createTrackedDialog('No Terms Warning', '', QuestionDialog, {
Modal.createTrackedDialog('No Terms Warning', '', QuestionDialog, {
title: _t("Identity server has no terms of service"), title: _t("Identity server has no terms of service"),
description: ( description: (
<div> <div>
@ -223,15 +224,14 @@ export default class SetIdServer extends React.Component {
</div> </div>
), ),
button: _t("Continue"), button: _t("Continue"),
onFinished: resolve,
});
}); });
return finished;
} }
_onDisconnectClicked = async () => { _onDisconnectClicked = async () => {
this.setState({disconnectBusy: true}); this.setState({disconnectBusy: true});
try { try {
const confirmed = await this._showServerChangeWarning({ const [confirmed] = await this._showServerChangeWarning({
title: _t("Disconnect identity server"), title: _t("Disconnect identity server"),
unboundMessage: _t( unboundMessage: _t(
"Disconnect from the identity server <idserver />?", {}, "Disconnect from the identity server <idserver />?", {},
@ -268,14 +268,12 @@ export default class SetIdServer extends React.Component {
} }
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
return new Promise(resolve => { const { finished } = Modal.createTrackedDialog('Identity Server Bound Warning', '', QuestionDialog, {
Modal.createTrackedDialog('Identity Server Bound Warning', '', QuestionDialog, {
title, title,
description: message, description: message,
button, button,
onFinished: resolve,
});
}); });
return finished;
} }
_disconnectIdServer = () => { _disconnectIdServer = () => {