Skip to content

Commit

Permalink
Launchpad - Update launchpad domain upsell task completion for "choos…
Browse files Browse the repository at this point in the history
…e my domain later" link (Automattic#75133)

* Update domain upsell completion logic

* Update redirection and completion logic

* Update domain upsell choose my domain later logic

* Update launchpad settings request key
  • Loading branch information
agrullon95 authored Apr 7, 2023
1 parent 51cdc22 commit 5b3e932
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
21 changes: 21 additions & 0 deletions client/data/sites/use-launchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ), {
Expand Down
7 changes: 7 additions & 0 deletions client/landing/stepper/declarative-flow/domain-upsell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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':
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface LaunchpadStatuses {
video_uploaded?: boolean;
publish_first_course?: boolean;
plan_completed?: boolean;
domain_upsell_deferred?: boolean;
}

export interface LaunchpadResponse {
Expand Down

0 comments on commit 5b3e932

Please sign in to comment.