From 8120d52de162a7df68b2233bbf3caf6016f4cd8f Mon Sep 17 00:00:00 2001 From: M Fahru Date: Tue, 6 Jun 2023 09:43:43 -0700 Subject: [PATCH] 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 --- services/web/app/views/layout/fat-footer.pug | 2 +- .../subscription/plans-v2/plans-v2-main.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/services/web/app/views/layout/fat-footer.pug b/services/web/app/views/layout/fat-footer.pug index 99dcdf49e6..0e377affcd 100644 --- a/services/web/app/views/layout/fat-footer.pug +++ b/services/web/app/views/layout/fat-footer.pug @@ -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')} diff --git a/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-main.js b/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-main.js index 0e7940ee00..e2acdba975 100644 --- a/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-main.js +++ b/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-main.js @@ -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 {