Fix "For students" link in footer isn't working properly (#13296)

* Fix "For student" link in footer isn't working because of hash being placed before querystring

* add scroll to top behaviour if "For students" link is accessed on the plans page

* Add an extra delay to make sure computation is finished before performing scroll to top behaviour

GitOrigin-RevId: 46b906271223267bc47ffcd781c25dc03f23a8e7
This commit is contained in:
M Fahru 2023-06-06 09:43:43 -07:00 committed by Copybot
parent 7bbf7baf03
commit 8120d52de1
2 changed files with 19 additions and 2 deletions

View file

@ -54,7 +54,7 @@ footer.fat-footer.hidden-print
li
a(href="/for/universities") #{translate('for_universities')}
li
a(href="/user/subscription/plans#view=student?itm_referrer=footer-for-students") #{translate('for_students')}
a(href="/user/subscription/plans?itm_referrer=footer-for-students#view=student") #{translate('for_students')}
.footer-section
.footer-section-heading #{translate('get_involved')}

View file

@ -170,8 +170,25 @@ function selectViewFromHash() {
// set annual as the default
currentMonthlyAnnualSwitchValue = 'annual'
selectTab(view)
// clear the hash so it doesn't persist when switching plans
window.location.hash = ''
const currentURL = window.location.pathname + window.location.search
history.replaceState('', document.title, currentURL)
// Add a small delay since it seems the scroll won't behave correctly on this scenario:
// 1. Open plans page
// 2. Click on "Group Plans"
// 3. Scroll down to footer
// 4. Click "For students" link
//
// I assume this is happening because the `selectTab` function above is doing a lot
// of computation to change the view and it somehow prevents the `window.scrollTo` command
// to behave correctly.
const SCROLL_TO_TOP_DELAY = 50
window.setTimeout(() => {
window.scrollTo({ top: 0, behavior: 'smooth' })
}, SCROLL_TO_TOP_DELAY)
}
}
} catch {