plans-v2-group-plan-modal.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import './group-plan-modal'
  2. import { updateMainGroupPlanPricing } from '../../pages/user/subscription/plans-v2/plans-v2-group-plan'
  3. export function changePlansV2MainPageGroupData() {
  4. const mainPlansPageFormEl = document.querySelector(
  5. '[data-ol-plans-v2-license-picker-form]'
  6. )
  7. const mainPlansPageLicensePickerEl = mainPlansPageFormEl.querySelector(
  8. '[data-ol-plans-v2-license-picker-select]'
  9. )
  10. const mainPlansPageEducationalDiscountEl = mainPlansPageFormEl.querySelector(
  11. '[data-ol-plans-v2-license-picker-educational-discount-input]'
  12. )
  13. const groupPlanModalNumberOfLicenses = document.querySelector(
  14. '[data-ol-group-plan-modal] #size'
  15. ).value
  16. const educationalDiscountChecked = document.querySelector(
  17. '[data-ol-group-plan-modal] #usage'
  18. ).checked
  19. const educationalDiscountEnabled =
  20. educationalDiscountChecked && groupPlanModalNumberOfLicenses >= 10
  21. // update license picker on the main plans page
  22. mainPlansPageLicensePickerEl.value = groupPlanModalNumberOfLicenses
  23. // update educational discount checkbox on the main plans page
  24. //
  25. // extra note
  26. // for number of users < 10, there is a difference on the checkbox behaviour
  27. // between the group plan modal and the main plan page
  28. //
  29. // On the group plan modal, the checkbox button is not visually disabled for number of users < 10 (checkbox can still be clicked)
  30. // but the logic is disabled and there will be an extra text whether or not the discount is applied
  31. //
  32. // However, on the main group plan page, the checkbox button is visually disabled for number of users < 10 (checkbox can not be clicked)
  33. // Hence, there's a possibility that the checkbox on the group plan modal is checked, but the discount is not applied.
  34. // i.e user can still click the checkbox with number of users < 10. The price won't be discounted, but the checkbox is checked.
  35. if (groupPlanModalNumberOfLicenses >= 10) {
  36. mainPlansPageEducationalDiscountEl.checked = educationalDiscountEnabled
  37. } else {
  38. // The code below is for disabling the checkbox button on the main plan page for number of users <10
  39. // while still checking the educational discount
  40. if (educationalDiscountChecked) {
  41. mainPlansPageEducationalDiscountEl.checked = false
  42. }
  43. }
  44. updateMainGroupPlanPricing()
  45. }
  46. function hideCurrencyPicker() {
  47. document.querySelector('[data-ol-group-plan-form-currency]').hidden = true
  48. }
  49. document
  50. .querySelectorAll('[data-ol-group-plan-form] select')
  51. .forEach(el => el.addEventListener('change', changePlansV2MainPageGroupData))
  52. document
  53. .querySelectorAll('[data-ol-group-plan-form] input')
  54. .forEach(el => el.addEventListener('change', changePlansV2MainPageGroupData))
  55. const isGroupPlanModalAvailable = document.querySelector(
  56. '[data-ol-group-plan-modal]'
  57. )
  58. if (isGroupPlanModalAvailable) {
  59. hideCurrencyPicker()
  60. }