From c3314f57a925eae14583564a8bc055b0c2e3cb35 Mon Sep 17 00:00:00 2001 From: Paulo Trentin Date: Fri, 24 Jan 2025 17:03:12 -0300 Subject: [PATCH] Final improvements from PR review --- .../steps-repository/launchpad/index.tsx | 16 ++++++++-------- client/my-sites/customer-home/controller.jsx | 7 ++----- ...d-first.js => should-show-launchpad-first.ts} | 7 ++++--- 3 files changed, 14 insertions(+), 16 deletions(-) rename client/state/selectors/{should-show-launchpad-first.js => should-show-launchpad-first.ts} (59%) diff --git a/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/index.tsx b/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/index.tsx index f4bd976ac3239..b588be8e8a574 100644 --- a/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/index.tsx +++ b/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/index.tsx @@ -92,19 +92,19 @@ const Launchpad: Step = ( { navigation, flow }: LaunchpadProps ) => { } }, [ verifiedParam, translate, dispatch ] ); + // Avoid screen flickering when redirecting to other paths + if ( ! site?.options ) { + return null; + } + if ( launchpadScreenOption === 'skipped' ) { window.location.assign( `/home/${ siteSlug }` ); - return; + return null; } - if ( shouldShowLaunchpadFirst( site?.options?.site_creation_flow ) ) { + if ( shouldShowLaunchpadFirst( site ) ) { window.location.replace( `/home/${ siteSlug }` ); - return; - } - - // Avoid screen flickering when redirecting to other paths - if ( ! site?.options ) { - return; + return null; } return ( diff --git a/client/my-sites/customer-home/controller.jsx b/client/my-sites/customer-home/controller.jsx index ef8d7584e18b8..054e97141e772 100644 --- a/client/my-sites/customer-home/controller.jsx +++ b/client/my-sites/customer-home/controller.jsx @@ -29,10 +29,7 @@ export default async function renderHome( context, next ) { } context.primary = ( - + ); next(); @@ -82,7 +79,7 @@ export async function maybeRedirect( context, next ) { const site = getSelectedSite( state ); - if ( shouldShowLaunchpadFirst( site?.options?.site_creation_flow ) ) { + if ( shouldShowLaunchpadFirst( site ) ) { return next(); } diff --git a/client/state/selectors/should-show-launchpad-first.js b/client/state/selectors/should-show-launchpad-first.ts similarity index 59% rename from client/state/selectors/should-show-launchpad-first.js rename to client/state/selectors/should-show-launchpad-first.ts index ece5ca6d49776..03e95bb138326 100644 --- a/client/state/selectors/should-show-launchpad-first.js +++ b/client/state/selectors/should-show-launchpad-first.ts @@ -1,12 +1,13 @@ import config from '@automattic/calypso-config'; +import { SiteDetails } from '@automattic/data-stores'; /** * Determines if the launchpad should be shown first based on site createion flow - * @param {string|undefined} siteCreationFlow Site creation flow + * @param {SiteDetails|undefined} site Site object * @returns {boolean} Whether launchpad should be shown first */ -export const shouldShowLaunchpadFirst = ( siteCreationFlow ) => { - const wasSiteCreatedOnboardingFlow = siteCreationFlow === 'onboarding'; +export const shouldShowLaunchpadFirst = ( site: SiteDetails ) => { + const wasSiteCreatedOnboardingFlow = site?.options?.site_creation_flow === 'onboarding'; const isLaunchpadFirstEnabled = config.isEnabled( 'home/launchpad-first' ); return wasSiteCreatedOnboardingFlow && isLaunchpadFirstEnabled;