Avoid visual glitch when terms appear for IM

This avoids a visual glitch where the Integration Manager portal would briefly
appear, but then be replaced by a smaller Terms dialog when there's something to
agree to.

To resolve this minimal code churn, this cheats a bit and customises the size of
the terms dialog to match the IM portal modal when terms are shown for IM
purposes.

Fixes https://github.com/vector-im/riot-web/issues/10386
This commit is contained in:
J. Ryan Stinnett 2019-07-23 15:11:38 +01:00
parent 2eb8a8879b
commit 39d5aa7cf4
5 changed files with 49 additions and 19 deletions

View file

@ -15,6 +15,7 @@ limitations under the License.
*/
import Promise from 'bluebird';
import classNames from 'classnames';
import MatrixClientPeg from './MatrixClientPeg';
import sdk from './';
@ -39,17 +40,6 @@ export class Service {
}
}
/**
* Present a popup to the user prompting them to agree to terms and conditions
*
* @param {Service[]} services Object with keys 'serviceType', 'baseUrl', 'accessToken'
* @returns {Promise} resolves when the user agreed to all necessary terms or rejects
* if they cancel.
*/
export function presentTermsForServices(services) {
return startTermsFlow(services, dialogTermsInteractionCallback);
}
/**
* Start a flow where the user is presented with terms & conditions for some services
*
@ -61,7 +51,10 @@ export function presentTermsForServices(services) {
* @returns {Promise} resolves when the user agreed to all necessary terms or rejects
* if they cancel.
*/
export async function startTermsFlow(services, interactionCallback) {
export async function startTermsFlow(
services,
interactionCallback = dialogTermsInteractionCallback,
) {
const termsPromises = services.map(
(s) => MatrixClientPeg.get().getTerms(s.serviceType, s.baseUrl),
);
@ -160,7 +153,11 @@ export async function startTermsFlow(services, interactionCallback) {
return Promise.all(agreePromises);
}
function dialogTermsInteractionCallback(policiesAndServicePairs, agreedUrls) {
export function dialogTermsInteractionCallback(
policiesAndServicePairs,
agreedUrls,
extraClassNames,
) {
return new Promise((resolve, reject) => {
console.log("Terms that need agreement", policiesAndServicePairs);
const TermsDialog = sdk.getComponent("views.dialogs.TermsDialog");
@ -175,6 +172,6 @@ function dialogTermsInteractionCallback(policiesAndServicePairs, agreedUrls) {
}
resolve(agreedUrls);
},
});
}, classNames("mx_TermsDialog", extraClassNames));
});
}