overleaf/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-hash.js
M Fahru 69871fccbe Fix plans page hash does not get updated if no hash is on the URL
Example case: visit plans page via other pages, the hash will be empty initially, this commit will make sure hash is updated even though no initial hash exists.

GitOrigin-RevId: 411585111e8cf1b3eb803059ad4cf98ae4e69b19
2024-05-30 08:04:27 +00:00

47 lines
1.3 KiB
JavaScript

export function getViewInfoFromHash() {
const hash = window.location.hash.substring(1)
switch (hash) {
case 'individual-monthly':
return ['individual', 'monthly']
case 'individual-annual':
return ['individual', 'annual']
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.substring(1) !== 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()
}
})
})
}