2022-05-19 07:57:36 -04:00
|
|
|
import { updateGroupModalPlanPricing } from '../../../../features/plans/group-plan-modal'
|
|
|
|
import '../../../../features/plans/plans-v2-group-plan-modal'
|
2022-07-07 09:36:25 -04:00
|
|
|
import { createLocalizedGroupPlanPrice } from '../../../../features/plans/utils/group-plan-pricing'
|
2022-05-12 07:38:02 -04:00
|
|
|
import getMeta from '../../../../utils/meta'
|
|
|
|
|
2022-07-07 09:36:25 -04:00
|
|
|
const MINIMUM_LICENSE_SIZE_EDUCATIONAL_DISCOUNT = 10
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2022-05-19 07:57:36 -04:00
|
|
|
export function updateMainGroupPlanPricing() {
|
2022-07-07 09:36:25 -04:00
|
|
|
const currency = getMeta('ol-recommendedCurrency')
|
2022-05-12 07:38:02 -04:00
|
|
|
|
|
|
|
const formEl = document.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-form]'
|
|
|
|
)
|
2022-07-07 09:36:25 -04:00
|
|
|
const licenseSize = formEl.querySelector(
|
2022-05-12 07:38:02 -04:00
|
|
|
'[data-ol-plans-v2-license-picker-select]'
|
|
|
|
).value
|
2022-07-07 09:36:25 -04:00
|
|
|
|
2022-05-12 07:38:02 -04:00
|
|
|
const usage = formEl.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
|
|
).checked
|
|
|
|
? 'educational'
|
|
|
|
: 'enterprise'
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
const {
|
2022-07-07 09:36:25 -04:00
|
|
|
localizedPrice: localizedPriceProfessional,
|
|
|
|
localizedPerUserPrice: localizedPerUserPriceProfessional,
|
|
|
|
} = createLocalizedGroupPlanPrice({
|
|
|
|
plan: 'professional',
|
|
|
|
licenseSize,
|
|
|
|
currency,
|
|
|
|
usage,
|
|
|
|
})
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
const {
|
2022-07-07 09:36:25 -04:00
|
|
|
localizedPrice: localizedPriceCollaborator,
|
|
|
|
localizedPerUserPrice: localizedPerUserPriceCollaborator,
|
|
|
|
} = createLocalizedGroupPlanPrice({
|
|
|
|
plan: 'collaborator',
|
|
|
|
licenseSize,
|
|
|
|
currency,
|
|
|
|
usage,
|
|
|
|
})
|
2022-05-12 07:38:02 -04:00
|
|
|
|
|
|
|
document.querySelector(
|
|
|
|
'[data-ol-plans-v2-group-total-price="professional"]'
|
2022-07-07 09:36:25 -04:00
|
|
|
).innerText = localizedPriceProfessional
|
|
|
|
|
2022-05-12 07:38:02 -04:00
|
|
|
document.querySelector(
|
2022-07-07 09:36:25 -04:00
|
|
|
'[data-ol-plans-v2-group-price-per-user="professional"]'
|
|
|
|
).innerText = localizedPerUserPriceProfessional
|
2022-05-12 07:38:02 -04:00
|
|
|
|
|
|
|
document.querySelector(
|
2022-07-07 09:36:25 -04:00
|
|
|
'[data-ol-plans-v2-group-total-price="collaborator"]'
|
|
|
|
).innerText = localizedPriceCollaborator
|
2022-05-12 07:38:02 -04:00
|
|
|
|
|
|
|
document.querySelector(
|
2022-07-07 09:36:25 -04:00
|
|
|
'[data-ol-plans-v2-group-price-per-user="collaborator"]'
|
|
|
|
).innerText = localizedPerUserPriceCollaborator
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2022-07-07 09:36:25 -04:00
|
|
|
const notEligibleForEducationalDiscount =
|
|
|
|
licenseSize < MINIMUM_LICENSE_SIZE_EDUCATIONAL_DISCOUNT
|
2022-06-22 08:22:11 -04:00
|
|
|
|
|
|
|
formEl
|
|
|
|
.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-label]'
|
|
|
|
)
|
2022-07-07 09:36:25 -04:00
|
|
|
.classList.toggle('disabled', notEligibleForEducationalDiscount)
|
2022-06-22 08:22:11 -04:00
|
|
|
|
|
|
|
formEl.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
2022-07-07 09:36:25 -04:00
|
|
|
).disabled = notEligibleForEducationalDiscount
|
2022-06-22 08:22:11 -04:00
|
|
|
|
2022-07-07 09:36:25 -04:00
|
|
|
if (notEligibleForEducationalDiscount) {
|
2022-06-22 08:22:11 -04:00
|
|
|
// force disable educational discount checkbox
|
2022-05-12 07:38:02 -04:00
|
|
|
formEl.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
|
|
).checked = false
|
|
|
|
}
|
2022-07-08 09:26:11 -04:00
|
|
|
|
|
|
|
changeNumberOfUsersInTableHead()
|
|
|
|
changeNumberOfUsersInFeatureTable()
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function changeGroupPlanModalNumberOfLicenses() {
|
|
|
|
const modalEl = document.querySelector('[data-ol-group-plan-modal]')
|
|
|
|
const numberOfLicenses = document.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-select]'
|
|
|
|
).value
|
|
|
|
|
|
|
|
const groupPlanModalLicensePickerEl = modalEl.querySelector('#size')
|
|
|
|
|
2022-05-19 07:57:36 -04:00
|
|
|
groupPlanModalLicensePickerEl.value = numberOfLicenses
|
|
|
|
updateGroupModalPlanPricing()
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function changeGroupPlanModalEducationalDiscount() {
|
|
|
|
const modalEl = document.querySelector('[data-ol-group-plan-modal]')
|
|
|
|
const groupPlanModalEducationalDiscountEl = modalEl.querySelector('#usage')
|
|
|
|
const educationalDiscountChecked = document.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
|
|
).checked
|
|
|
|
|
2022-05-19 07:57:36 -04:00
|
|
|
groupPlanModalEducationalDiscountEl.checked = educationalDiscountChecked
|
|
|
|
updateGroupModalPlanPricing()
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|
2022-07-08 09:26:11 -04:00
|
|
|
|
|
|
|
export function changeNumberOfUsersInFeatureTable() {
|
|
|
|
document
|
|
|
|
.querySelectorAll(
|
|
|
|
'[data-ol-plans-v2-table-cell-plan^="group"][data-ol-plans-v2-table-cell-feature="number_of_users"]'
|
|
|
|
)
|
|
|
|
.forEach(el => {
|
|
|
|
const licenseSize = document.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-select]'
|
|
|
|
).value
|
|
|
|
|
|
|
|
el.textContent = `${licenseSize} users`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export function changeNumberOfUsersInTableHead() {
|
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-plans-v2-table-th-group-license-size]')
|
|
|
|
.forEach(el => {
|
|
|
|
const licenseSize = el.getAttribute(
|
|
|
|
'data-ol-plans-v2-table-th-group-license-size'
|
|
|
|
)
|
|
|
|
const currentLicenseSize = document.querySelector(
|
|
|
|
'[data-ol-plans-v2-license-picker-select]'
|
|
|
|
).value
|
|
|
|
|
|
|
|
el.hidden = licenseSize !== currentLicenseSize
|
|
|
|
})
|
|
|
|
}
|