Explorar el Código

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
M Fahru hace 3 años
padre
commit
8120d52de1

+ 1 - 1
services/web/app/views/layout/fat-footer.pug

@@ -54,7 +54,7 @@ footer.fat-footer.hidden-print
 					li
 					li
 						a(href="/for/universities") #{translate('for_universities')}
 						a(href="/for/universities") #{translate('for_universities')}
 					li
 					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
 				.footer-section-heading #{translate('get_involved')}
 				.footer-section-heading #{translate('get_involved')}

+ 18 - 1
services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-main.js

@@ -170,8 +170,25 @@ function selectViewFromHash() {
         // set annual as the default
         // set annual as the default
         currentMonthlyAnnualSwitchValue = 'annual'
         currentMonthlyAnnualSwitchValue = 'annual'
         selectTab(view)
         selectTab(view)
+
         // clear the hash so it doesn't persist when switching plans
         // 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 {
   } catch {