overleaf/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-hash.js
M Fahru 5b29729e9b Merge pull request #18714 from overleaf/mf-fix-group-plan-modal-hash-plans-table
[web] Fix loading plans page with group plan modal hash (#groups) does not enable the group plan table

GitOrigin-RevId: acd2e683d8e8d3f2b3325c3745856fe27c96eed6
2024-06-06 08:05:10 +00:00

52 lines
1.5 KiB
JavaScript

import { GROUP_PLAN_MODAL_HASH } from '@/features/plans/group-plan-modal'
export function getViewInfoFromHash() {
const hashValue = window.location.hash.replace('#', '')
const groupPlanModalHashValue = GROUP_PLAN_MODAL_HASH.replace('#', '')
switch (hashValue) {
case 'individual-monthly':
return ['individual', 'monthly']
case 'individual-annual':
return ['individual', 'annual']
case groupPlanModalHashValue:
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}`
if (window.location.hash.replace('#', '') !== newHash) {
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()
}
})
})
}