overleaf/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-subscription-button.js
M Fahru 487ff4f505 Improvement on form data sync between group plan modal and new plan page (#8003)
GitOrigin-RevId: 66a0a423fe48a8a8a7ddd292ba218cd5038dfdb1
2022-05-20 08:03:44 +00:00

43 lines
1.3 KiB
JavaScript

import { updateGroupModalPlanPricing } from '../../../../features/plans/group-plan-modal'
function changeGroupPlanModalRadioInputData(plan) {
const groupPlan = plan.split('_')[1]
const groupModalRadioInputEl = document.querySelector(
`[data-ol-group-plan-code="${groupPlan}"]`
)
groupModalRadioInputEl.checked = true
updateGroupModalPlanPricing()
}
function showGroupPlanModal(el) {
const plan = el.getAttribute('data-ol-start-new-subscription')
changeGroupPlanModalRadioInputData(plan)
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')
})
.on('hidden.bs.modal', function () {
history.replaceState(null, document.title, window.location.pathname)
})
modalEl.modal()
}
export function setUpGroupSubscriptionButtonAction() {
document.querySelectorAll('[data-ol-start-new-subscription]').forEach(el => {
const plan = el.getAttribute('data-ol-start-new-subscription')
if (plan === 'group_collaborator' || plan === 'group_professional') {
el.addEventListener('click', e => {
e.preventDefault()
showGroupPlanModal(el)
})
}
})
}