Prevent the plan dialog from opening multiple times

Close #8868
This commit is contained in:
wrd 2025-10-16 13:51:42 +02:00 committed by paw
parent 9100edc7b8
commit c33c24053e

View file

@ -9,19 +9,34 @@ import { GENERATED_MAX_ID } from "../api/common/utils/EntityUtils.js"
import { AvailablePlanType, Const, NewBusinessPlans, NewPaidPlans, NewPersonalPlans, PlanType } from "../api/common/TutanotaConstants.js" import { AvailablePlanType, Const, NewBusinessPlans, NewPaidPlans, NewPersonalPlans, PlanType } from "../api/common/TutanotaConstants.js"
import { ProgrammingError } from "../api/common/error/ProgrammingError.js" import { ProgrammingError } from "../api/common/error/ProgrammingError.js"
let upgradeDialogShowing = false
/** /**
* Opens a dialog which states that the function is not available in the Free subscription and provides an option to upgrade. * Opens a dialog which states that the function is not available in the Free subscription and provides an option to upgrade.
*/ */
export async function showNotAvailableForFreeDialog(acceptedPlans: readonly AvailablePlanType[] = NewPaidPlans) { export async function showNotAvailableForFreeDialog(acceptedPlans: readonly AvailablePlanType[] = NewPaidPlans) {
const wizard = await import("../subscription/UpgradeSubscriptionWizard") // upgradeDialogShowing prevents the dialog from being opened multiple times, as could happen when waiting for the wizard to import
const customerInfo = await locator.logins.getUserController().loadCustomerInfo() if (!upgradeDialogShowing) {
upgradeDialogShowing = true
try {
const wizard = await import("../subscription/UpgradeSubscriptionWizard")
const customerInfo = await locator.logins.getUserController().loadCustomerInfo()
const businessPlanRequired = const businessPlanRequired =
acceptedPlans.filter((plan) => NewBusinessPlans.includes(plan)).length === acceptedPlans.length && acceptedPlans.filter((plan) => NewBusinessPlans.includes(plan)).length === acceptedPlans.length &&
NewPersonalPlans.includes(downcast(customerInfo.plan)) NewPersonalPlans.includes(downcast(customerInfo.plan))
const msg = lang.getTranslation(businessPlanRequired ? "pricing.notSupportedByPersonalPlan_msg" : "newPaidPlanRequired_msg") const msg = lang.getTranslation(businessPlanRequired ? "pricing.notSupportedByPersonalPlan_msg" : "newPaidPlanRequired_msg")
await wizard.showUpgradeWizard({ logins: locator.logins, isCalledBySatisfactionDialog: false, acceptedPlans, msg }) await wizard.showUpgradeWizard({
logins: locator.logins,
isCalledBySatisfactionDialog: false,
acceptedPlans,
msg,
})
} finally {
upgradeDialogShowing = false
}
}
} }
export function createNotAvailableForFreeClickHandler( export function createNotAvailableForFreeClickHandler(