2021-09-22 07:13:18 -04:00
|
|
|
import getMeta from '../../../utils/meta'
|
|
|
|
import { swapModal } from '../../utils/swapModal'
|
|
|
|
import * as eventTracking from '../../../infrastructure/event-tracking'
|
2022-07-07 09:36:25 -04:00
|
|
|
import { createLocalizedGroupPlanPrice } from '../utils/group-plan-pricing'
|
2021-09-22 07:13:18 -04:00
|
|
|
|
|
|
|
function getFormValues() {
|
|
|
|
const modalEl = document.querySelector('[data-ol-group-plan-modal]')
|
2022-01-10 05:23:05 -05:00
|
|
|
const planCode = modalEl.querySelector(
|
|
|
|
'input[name="plan_code"]:checked'
|
|
|
|
).value
|
2021-09-22 07:13:18 -04:00
|
|
|
const size = modalEl.querySelector('#size').value
|
|
|
|
const currency = modalEl.querySelector('#currency').value
|
2021-11-16 09:15:15 -05:00
|
|
|
const usage = modalEl.querySelector('#usage').checked
|
|
|
|
? 'educational'
|
|
|
|
: 'enterprise'
|
2021-09-22 07:13:18 -04:00
|
|
|
return { planCode, size, currency, usage }
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:57:36 -04:00
|
|
|
export function updateGroupModalPlanPricing() {
|
2021-09-22 07:13:18 -04:00
|
|
|
const modalEl = document.querySelector('[data-ol-group-plan-modal]')
|
|
|
|
const { planCode, size, currency, usage } = getFormValues()
|
|
|
|
|
2022-07-07 09:36:25 -04:00
|
|
|
const { localizedPrice, localizedPerUserPrice } =
|
|
|
|
createLocalizedGroupPlanPrice({
|
|
|
|
plan: planCode,
|
|
|
|
licenseSize: size,
|
|
|
|
currency,
|
|
|
|
usage,
|
|
|
|
})
|
2021-09-22 07:13:18 -04:00
|
|
|
|
|
|
|
modalEl.querySelectorAll('[data-ol-group-plan-plan-code]').forEach(el => {
|
|
|
|
el.hidden = el.getAttribute('data-ol-group-plan-plan-code') !== planCode
|
|
|
|
})
|
|
|
|
modalEl.querySelectorAll('[data-ol-group-plan-usage]').forEach(el => {
|
|
|
|
el.hidden = el.getAttribute('data-ol-group-plan-usage') !== usage
|
|
|
|
})
|
2022-01-10 05:23:05 -05:00
|
|
|
modalEl.querySelector('[data-ol-group-plan-display-price]').innerText =
|
2022-07-07 09:36:25 -04:00
|
|
|
localizedPrice
|
2023-07-18 05:22:15 -04:00
|
|
|
modalEl
|
|
|
|
.querySelectorAll('[data-ol-group-plan-price-per-user]')
|
|
|
|
.forEach(el => {
|
|
|
|
el.innerText = `${localizedPerUserPrice} ${el.getAttribute(
|
|
|
|
'data-ol-group-plan-price-per-user'
|
|
|
|
)}`
|
|
|
|
})
|
2021-11-16 09:15:15 -05:00
|
|
|
|
|
|
|
modalEl.querySelector('[data-ol-group-plan-educational-discount]').hidden =
|
|
|
|
usage !== 'educational'
|
|
|
|
|
|
|
|
modalEl.querySelector(
|
|
|
|
'[data-ol-group-plan-educational-discount-applied]'
|
|
|
|
).hidden = size < 10
|
|
|
|
|
|
|
|
modalEl.querySelector(
|
|
|
|
'[data-ol-group-plan-educational-discount-ineligible]'
|
|
|
|
).hidden = size >= 10
|
2021-09-22 07:13:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const modalEl = $('[data-ol-group-plan-modal]')
|
|
|
|
modalEl
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
const path = `${window.location.pathname}${window.location.search}`
|
|
|
|
history.replaceState(null, document.title, path + '#groups')
|
2023-11-24 11:05:56 -05:00
|
|
|
eventTracking.sendMB('form-submitted-groups-modal-open')
|
2021-09-22 07:13:18 -04:00
|
|
|
})
|
|
|
|
.on('hidden.bs.modal', function () {
|
2022-06-22 08:20:33 -04:00
|
|
|
const path = `${window.location.pathname}${window.location.search}`
|
|
|
|
history.replaceState(null, document.title, path)
|
2021-09-22 07:13:18 -04:00
|
|
|
})
|
|
|
|
|
2022-04-07 09:15:11 -04:00
|
|
|
function showGroupPlanModal() {
|
2021-09-22 07:13:18 -04:00
|
|
|
modalEl.modal()
|
|
|
|
eventTracking.send(
|
|
|
|
'subscription-funnel',
|
|
|
|
'plans-page',
|
|
|
|
'group-inquiry-potential'
|
2022-02-01 05:54:13 -05:00
|
|
|
) // deprecated by plans-page-click
|
2021-09-22 07:13:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-group-plan-form] select')
|
2022-05-19 07:57:36 -04:00
|
|
|
.forEach(el => el.addEventListener('change', updateGroupModalPlanPricing))
|
2021-11-16 09:15:15 -05:00
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-group-plan-form] input')
|
2022-05-19 07:57:36 -04:00
|
|
|
.forEach(el => el.addEventListener('change', updateGroupModalPlanPricing))
|
2021-09-22 07:13:18 -04:00
|
|
|
document.querySelectorAll('[data-ol-purchase-group-plan]').forEach(el =>
|
|
|
|
el.addEventListener('click', e => {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
const { planCode, size, currency, usage } = getFormValues()
|
|
|
|
const queryParams = new URLSearchParams(
|
|
|
|
Object.entries({
|
|
|
|
planCode: `group_${planCode}_${size}_${usage}`,
|
|
|
|
currency,
|
|
|
|
itm_campaign: 'groups',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
const itmContent = getMeta('ol-itm_content')
|
|
|
|
if (itmContent) {
|
|
|
|
queryParams.set('itm_content', itmContent)
|
|
|
|
}
|
2022-02-01 05:54:13 -05:00
|
|
|
eventTracking.sendMB('groups-modal-click', {
|
|
|
|
plan: planCode,
|
|
|
|
users: size,
|
2022-05-16 10:25:49 -04:00
|
|
|
currency,
|
2022-02-01 05:54:13 -05:00
|
|
|
type: usage,
|
|
|
|
})
|
2021-09-22 07:13:18 -04:00
|
|
|
const url = new URL('/user/subscription/new', window.origin)
|
|
|
|
url.search = queryParams.toString()
|
|
|
|
window.location = url.toString()
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
document.querySelectorAll('[data-ol-open-group-plan-modal]').forEach(el => {
|
2022-02-01 05:54:13 -05:00
|
|
|
const location = el.getAttribute('data-ol-location')
|
2021-09-22 07:13:18 -04:00
|
|
|
el.addEventListener('click', function (e) {
|
|
|
|
e.preventDefault()
|
2022-02-01 05:54:13 -05:00
|
|
|
eventTracking.sendMB('plans-page-click', {
|
|
|
|
button: 'group',
|
|
|
|
location,
|
2023-03-16 10:33:01 -04:00
|
|
|
'billing-period': 'annual',
|
2022-02-01 05:54:13 -05:00
|
|
|
})
|
2022-04-07 09:15:11 -04:00
|
|
|
showGroupPlanModal()
|
2021-09-22 07:13:18 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-open-contact-form-for-more-than-50-licenses]')
|
|
|
|
.forEach(el => {
|
|
|
|
el.addEventListener('click', function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
swapModal(
|
|
|
|
'[data-ol-group-plan-modal]',
|
|
|
|
'[data-ol-contact-form-modal="general"]'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-06-13 05:33:26 -04:00
|
|
|
const isGroupPlanModalAvailable = document.querySelector(
|
|
|
|
'[data-ol-group-plan-modal]'
|
|
|
|
)
|
|
|
|
|
|
|
|
if (isGroupPlanModalAvailable) {
|
|
|
|
updateGroupModalPlanPricing()
|
|
|
|
}
|
2021-09-22 07:13:18 -04:00
|
|
|
|
|
|
|
if (window.location.hash === '#groups') {
|
|
|
|
showGroupPlanModal()
|
|
|
|
}
|