Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launchpad.- Update mayberedirect launchpad option retrieval #74365

Merged
29 changes: 4 additions & 25 deletions client/my-sites/customer-home/controller.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { isEcommerce } from '@automattic/calypso-products/src';
import page from 'page';
import { fetchLaunchpad } from 'calypso/data/sites/use-launchpad';
import { getQueryArgs } from 'calypso/lib/query-args';
import { fetchSitePlugins } from 'calypso/state/plugins/installed/actions';
import { getPluginOnSite } from 'calypso/state/plugins/installed/selectors';
import { requestSite } from 'calypso/state/sites/actions';
import {
canCurrentUserUseCustomerHome,
getSiteOptions,
getSiteUrl,
getSitePlan,
} from 'calypso/state/sites/selectors';
Expand Down Expand Up @@ -38,34 +37,14 @@ export async function maybeRedirect( context, next ) {
}

const siteId = getSelectedSiteId( state );
const maybeStalelaunchpadScreenOption = getSiteOptions( state, siteId )?.launchpad_screen;
const { launchpad_screen, site_intent } = await fetchLaunchpad( slug );

// We need the latest site info to determine if a user should be redirected to Launchpad.
// As a result, we can't use locally cached data, which might think that Launchpad is
// still enabled when, in reality, the final tasks have been completed and everything is
// disabled. Because of this, we refetch site information and limit traffic by scoping down
// requests to launchpad enabled sites.
// See https://cylonp2.wordpress.com/2022/09/19/question-about-infinite-redirect/#comment-1731
if (
( maybeStalelaunchpadScreenOption && maybeStalelaunchpadScreenOption === 'full' ) ||
getQueryArgs()?.showLaunchpad === 'true'
) {
await context.store.dispatch( requestSite( siteId ) );
}

const refetchedOptions = getSiteOptions( context.store.getState(), siteId );
const shouldRedirectToLaunchpad =
refetchedOptions?.launchpad_screen === 'full' &&
// Temporary hack/band-aid to resolve a stale issue with atomic that the requestSite
// dispatch above doesnt always seem to resolve.
getQueryArgs()?.launchpadComplete !== 'true';

if ( shouldRedirectToLaunchpad ) {
if ( launchpad_screen === 'full' ) {
// The new stepper launchpad onboarding flow isn't registered within the "page"
// client-side router, so page.redirect won't work. We need to use the
// traditional window.location Web API.
const verifiedParam = getQueryArgs()?.verified;
redirectToLaunchpad( slug, refetchedOptions?.site_intent, verifiedParam );
redirectToLaunchpad( slug, site_intent, verifiedParam );
return;
}

Expand Down