From 8fe46feffb08d25758c8dc1992801edc1a6db3be Mon Sep 17 00:00:00 2001 From: Jessica Lawshe <5312836+lawshe@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:19:59 -0500 Subject: [PATCH] Merge pull request #18713 from overleaf/jel-group-plan-modal-defaults [web] Move group modal defaults for plans page to function GitOrigin-RevId: 0ebce884f9e984b50318742765b7a768f259a8db --- .../Subscription/SubscriptionController.js | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index 6d3811bfff..8bbb8eace1 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -32,6 +32,28 @@ const validGroupPlanModalOptions = { usage: groupPlanModalOptions.usages.map(item => item.code), } +function _getGroupPlanModalDefaults(req, currency) { + function getDefault(param, category, defaultValue) { + const v = req.query && req.query[param] + if (v && validGroupPlanModalOptions[category].includes(v)) { + return v + } + return defaultValue + } + + let defaultGroupPlanModalCurrency = 'USD' + if (validGroupPlanModalOptions.currency.includes(currency)) { + defaultGroupPlanModalCurrency = currency + } + + return { + plan_code: getDefault('plan', 'plan_code', 'collaborator'), + size: getDefault('number', 'size', '2'), + currency: getDefault('currency', 'currency', defaultGroupPlanModalCurrency), + usage: getDefault('usage', 'usage', 'enterprise'), + } +} + async function plansPage(req, res) { const websiteRedesignPlansAssignment = await SplitTestHandler.promises.getAssignment( @@ -58,26 +80,10 @@ async function plansPage(req, res) { } = await _getRecommendedCurrency(req, res) const latamCountryBannerDetails = await getLatamCountryBannerDetails(req, res) - function getDefault(param, category, defaultValue) { - const v = req.query && req.query[param] - if (v && validGroupPlanModalOptions[category].includes(v)) { - return v - } - return defaultValue - } + const groupPlanModalDefaults = _getGroupPlanModalDefaults(req, currency) const currentView = 'annual' - let defaultGroupPlanModalCurrency = 'USD' - if (validGroupPlanModalOptions.currency.includes(currency)) { - defaultGroupPlanModalCurrency = currency - } - const groupPlanModalDefaults = { - plan_code: getDefault('plan', 'plan_code', 'collaborator'), - size: getDefault('number', 'size', '2'), - currency: getDefault('currency', 'currency', defaultGroupPlanModalCurrency), - usage: getDefault('usage', 'usage', 'enterprise'), - } const plansPageViewSegmentation = { currency: recommendedCurrency, countryCode,