Improvement on form data sync between group plan modal and new plan page (#8003)

GitOrigin-RevId: 66a0a423fe48a8a8a7ddd292ba218cd5038dfdb1
This commit is contained in:
M Fahru 2022-05-19 07:57:36 -04:00 committed by Copybot
parent 1c0a9dae72
commit 487ff4f505
6 changed files with 62 additions and 83 deletions

View file

@ -45,20 +45,6 @@ async function plansPage(req, res) {
} }
return defaultValue return defaultValue
} }
let defaultGroupPlanModalCurrency = 'USD'
if (validGroupPlanModalOptions.currency.includes(recommendedCurrency)) {
defaultGroupPlanModalCurrency = recommendedCurrency
}
const groupPlanModalDefaults = {
plan_code: getDefault('plan', 'plan_code', 'collaborator'),
size: getDefault('number', 'size', '10'),
currency: getDefault('currency', 'currency', defaultGroupPlanModalCurrency),
usage: getDefault('usage', 'usage', 'enterprise'),
}
AnalyticsManager.recordEventForSession(req.session, 'plans-page-view')
const newPlansPageAssignmentV2 = const newPlansPageAssignmentV2 =
await SplitTestHandler.promises.getAssignment( await SplitTestHandler.promises.getAssignment(
req, req,
@ -70,6 +56,19 @@ async function plansPage(req, res) {
newPlansPageAssignmentV2 && newPlansPageAssignmentV2 &&
newPlansPageAssignmentV2.variant === 'new-plans-page' newPlansPageAssignmentV2.variant === 'new-plans-page'
let defaultGroupPlanModalCurrency = 'USD'
if (validGroupPlanModalOptions.currency.includes(recommendedCurrency)) {
defaultGroupPlanModalCurrency = recommendedCurrency
}
const groupPlanModalDefaults = {
plan_code: getDefault('plan', 'plan_code', 'collaborator'),
size: getDefault('number', 'size', newPlansPageVariantV2 ? '2' : '10'),
currency: getDefault('currency', 'currency', defaultGroupPlanModalCurrency),
usage: getDefault('usage', 'usage', 'enterprise'),
}
AnalyticsManager.recordEventForSession(req.session, 'plans-page-view')
const standardPlanNameAssignment = const standardPlanNameAssignment =
await SplitTestHandler.promises.getAssignment( await SplitTestHandler.promises.getAssignment(
req, req,

View file

@ -15,7 +15,7 @@ function getFormValues() {
return { planCode, size, currency, usage } return { planCode, size, currency, usage }
} }
function updateGroupPlanView() { export function updateGroupModalPlanPricing() {
const groupPlans = getMeta('ol-groupPlans') const groupPlans = getMeta('ol-groupPlans')
const currencySymbols = getMeta('ol-currencySymbols') const currencySymbols = getMeta('ol-currencySymbols')
@ -74,10 +74,10 @@ function showGroupPlanModal() {
document document
.querySelectorAll('[data-ol-group-plan-form] select') .querySelectorAll('[data-ol-group-plan-form] select')
.forEach(el => el.addEventListener('change', updateGroupPlanView)) .forEach(el => el.addEventListener('change', updateGroupModalPlanPricing))
document document
.querySelectorAll('[data-ol-group-plan-form] input') .querySelectorAll('[data-ol-group-plan-form] input')
.forEach(el => el.addEventListener('change', updateGroupPlanView)) .forEach(el => el.addEventListener('change', updateGroupModalPlanPricing))
document.querySelectorAll('[data-ol-purchase-group-plan]').forEach(el => document.querySelectorAll('[data-ol-purchase-group-plan]').forEach(el =>
el.addEventListener('click', e => { el.addEventListener('click', e => {
e.preventDefault() e.preventDefault()
@ -131,7 +131,7 @@ document
}) })
}) })
updateGroupPlanView() updateGroupModalPlanPricing()
if (window.location.hash === '#groups') { if (window.location.hash === '#groups') {
showGroupPlanModal() showGroupPlanModal()

View file

@ -1,11 +1,5 @@
import './group-plan-modal' import './group-plan-modal'
import getMeta from '../../utils/meta' import { updateMainGroupPlanPricing } from '../../pages/user/subscription/plans-v2/plans-v2-group-plan'
const NEW_PLANS_PAGE_VARIANT = 'new-plans-page'
export function checkIfGroupModalOpen() {
return window.location.hash.includes('groups')
}
export function changePlansV2MainPageGroupData() { export function changePlansV2MainPageGroupData() {
const mainPlansPageFormEl = document.querySelector( const mainPlansPageFormEl = document.querySelector(
@ -30,52 +24,43 @@ export function changePlansV2MainPageGroupData() {
const educationalDiscountEnabled = const educationalDiscountEnabled =
educationalDiscountChecked && groupPlanModalNumberOfLicenses >= 10 educationalDiscountChecked && groupPlanModalNumberOfLicenses >= 10
if (checkIfGroupModalOpen()) {
// update license picker on the main plans page // update license picker on the main plans page
mainPlansPageLicensePickerEl.value = groupPlanModalNumberOfLicenses mainPlansPageLicensePickerEl.value = groupPlanModalNumberOfLicenses
mainPlansPageLicensePickerEl.dispatchEvent(new Event('change'))
// update educational discount checkbox on the main plans page // update educational discount checkbox on the main plans page
//
// extra note
// for number of users < 10, there is a difference on the checkbox behaviour
// between the group plan modal and the main plan page
//
// On the group plan modal, the checkbox button is not visually disabled for number of users < 10 (checkbox can still be clicked)
// but the logic is disabled and there will be an extra text whether or not the discount is applied
//
// However, on the main group plan page, the checkbox button is visually disabled for number of users < 10 (checkbox can not be clicked)
// Hence, there's a possibility that the checkbox on the group plan modal is checked, but the discount is not applied.
// i.e user can still click the checkbox with number of users < 10. The price won't be discounted, but the checkbox is checked.
if (groupPlanModalNumberOfLicenses >= 10) { if (groupPlanModalNumberOfLicenses >= 10) {
mainPlansPageEducationalDiscountEl.checked = educationalDiscountEnabled mainPlansPageEducationalDiscountEl.checked = educationalDiscountEnabled
mainPlansPageEducationalDiscountEl.dispatchEvent(new Event('change'))
} else { } else {
// The code below is for disabling the checkbox button on the main plan page for number of users <10
// while still checking the educational discount
if (educationalDiscountChecked) { if (educationalDiscountChecked) {
mainPlansPageEducationalDiscountEl.checked = false mainPlansPageEducationalDiscountEl.checked = false
mainPlansPageEducationalDiscountEl.dispatchEvent(new Event('change'))
}
} }
} }
updateMainGroupPlanPricing()
} }
function hideCurrencyPicker() { function hideCurrencyPicker() {
document.querySelector('[data-ol-group-plan-form-currency]').hidden = true document.querySelector('[data-ol-group-plan-form-currency]').hidden = true
} }
const plansPageVariant =
getMeta('ol-splitTestVariants')?.['plans-page-layout-v2'] ?? 'default'
if (plansPageVariant === NEW_PLANS_PAGE_VARIANT) {
hideCurrencyPicker()
// we need to sync the form data between group plan modal
// and the main plan page
document.querySelectorAll('[data-ol-group-plan-code]').forEach(el => {
// listening to new CustomEvent 'showmodal'
// we do this to check whether user clicks the "Standard (Collaborator)" plan or the "Professional" plan
// and the radio button on the group plan modal will then be 'checked' accordingly
el.addEventListener('showmodal', () => {
if (!checkIfGroupModalOpen()) {
el.checked = true
el.dispatchEvent(new Event('change'))
}
})
})
}
document document
.querySelectorAll('[data-ol-group-plan-form] select') .querySelectorAll('[data-ol-group-plan-form] select')
.forEach(el => el.addEventListener('change', changePlansV2MainPageGroupData)) .forEach(el => el.addEventListener('change', changePlansV2MainPageGroupData))
document document
.querySelectorAll('[data-ol-group-plan-form] input') .querySelectorAll('[data-ol-group-plan-form] input')
.forEach(el => el.addEventListener('change', changePlansV2MainPageGroupData)) .forEach(el => el.addEventListener('change', changePlansV2MainPageGroupData))
hideCurrencyPicker()

View file

@ -1,9 +1,10 @@
import { checkIfGroupModalOpen } from '../../../../features/plans/plans-v2-group-plan-modal' import { updateGroupModalPlanPricing } from '../../../../features/plans/group-plan-modal'
import '../../../../features/plans/plans-v2-group-plan-modal'
import getMeta from '../../../../utils/meta' import getMeta from '../../../../utils/meta'
const MINIMUM_NUMBER_OF_LICENSES_EDUCATIONAL_DISCOUNT = 10 const MINIMUM_NUMBER_OF_LICENSES_EDUCATIONAL_DISCOUNT = 10
export function updateGroupPricing() { export function updateMainGroupPlanPricing() {
const groupPlans = getMeta('ol-groupPlans') const groupPlans = getMeta('ol-groupPlans')
const currencySymbols = getMeta('ol-currencySymbols') const currencySymbols = getMeta('ol-currencySymbols')
const currentCurrencyCode = getMeta('ol-recommendedCurrency') const currentCurrencyCode = getMeta('ol-recommendedCurrency')
@ -116,10 +117,8 @@ export function changeGroupPlanModalNumberOfLicenses() {
const groupPlanModalLicensePickerEl = modalEl.querySelector('#size') const groupPlanModalLicensePickerEl = modalEl.querySelector('#size')
if (!checkIfGroupModalOpen()) {
groupPlanModalLicensePickerEl.value = numberOfLicenses groupPlanModalLicensePickerEl.value = numberOfLicenses
groupPlanModalLicensePickerEl.dispatchEvent(new Event('change')) updateGroupModalPlanPricing()
}
} }
export function changeGroupPlanModalEducationalDiscount() { export function changeGroupPlanModalEducationalDiscount() {
@ -129,8 +128,6 @@ export function changeGroupPlanModalEducationalDiscount() {
'[data-ol-plans-v2-license-picker-educational-discount-input]' '[data-ol-plans-v2-license-picker-educational-discount-input]'
).checked ).checked
if (!checkIfGroupModalOpen()) {
groupPlanModalEducationalDiscountEl.checked = educationalDiscountChecked groupPlanModalEducationalDiscountEl.checked = educationalDiscountChecked
groupPlanModalEducationalDiscountEl.dispatchEvent(new Event('change')) updateGroupModalPlanPricing()
}
} }

View file

@ -21,10 +21,9 @@ import {
changeGroupPlanModalNumberOfLicenses, changeGroupPlanModalNumberOfLicenses,
hideGroupPlansLicensePicker, hideGroupPlansLicensePicker,
showGroupPlansLicensePicker, showGroupPlansLicensePicker,
updateGroupPricing, updateMainGroupPlanPricing,
} from './plans-v2-group-plan' } from './plans-v2-group-plan'
import { setUpGroupSubscriptionButtonAction } from './plans-v2-subscription-button' import { setUpGroupSubscriptionButtonAction } from './plans-v2-subscription-button'
import { checkIfGroupModalOpen } from '../../../../features/plans/plans-v2-group-plan-modal'
import { updateLinkTargets } from '../plans' import { updateLinkTargets } from '../plans'
function selectTab(viewTab) { function selectTab(viewTab) {
@ -48,7 +47,7 @@ function selectTab(viewTab) {
if (viewTab === 'group') { if (viewTab === 'group') {
disableMonthlyAnnualSwitching() disableMonthlyAnnualSwitching()
hideMonthlyAnnualTooltip() hideMonthlyAnnualTooltip()
updateGroupPricing() updateMainGroupPlanPricing()
underlineAnnualText() underlineAnnualText()
showGroupPlansLicensePicker() showGroupPlansLicensePicker()
hideMonthlyAnnualSwitchOnSmallScreen() hideMonthlyAnnualSwitchOnSmallScreen()
@ -81,10 +80,8 @@ function setUpGroupPlanPricingChange() {
.querySelectorAll('[data-ol-plans-v2-license-picker-select]') .querySelectorAll('[data-ol-plans-v2-license-picker-select]')
.forEach(el => { .forEach(el => {
el.addEventListener('change', () => { el.addEventListener('change', () => {
updateGroupPricing() updateMainGroupPlanPricing()
if (!checkIfGroupModalOpen()) {
changeGroupPlanModalNumberOfLicenses() changeGroupPlanModalNumberOfLicenses()
}
}) })
}) })
@ -94,10 +91,8 @@ function setUpGroupPlanPricingChange() {
) )
.forEach(el => .forEach(el =>
el.addEventListener('change', () => { el.addEventListener('change', () => {
updateGroupPricing() updateMainGroupPlanPricing()
if (!checkIfGroupModalOpen()) {
changeGroupPlanModalEducationalDiscount() changeGroupPlanModalEducationalDiscount()
}
}) })
) )
} }

View file

@ -1,17 +1,20 @@
function sendShowModalEvent(plan) { import { updateGroupModalPlanPricing } from '../../../../features/plans/group-plan-modal'
function changeGroupPlanModalRadioInputData(plan) {
const groupPlan = plan.split('_')[1] const groupPlan = plan.split('_')[1]
const groupModalRadioInputEl = document.querySelector( const groupModalRadioInputEl = document.querySelector(
`[data-ol-group-plan-code="${groupPlan}"]` `[data-ol-group-plan-code="${groupPlan}"]`
) )
groupModalRadioInputEl.dispatchEvent(new CustomEvent('showmodal')) groupModalRadioInputEl.checked = true
updateGroupModalPlanPricing()
} }
function showGroupPlanModal(el) { function showGroupPlanModal(el) {
const plan = el.getAttribute('data-ol-start-new-subscription') const plan = el.getAttribute('data-ol-start-new-subscription')
sendShowModalEvent(plan) changeGroupPlanModalRadioInputData(plan)
const modalEl = $('[data-ol-group-plan-modal]') const modalEl = $('[data-ol-group-plan-modal]')
modalEl modalEl