Skip to content

Commit

Permalink
Launchpad in My Home: Prevent redirection to Full-screen Launchpad (#…
Browse files Browse the repository at this point in the history
…98761)

* Launchpad in My Home: Prevent redirection to Full-screen Launchpad

* Scope variables according to their usage

---------

Co-authored-by: Paulo Trentin <[email protected]>
  • Loading branch information
zaguiini and paulopmt1 authored Jan 23, 2025
1 parent e40a0ec commit 1be05ea
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions client/my-sites/customer-home/controller.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from '@automattic/calypso-config';
import page from '@automattic/calypso-router';
import { fetchLaunchpad } from '@automattic/data-stores';
import { areLaunchpadTasksCompleted } from 'calypso/landing/stepper/declarative-flow/internals/steps-repository/launchpad/task-helper';
Expand Down Expand Up @@ -49,19 +50,38 @@ export async function maybeRedirect( context, next ) {
}

const siteId = getSelectedSiteId( state );
const site = getSelectedSite( state );
const isSiteLaunched = site?.launch_status === 'launched' || false;
let fetchPromise;

if ( isSiteOnWooExpressEcommerceTrial( state, siteId ) ) {
// Pre-fetch plugins and modules to avoid flashing content prior deciding whether to redirect.
fetchPromise = Promise.allSettled( [
await Promise.allSettled( [
context.store.dispatch( fetchSitePlugins( siteId ) ),
context.store.dispatch( fetchModuleList( siteId ) ),
] );

// Ecommerce Plan's Home redirects to WooCommerce Home.
// Temporary redirection until we create a dedicated Home for Ecommerce.
// We need to make sure that sites on the eCommerce plan actually have WooCommerce installed before we redirect to the WooCommerce Home
// So we need to trigger a fetch of site plugins
const siteUrl = getSiteUrl( state, siteId );
if ( siteUrl !== null ) {
const refetchedState = context.store.getState();
const installedWooCommercePlugin = getPluginOnSite( refetchedState, siteId, 'woocommerce' );
const isSSOEnabled = !! isJetpackModuleActive( refetchedState, siteId, 'sso' );
if ( isSSOEnabled && installedWooCommercePlugin && installedWooCommercePlugin.active ) {
window.location.replace( siteUrl + '/wp-admin/admin.php?page=wc-admin' );
return;
}
}
}

if ( config.isEnabled( 'home/launchpad-first' ) ) {
return next();
}

try {
const site = getSelectedSite( state );
const isSiteLaunched = site?.launch_status === 'launched' || false;

const {
launchpad_screen: launchpadScreenOption,
site_intent: siteIntentOption,
Expand Down Expand Up @@ -93,23 +113,5 @@ export async function maybeRedirect( context, next ) {
}
} catch ( error ) {}

// Ecommerce Plan's Home redirects to WooCommerce Home.
// Temporary redirection until we create a dedicated Home for Ecommerce.
if ( fetchPromise?.then ) {
// We need to make sure that sites on the eCommerce plan actually have WooCommerce installed before we redirect to the WooCommerce Home
// So we need to trigger a fetch of site plugins
fetchPromise.then( () => {
const siteUrl = getSiteUrl( state, siteId );
if ( siteUrl !== null ) {
const refetchedState = context.store.getState();
const installedWooCommercePlugin = getPluginOnSite( refetchedState, siteId, 'woocommerce' );
const isSSOEnabled = !! isJetpackModuleActive( refetchedState, siteId, 'sso' );
if ( isSSOEnabled && installedWooCommercePlugin && installedWooCommercePlugin.active ) {
window.location.replace( siteUrl + '/wp-admin/admin.php?page=wc-admin' );
}
}
} );
}

next();
}

0 comments on commit 1be05ea

Please sign in to comment.