2024-06-05 13:42:25 -04:00
|
|
|
import { GROUP_PLAN_MODAL_HASH } from '@/features/plans/group-plan-modal'
|
|
|
|
|
2024-05-28 12:48:29 -04:00
|
|
|
export function getViewInfoFromHash() {
|
2024-06-05 13:42:25 -04:00
|
|
|
const hashValue = window.location.hash.replace('#', '')
|
|
|
|
|
|
|
|
const groupPlanModalHashValue = GROUP_PLAN_MODAL_HASH.replace('#', '')
|
2024-05-28 12:48:29 -04:00
|
|
|
|
2024-06-05 13:42:25 -04:00
|
|
|
switch (hashValue) {
|
2024-05-28 12:48:29 -04:00
|
|
|
case 'individual-monthly':
|
|
|
|
return ['individual', 'monthly']
|
|
|
|
case 'individual-annual':
|
|
|
|
return ['individual', 'annual']
|
2024-06-05 13:42:25 -04:00
|
|
|
case groupPlanModalHashValue:
|
2024-05-28 12:48:29 -04:00
|
|
|
case 'group':
|
|
|
|
return ['group', 'annual']
|
|
|
|
case 'student-monthly':
|
|
|
|
return ['student', 'monthly']
|
|
|
|
case 'student-annual':
|
|
|
|
return ['student', 'annual']
|
|
|
|
default:
|
|
|
|
return ['individual', 'monthly']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {individual | group | student} viewTab
|
|
|
|
* @param {monthly | annual} period
|
|
|
|
*/
|
|
|
|
export function setHashFromViewTab(viewTab, period) {
|
|
|
|
const newHash = viewTab === 'group' ? 'group' : `${viewTab}-${period}`
|
2024-06-05 13:42:25 -04:00
|
|
|
if (window.location.hash.replace('#', '') !== newHash) {
|
2024-05-28 12:48:29 -04:00
|
|
|
window.location.hash = newHash
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is only for the students link in footer
|
|
|
|
export function handleForStudentsLinkInFooter() {
|
|
|
|
const links = document.querySelectorAll('[data-ol-for-students-link]')
|
|
|
|
|
|
|
|
links.forEach(function (link) {
|
|
|
|
link.addEventListener('click', function () {
|
|
|
|
if (window.location.pathname === '/user/subscription/plans') {
|
|
|
|
// reload location with the correct hash
|
|
|
|
const newURL =
|
|
|
|
'/user/subscription/plans?itm_referrer=footer-for-students#student-annual'
|
|
|
|
history.replaceState(null, '', newURL)
|
|
|
|
location.reload()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|