docbrown/app/javascript/packs/onboardingRedirectCheck.jsx
Julianna Tetreault 8d00e27b69
Remove Creator Onboarding Feature Flags from Codebase (#15982)
* Removes FeatureFlag.enabled?(:creator_onboarding) from codebase

* Removes FeatureFlag.enabled?(:creator_onboarding) from specs

* Further cleanup, removal, and spec fixes

* Fixes the user_request_confirmation_spec.rb

* Reverts change to confirmation email button

* Revert revert after looking at designs again :(

* Removes redundant logo_png field from config + fixes test

* Rewords an expectation in user_uses_the_editor_spec.rb

* Revert removal of logo_png from Config images

* Removes CSS class from user_uses_the_editor_spec.rb

* Removes test from user_uses_the_editor_sepc.rb

* Removes unnecessary else from _logo.html.erb

* Adds back removed system spec

* Removes SVG-related code from _logo.html.erb

* Removes AsyncInfoController#use_creator_onboarding

* Fixes spec failues due to removed code

* Removes svg-related code (that I thought I removed already :/ )

* Re-removes FeatureFlag and logo_svg from _images.html.erb

* Remove newest instances of FeatureFlag(:creator_onboarding)

* remove instances where we use the creator_onboarding field from the base_data

* fix: redirect to the correct path in the reguistrations controller based on whether the user is a creator or not

Co-authored-by: Ridhwana <ridhwana.khan16@gmail.com>
2022-01-31 11:30:43 -07:00

90 lines
2.6 KiB
JavaScript

import { getUserDataAndCsrfToken } from '@utilities/getUserDataAndCsrfToken';
HTMLDocument.prototype.ready = new Promise((resolve) => {
if (document.readyState !== 'loading') {
return resolve();
}
document.addEventListener('DOMContentLoaded', () => resolve());
return null;
});
function redirectableLocation() {
return ![
'/onboarding',
'/signout_confirm',
'/privacy',
'/admin/creator_settings/new',
].includes(window.location.pathname);
}
function redirectableCreatorOnboardingLocation() {
return (
redirectableLocation() &&
!['/code-of-conduct', '/terms'].includes(window.location.pathname)
);
}
function onboardingSkippable(currentUser) {
return (
currentUser.saw_onboarding &&
currentUser.checked_code_of_conduct &&
currentUser.checked_terms_and_conditions
);
}
function onboardCreator(currentUser) {
return (
document.body.dataset.creator === 'true' && !currentUser.saw_onboarding
);
}
document.ready.then(
getUserDataAndCsrfToken()
.then(({ currentUser, csrfToken }) => {
window.currentUser = currentUser;
window.csrfToken = csrfToken;
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}`;
}
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error('Error getting user and CSRF Token', error);
}),
);
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() &&
shouldRedirectToOnboarding() &&
onboardCreator(currentUser)
) {
window.location = `${window.location.origin}/admin/creator_settings/new?referrer=${window.location}`;
} else if (
redirectableLocation() &&
shouldRedirectToOnboarding() &&
!onboardingSkippable(currentUser)
) {
window.location = `${window.location.origin}/onboarding?referrer=${window.location}`;
}
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error('Error getting user and CSRF Token', error);
});
});