mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
8157616f85
GitOrigin-RevId: 4e4629583c6e86bd2bc6165d123224734c133df7
81 lines
2.8 KiB
JavaScript
81 lines
2.8 KiB
JavaScript
import './group-plan-modal'
|
|
import getMeta from '../../utils/meta'
|
|
|
|
const NEW_PLANS_PAGE_VARIANT = 'new-plans-page'
|
|
|
|
export function checkIfGroupModalOpen() {
|
|
return window.location.hash.includes('groups')
|
|
}
|
|
|
|
export function changePlansV2MainPageGroupData() {
|
|
const mainPlansPageFormEl = document.querySelector(
|
|
'[data-ol-plans-v2-license-picker-form]'
|
|
)
|
|
const mainPlansPageLicensePickerEl = mainPlansPageFormEl.querySelector(
|
|
'[data-ol-plans-v2-license-picker-select]'
|
|
)
|
|
|
|
const mainPlansPageEducationalDiscountEl = mainPlansPageFormEl.querySelector(
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
)
|
|
|
|
const groupPlanModalNumberOfLicenses = document.querySelector(
|
|
'[data-ol-group-plan-modal] #size'
|
|
).value
|
|
|
|
const educationalDiscountChecked = document.querySelector(
|
|
'[data-ol-group-plan-modal] #usage'
|
|
).checked
|
|
|
|
const educationalDiscountEnabled =
|
|
educationalDiscountChecked && groupPlanModalNumberOfLicenses >= 10
|
|
|
|
if (checkIfGroupModalOpen()) {
|
|
// update license picker on the main plans page
|
|
mainPlansPageLicensePickerEl.value = groupPlanModalNumberOfLicenses
|
|
mainPlansPageLicensePickerEl.dispatchEvent(new Event('change'))
|
|
|
|
// update educational discount checkbox on the main plans page
|
|
if (groupPlanModalNumberOfLicenses >= 10) {
|
|
mainPlansPageEducationalDiscountEl.checked = educationalDiscountEnabled
|
|
mainPlansPageEducationalDiscountEl.dispatchEvent(new Event('change'))
|
|
} else {
|
|
if (educationalDiscountChecked) {
|
|
mainPlansPageEducationalDiscountEl.checked = false
|
|
mainPlansPageEducationalDiscountEl.dispatchEvent(new Event('change'))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function hideCurrencyPicker() {
|
|
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
|
|
.querySelectorAll('[data-ol-group-plan-form] select')
|
|
.forEach(el => el.addEventListener('change', changePlansV2MainPageGroupData))
|
|
document
|
|
.querySelectorAll('[data-ol-group-plan-form] input')
|
|
.forEach(el => el.addEventListener('change', changePlansV2MainPageGroupData))
|