From 00324c38e6b5ebd0e217785fb7861bb3f8656005 Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Tue, 7 Dec 2021 06:47:42 -0700 Subject: [PATCH] Pulls Creator Onboarding Redirect Links Into a Creator Onboarding-Specific Function (#15654) * Pulls Creator Onboarding redirect links out into own function * Adds all pathnames to redirectableCreatorOnbboardingLocation() * Uses Array.proptypes.includes() in onboardingRedirectCheck.jsx * Adds back removed pathname from redirectableLocation * Refactor redirectableCreatorOnboardingLocation() * Adds back code changes that were reverted at some point :/ --- .../packs/onboardingRedirectCheck.jsx | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/javascript/packs/onboardingRedirectCheck.jsx b/app/javascript/packs/onboardingRedirectCheck.jsx index c96ffd51c..f0aabaef1 100644 --- a/app/javascript/packs/onboardingRedirectCheck.jsx +++ b/app/javascript/packs/onboardingRedirectCheck.jsx @@ -10,13 +10,18 @@ HTMLDocument.prototype.ready = new Promise((resolve) => { // If localStorage.getItem('shouldRedirectToOnboarding') is not set, i.e. null, that means we should redirect. function redirectableLocation() { + return ![ + '/onboarding', + '/signout_confirm', + '/privacy', + '/admin/creator_settings/new', + ].includes(window.location.pathname); +} + +function redirectableCreatorOnboardingLocation() { return ( - window.location.pathname !== '/onboarding' && - window.location.pathname !== '/signout_confirm' && - window.location.pathname !== '/privacy' && - window.location.pathname !== '/code-of-conduct' && - window.location.pathname !== '/terms' && - window.location.pathname !== '/admin/creator_settings/new' + redirectableLocation() && + !['/code-of-conduct', '/terms'].includes(window.location.pathname) ); } @@ -42,8 +47,10 @@ document.ready.then( window.currentUser = currentUser; window.csrfToken = csrfToken; - if (redirectableLocation() && onboardCreator(currentUser)) { - window.location = `${window.location.origin}/admin/creator_settings/new?referrer=${window.location}`; + if (onboardCreator(currentUser)) { + if (redirectableCreatorOnboardingLocation()) { + window.location = `${window.location.origin}/admin/creator_settings/new?referrer=${window.location}`; + } } else if (redirectableLocation() && !onboardingSkippable(currentUser)) { window.location = `${window.location.origin}/onboarding?referrer=${window.location}`; } @@ -58,7 +65,7 @@ window.InstantClick.on('change', () => { getUserDataAndCsrfToken() .then(({ currentUser }) => { if ( - redirectableLocation() && + redirectableCreatorOnboardingLocation() && localStorage.getItem('shouldRedirectToOnboarding') === null && onboardCreator(currentUser) ) {