Refactored client-side onboarding redirect logic. (#16026)

This commit is contained in:
Nick Taylor 2022-01-11 07:04:06 -05:00 committed by GitHub
parent 70a5a6b4b9
commit ed003d3ab4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,7 +8,6 @@ HTMLDocument.prototype.ready = new Promise((resolve) => {
return null;
});
// If localStorage.getItem('shouldRedirectToOnboarding') is not set, i.e. null, that means we should redirect.
function redirectableLocation() {
return ![
'/onboarding',
@ -61,18 +60,26 @@ document.ready.then(
}),
);
function shouldRedirectToOnboarding() {
// If the value is null in localStorage, that means we should redirect.
const shouldRedirect =
localStorage.getItem('shouldRedirectToOnboarding') ?? true;
return JSON.parse(shouldRedirect);
}
window.InstantClick.on('change', () => {
getUserDataAndCsrfToken()
.then(({ currentUser }) => {
if (
redirectableCreatorOnboardingLocation() &&
localStorage.getItem('shouldRedirectToOnboarding') === null &&
shouldRedirectToOnboarding() &&
onboardCreator(currentUser)
) {
window.location = `${window.location.origin}/admin/creator_settings/new?referrer=${window.location}`;
} else if (
redirectableLocation() &&
localStorage.getItem('shouldRedirectToOnboarding') === null &&
shouldRedirectToOnboarding() &&
!onboardingSkippable(currentUser)
) {
window.location = `${window.location.origin}/onboarding?referrer=${window.location}`;