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 :/
This commit is contained in:
Julianna Tetreault 2021-12-07 06:47:42 -07:00 committed by GitHub
parent 8c1b1f1982
commit 00324c38e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
) {