From 8863e5cdafa87c929d48294cbb0a6d813eac2d3a Mon Sep 17 00:00:00 2001 From: Paulo Marcos Trentin Date: Sun, 2 Feb 2025 18:06:42 -0300 Subject: [PATCH] Move user to /plans page when exiting and clearing cart from checkout (#99174) * Fix the exit checkout flow by proper redirecting back to /plans page * Refactor backDestination logic Update `getPostCheckoutDestination` to return both destination and backDestination. That way we're sharing the same logic for determing whether this is the big sky flow or not. --------- Co-authored-by: Philip Jackson --- .../stepper/declarative-flow/onboarding.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/client/landing/stepper/declarative-flow/onboarding.ts b/client/landing/stepper/declarative-flow/onboarding.ts index c8ca6ed50dc1f..c81170e98ec8b 100644 --- a/client/landing/stepper/declarative-flow/onboarding.ts +++ b/client/landing/stepper/declarative-flow/onboarding.ts @@ -162,24 +162,33 @@ const onboarding: Flow = { const { isEligible: isBigSkyEligible } = useIsBigSkyEligible(); const isDesignChoicesStepEnabled = isBigSkyEligible && isGoalsAtFrontExperiment; - const getPostCheckoutDestination = ( providedDependencies: ProvidedDependencies ) => { + /** + * Returns [destination, backDestination] for the post-checkout destination. + */ + const getPostCheckoutDestination = ( + providedDependencies: ProvidedDependencies + ): [ string, string ] => { if ( createWithBigSky && config.isEnabled( 'onboarding/big-sky-before-plans' ) && isGoalsAtFrontExperiment ) { - return addQueryArgs( '/setup/site-setup/launch-big-sky', { + const destination = addQueryArgs( '/setup/site-setup/launch-big-sky', { siteSlug: providedDependencies.siteSlug, } ); + + return [ destination, addQueryArgs( '/setup/onboarding/plans', { skippedCheckout: 1 } ) ]; } - return addQueryArgs( '/setup/site-setup', { + const destination = addQueryArgs( '/setup/site-setup', { siteSlug: providedDependencies.siteSlug, ...( isGoalsAtFrontExperiment && { 'goals-at-front-experiment': true } ), ...( config.isEnabled( 'onboarding/newsletter-goal' ) && { flags: 'onboarding/newsletter-goal', } ), } ); + + return [ destination, addQueryArgs( destination, { skippedCheckout: 1 } ) ]; }; clearUseMyDomainsQueryParams( currentStepSlug ); @@ -344,7 +353,8 @@ const onboarding: Flow = { case 'create-site': return navigate( 'processing', undefined, true ); case 'processing': { - const destination = getPostCheckoutDestination( providedDependencies ); + const [ destination, backDestination ] = + getPostCheckoutDestination( providedDependencies ); persistSignupDestination( destination ); setSignupCompleteFlowName( flowName ); @@ -358,7 +368,7 @@ const onboarding: Flow = { addQueryArgs( `/checkout/${ encodeURIComponent( siteSlug ) }`, { redirect_to: destination, signup: 1, - checkoutBackUrl: pathToUrl( addQueryArgs( destination, { skippedCheckout: 1 } ) ), + checkoutBackUrl: pathToUrl( backDestination ), coupon, } ) );