|
@@ -1,93 +1,76 @@
|
|
|
import { updateGroupModalPlanPricing } from '../../../../features/plans/group-plan-modal'
|
|
import { updateGroupModalPlanPricing } from '../../../../features/plans/group-plan-modal'
|
|
|
import '../../../../features/plans/plans-v2-group-plan-modal'
|
|
import '../../../../features/plans/plans-v2-group-plan-modal'
|
|
|
|
|
+import { createLocalizedGroupPlanPrice } from '../../../../features/plans/utils/group-plan-pricing'
|
|
|
import getMeta from '../../../../utils/meta'
|
|
import getMeta from '../../../../utils/meta'
|
|
|
|
|
|
|
|
-const MINIMUM_NUMBER_OF_LICENSES_EDUCATIONAL_DISCOUNT = 10
|
|
|
|
|
|
|
+const MINIMUM_LICENSE_SIZE_EDUCATIONAL_DISCOUNT = 10
|
|
|
|
|
|
|
|
export function updateMainGroupPlanPricing() {
|
|
export function updateMainGroupPlanPricing() {
|
|
|
- const groupPlans = getMeta('ol-groupPlans')
|
|
|
|
|
- const currencySymbols = getMeta('ol-currencySymbols')
|
|
|
|
|
- const currentCurrencyCode = getMeta('ol-recommendedCurrency')
|
|
|
|
|
|
|
+ const currency = getMeta('ol-recommendedCurrency')
|
|
|
|
|
|
|
|
const formEl = document.querySelector(
|
|
const formEl = document.querySelector(
|
|
|
'[data-ol-plans-v2-license-picker-form]'
|
|
'[data-ol-plans-v2-license-picker-form]'
|
|
|
)
|
|
)
|
|
|
- const numberOfLicenses = formEl.querySelector(
|
|
|
|
|
|
|
+ const licenseSize = formEl.querySelector(
|
|
|
'[data-ol-plans-v2-license-picker-select]'
|
|
'[data-ol-plans-v2-license-picker-select]'
|
|
|
).value
|
|
).value
|
|
|
- const currency = currentCurrencyCode
|
|
|
|
|
- const currencySymbol = currencySymbols[currency]
|
|
|
|
|
|
|
+
|
|
|
const usage = formEl.querySelector(
|
|
const usage = formEl.querySelector(
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
|
).checked
|
|
).checked
|
|
|
? 'educational'
|
|
? 'educational'
|
|
|
: 'enterprise'
|
|
: 'enterprise'
|
|
|
|
|
|
|
|
- function calculatePrice(plan) {
|
|
|
|
|
- const priceInCents =
|
|
|
|
|
- groupPlans[usage][plan][currency][numberOfLicenses].price_in_cents
|
|
|
|
|
- const priceInUnit = (priceInCents / 100).toFixed()
|
|
|
|
|
- const perUserPrice = (priceInCents / 100 / numberOfLicenses).toFixed(2)
|
|
|
|
|
-
|
|
|
|
|
- return { priceInUnit, perUserPrice }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
const {
|
|
const {
|
|
|
- priceInUnit: priceInUnitProfessional,
|
|
|
|
|
- perUserPrice: perUserPriceProfessional,
|
|
|
|
|
- } = calculatePrice('professional')
|
|
|
|
|
- let displayPriceProfessional = `${currencySymbol}${priceInUnitProfessional}`
|
|
|
|
|
- let displayPerUserPriceProfessional = `${currencySymbol}${perUserPriceProfessional}`
|
|
|
|
|
|
|
+ localizedPrice: localizedPriceProfessional,
|
|
|
|
|
+ localizedPerUserPrice: localizedPerUserPriceProfessional,
|
|
|
|
|
+ } = createLocalizedGroupPlanPrice({
|
|
|
|
|
+ plan: 'professional',
|
|
|
|
|
+ licenseSize,
|
|
|
|
|
+ currency,
|
|
|
|
|
+ usage,
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
|
- priceInUnit: priceInUnitCollaborator,
|
|
|
|
|
- perUserPrice: perUserPriceCollaborator,
|
|
|
|
|
- } = calculatePrice('collaborator')
|
|
|
|
|
- let displayPriceCollaborator = `${currencySymbol}${priceInUnitCollaborator}`
|
|
|
|
|
- let displayPerUserPriceCollaborator = `${currencySymbol}${perUserPriceCollaborator}`
|
|
|
|
|
-
|
|
|
|
|
- if (currencySymbol === 'kr') {
|
|
|
|
|
- displayPriceProfessional = `${priceInUnitProfessional} ${currencySymbol}`
|
|
|
|
|
- displayPerUserPriceProfessional = `${perUserPriceProfessional} ${currencySymbol}`
|
|
|
|
|
- displayPriceCollaborator = `${priceInUnitCollaborator} ${currencySymbol}`
|
|
|
|
|
- displayPerUserPriceCollaborator = `${perUserPriceCollaborator} ${currencySymbol}`
|
|
|
|
|
- } else if (currencySymbol === 'Fr') {
|
|
|
|
|
- displayPriceProfessional = `${currencySymbol} ${priceInUnitProfessional}`
|
|
|
|
|
- displayPerUserPriceProfessional = `${currencySymbol} ${perUserPriceProfessional}`
|
|
|
|
|
- displayPriceCollaborator = `${currencySymbol} ${priceInUnitCollaborator}`
|
|
|
|
|
- displayPerUserPriceCollaborator = `${currencySymbol} ${perUserPriceCollaborator}`
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ localizedPrice: localizedPriceCollaborator,
|
|
|
|
|
+ localizedPerUserPrice: localizedPerUserPriceCollaborator,
|
|
|
|
|
+ } = createLocalizedGroupPlanPrice({
|
|
|
|
|
+ plan: 'collaborator',
|
|
|
|
|
+ licenseSize,
|
|
|
|
|
+ currency,
|
|
|
|
|
+ usage,
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
document.querySelector(
|
|
document.querySelector(
|
|
|
'[data-ol-plans-v2-group-total-price="professional"]'
|
|
'[data-ol-plans-v2-group-total-price="professional"]'
|
|
|
- ).innerText = displayPriceProfessional
|
|
|
|
|
|
|
+ ).innerText = localizedPriceProfessional
|
|
|
|
|
+
|
|
|
document.querySelector(
|
|
document.querySelector(
|
|
|
- '[data-ol-plans-v2-group-total-price="collaborator"]'
|
|
|
|
|
- ).innerText = displayPriceCollaborator
|
|
|
|
|
|
|
+ '[data-ol-plans-v2-group-price-per-user="professional"]'
|
|
|
|
|
+ ).innerText = localizedPerUserPriceProfessional
|
|
|
|
|
|
|
|
document.querySelector(
|
|
document.querySelector(
|
|
|
- '[data-ol-plans-v2-group-price-per-user="collaborator"]'
|
|
|
|
|
- ).innerText = displayPerUserPriceCollaborator
|
|
|
|
|
|
|
+ '[data-ol-plans-v2-group-total-price="collaborator"]'
|
|
|
|
|
+ ).innerText = localizedPriceCollaborator
|
|
|
|
|
|
|
|
document.querySelector(
|
|
document.querySelector(
|
|
|
- '[data-ol-plans-v2-group-price-per-user="professional"]'
|
|
|
|
|
- ).innerText = displayPerUserPriceProfessional
|
|
|
|
|
|
|
+ '[data-ol-plans-v2-group-price-per-user="collaborator"]'
|
|
|
|
|
+ ).innerText = localizedPerUserPriceCollaborator
|
|
|
|
|
|
|
|
- // educational discount can only be activated if numberOfLicenses is >= 10
|
|
|
|
|
- const notEligibleForDiscount =
|
|
|
|
|
- numberOfLicenses < MINIMUM_NUMBER_OF_LICENSES_EDUCATIONAL_DISCOUNT
|
|
|
|
|
|
|
+ const notEligibleForEducationalDiscount =
|
|
|
|
|
+ licenseSize < MINIMUM_LICENSE_SIZE_EDUCATIONAL_DISCOUNT
|
|
|
|
|
|
|
|
formEl
|
|
formEl
|
|
|
.querySelector(
|
|
.querySelector(
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-label]'
|
|
'[data-ol-plans-v2-license-picker-educational-discount-label]'
|
|
|
)
|
|
)
|
|
|
- .classList.toggle('disabled', notEligibleForDiscount)
|
|
|
|
|
|
|
+ .classList.toggle('disabled', notEligibleForEducationalDiscount)
|
|
|
|
|
|
|
|
formEl.querySelector(
|
|
formEl.querySelector(
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
|
- ).disabled = notEligibleForDiscount
|
|
|
|
|
|
|
+ ).disabled = notEligibleForEducationalDiscount
|
|
|
|
|
|
|
|
- if (notEligibleForDiscount) {
|
|
|
|
|
|
|
+ if (notEligibleForEducationalDiscount) {
|
|
|
// force disable educational discount checkbox
|
|
// force disable educational discount checkbox
|
|
|
formEl.querySelector(
|
|
formEl.querySelector(
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|