From 5b3e93234cfa7f1e01d902ce26d6cbe849453cac Mon Sep 17 00:00:00 2001 From: Anthony Grullon Date: Fri, 7 Apr 2023 19:06:46 -0400 Subject: [PATCH] Launchpad - Update launchpad domain upsell task completion for "choose my domain later" link (#75133) * Update domain upsell completion logic * Update redirection and completion logic * Update domain upsell choose my domain later logic * Update launchpad settings request key --- client/data/sites/use-launchpad.ts | 21 +++++++++++++++++++ .../stepper/declarative-flow/domain-upsell.ts | 7 +++++++ .../steps-repository/launchpad/task-helper.ts | 17 ++++++++++----- .../steps-repository/launchpad/types.ts | 1 + 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/client/data/sites/use-launchpad.ts b/client/data/sites/use-launchpad.ts index 875aba521b723..c57248161dc6a 100644 --- a/client/data/sites/use-launchpad.ts +++ b/client/data/sites/use-launchpad.ts @@ -10,6 +10,27 @@ export const fetchLaunchpad = ( siteSlug: string | null ) => { } ); }; +type LaunchpadUpdateSettings = { + checklist_statuses?: Record< string, boolean >; +}; + +export const updateLaunchpadSettings = ( + siteSlug: string | null, + settings: LaunchpadUpdateSettings = {} +) => { + const slug = encodeURIComponent( siteSlug as string ); + + return wpcom.req + .post( + { + path: `/sites/${ slug }/launchpad`, + apiNamespace: 'wpcom/v2', + }, + settings + ) + .catch(); +}; + export const useLaunchpad = ( siteSlug: string | null ) => { const key = [ 'launchpad', siteSlug ]; return useQuery( key, () => fetchLaunchpad( siteSlug ), { diff --git a/client/landing/stepper/declarative-flow/domain-upsell.ts b/client/landing/stepper/declarative-flow/domain-upsell.ts index e665ee011c644..9402a544c09c7 100644 --- a/client/landing/stepper/declarative-flow/domain-upsell.ts +++ b/client/landing/stepper/declarative-flow/domain-upsell.ts @@ -6,6 +6,7 @@ import { addProductsToCart, DOMAIN_UPSELL_FLOW, } from 'calypso/../packages/onboarding/src'; +import { updateLaunchpadSettings } from 'calypso/data/sites/use-launchpad'; import { useQuery } from '../hooks/use-query'; import { useSiteSlug } from '../hooks/use-site-slug'; import { ONBOARD_STORE } from '../stores'; @@ -50,6 +51,12 @@ const domainUpsell: Flow = { switch ( currentStep ) { case 'domains': if ( providedDependencies?.deferDomainSelection ) { + try { + await updateLaunchpadSettings( siteSlug, { + checklist_statuses: { domain_upsell_deferred: true }, + } ); + } catch ( error ) {} + return window.location.assign( returnUrl ); } setHideFreePlan( true ); diff --git a/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/task-helper.ts b/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/task-helper.ts index 5fabd6f4d9441..9d02c9235f951 100644 --- a/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/task-helper.ts +++ b/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/task-helper.ts @@ -52,7 +52,7 @@ export function getEnhancedTasks( const allowUpdateDesign = flow && ( isFreeFlow( flow ) || isBuildFlow( flow ) || isWriteFlow( flow ) ); - const isPaidPlan = ! site?.plan?.is_free; + const domainUpsellCompleted = isDomainUpsellCompleted( site, checklistStatuses ); const mustVerifyEmailBeforePosting = isNewsletterFlow( flow || null ) && ! isEmailVerified; @@ -337,10 +337,10 @@ export function getEnhancedTasks( case 'domain_upsell': taskData = { title: translate( 'Choose a domain' ), - completed: isPaidPlan, + completed: domainUpsellCompleted, actionDispatch: () => { - recordTaskClickTracksEvent( flow, isPaidPlan, task.id ); - const destinationUrl = isPaidPlan + recordTaskClickTracksEvent( flow, domainUpsellCompleted, task.id ); + const destinationUrl = domainUpsellCompleted ? `/domains/manage/${ siteSlug }` : addQueryArgs( '/setup/domain-upsell/domains', { siteSlug, @@ -349,7 +349,7 @@ export function getEnhancedTasks( } ); window.location.assign( destinationUrl ); }, - badgeText: isPaidPlan ? '' : translate( 'Upgrade plan' ), + badgeText: domainUpsellCompleted ? '' : translate( 'Upgrade plan' ), }; break; case 'verify_email': @@ -389,6 +389,13 @@ export function getEnhancedTasks( return enhancedTaskList; } +function isDomainUpsellCompleted( + site: SiteDetails | null, + checklistStatuses: LaunchpadStatuses +): boolean { + return ! site?.plan?.is_free || checklistStatuses?.domain_upsell_deferred === true; +} + // Records a generic task click Tracks event function recordTaskClickTracksEvent( flow: string | null | undefined, diff --git a/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/types.ts b/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/types.ts index 2cfe61ff9a650..749b0c7b70189 100644 --- a/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/types.ts +++ b/client/landing/stepper/declarative-flow/internals/steps-repository/launchpad/types.ts @@ -29,6 +29,7 @@ export interface LaunchpadStatuses { video_uploaded?: boolean; publish_first_course?: boolean; plan_completed?: boolean; + domain_upsell_deferred?: boolean; } export interface LaunchpadResponse {