Skip to content

Commit

Permalink
Launchpad: use configured wpcom client for REST requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Jan 15, 2025
1 parent 1bb294a commit 9d68270
Show file tree
Hide file tree
Showing 44 changed files with 185 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { useQueryTheme } from 'calypso/components/data/query-theme';
import { skipLaunchpad } from 'calypso/landing/stepper/utils/skip-launchpad';
import wpcom from 'calypso/lib/wp';
import { useDispatch as useReduxDispatch } from 'calypso/state';
import { getCurrentUserSiteCount, isUserLoggedIn } from 'calypso/state/current-user/selectors';
import { activateOrInstallThenActivate } from 'calypso/state/themes/actions';
Expand Down Expand Up @@ -171,15 +172,15 @@ const assemblerFirstFlow: Flow = {
}

case 'plans': {
await updateLaunchpadSettings( siteId, {
await updateLaunchpadSettings( wpcom, siteId, {
checklist_statuses: { plan_completed: true },
} );

return navigate( 'launchpad' );
}

case 'domains': {
await updateLaunchpadSettings( siteId, {
await updateLaunchpadSettings( wpcom, siteId, {
checklist_statuses: { domain_upsell_deferred: true },
} );

Expand Down
11 changes: 6 additions & 5 deletions client/landing/stepper/declarative-flow/design-first.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'calypso/landing/stepper/declarative-flow/internals/types';
import { SITE_STORE, ONBOARD_STORE } from 'calypso/landing/stepper/stores';
import { skipLaunchpad } from 'calypso/landing/stepper/utils/skip-launchpad';
import wpcom from 'calypso/lib/wp';
import { getCurrentUserSiteCount, isUserLoggedIn } from 'calypso/state/current-user/selectors';
import { useExitFlow } from '../hooks/use-exit-flow';
import { useSiteData } from '../hooks/use-site-data';
Expand Down Expand Up @@ -152,7 +153,7 @@ const designFirst: Flow = {
} );

if ( providedDependencies?.hasSetPreselectedTheme ) {
updateLaunchpadSettings( siteSlug as string, {
updateLaunchpadSettings( wpcom, siteSlug as string, {
checklist_statuses: { design_completed: true },
} );

Expand Down Expand Up @@ -193,7 +194,7 @@ const designFirst: Flow = {
}
case 'domains':
if ( siteId ) {
await updateLaunchpadSettings( siteId, {
await updateLaunchpadSettings( wpcom, siteId, {
checklist_statuses: { domain_upsell_deferred: true },
} );
}
Expand All @@ -205,21 +206,21 @@ const designFirst: Flow = {
return navigate( 'plans' );
case 'use-my-domain':
if ( siteId ) {
await updateLaunchpadSettings( siteId, {
await updateLaunchpadSettings( wpcom, siteId, {
checklist_statuses: { domain_upsell_deferred: true },
} );
}
return navigate( 'plans' );
case 'plans':
if ( siteId ) {
await updateLaunchpadSettings( siteId, {
await updateLaunchpadSettings( wpcom, siteId, {
checklist_statuses: { plan_completed: true },
} );
}
return navigate( 'launchpad' );
case 'setup-blog':
if ( siteId ) {
await updateLaunchpadSettings( siteId, {
await updateLaunchpadSettings( wpcom, siteId, {
checklist_statuses: { setup_blog: true },
} );
}
Expand Down
10 changes: 7 additions & 3 deletions client/landing/stepper/declarative-flow/domain-upsell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OnboardSelect, updateLaunchpadSettings, useLaunchpad } from '@automatti
import { addPlanToCart, addProductsToCart, DOMAIN_UPSELL_FLOW } from '@automattic/onboarding';
import { useDispatch, useSelect } from '@wordpress/data';
import { translate } from 'i18n-calypso';
import wpcom from 'calypso/lib/wp';
import { useQuery } from '../hooks/use-query';
import { useSiteIdParam } from '../hooks/use-site-id-param';
import { useSiteSlug } from '../hooks/use-site-slug';
Expand Down Expand Up @@ -37,7 +38,10 @@ const domainUpsell: Flow = {
[]
);
const { setHideFreePlan } = useDispatch( ONBOARD_STORE );
const { data: { launchpad_screen: launchpadScreenOption } = {} } = useLaunchpad( siteSlug );
const { data: { launchpad_screen: launchpadScreenOption } = {} } = useLaunchpad(
wpcom,
siteSlug
);

const returnUrl =
launchpadScreenOption === 'skipped'
Expand All @@ -61,7 +65,7 @@ const domainUpsell: Flow = {
try {
const siteIdentifier = siteSlug || siteId;
if ( siteIdentifier ) {
await updateLaunchpadSettings( siteIdentifier, {
await updateLaunchpadSettings( wpcom, siteIdentifier, {
checklist_statuses: { domain_upsell_deferred: true },
} );
}
Expand All @@ -77,7 +81,7 @@ const domainUpsell: Flow = {
const planCartItem = getPlanCartItem();
const domainCartItem = getDomainCartItem();
if ( planCartItem && siteSlug && flowName ) {
await addPlanToCart( siteSlug, flowName, true, '', planCartItem );
await addPlanToCart( wpcom, siteSlug, flowName, true, '', planCartItem );
}

if ( domainCartItem && siteSlug && flowName ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { updateLaunchpadSettings } from '@automattic/data-stores';
import { ExperimentAssignment } from '@automattic/explat-client';
import wpcom from 'calypso/lib/wp';

export const LAUNCHPAD_EXPERIMENT_NAME = 'calypso_onboarding_launchpad_removal_test_2024_08';

Expand Down Expand Up @@ -30,7 +31,7 @@ export const useLaunchpadDecider = ( { exitFlow, navigate }: Props ) => {

const setLaunchpadSkipState = ( siteIdOrSlug: string | number | null ) => {
if ( siteIdOrSlug && launchpadStateOnSkip ) {
updateLaunchpadSettings( siteIdOrSlug, { launchpad_screen: launchpadStateOnSkip } );
updateLaunchpadSettings( wpcom, siteIdOrSlug, { launchpad_screen: launchpadStateOnSkip } );
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import { ONBOARD_STORE } from 'calypso/landing/stepper/stores';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { urlToSlug } from 'calypso/lib/url';
import wpcom from 'calypso/lib/wp';
import SitePreview from '../../components/site-preview';
import useCelebrationData from './use-celebration-data';
import type { Step } from '../../types';
Expand All @@ -28,7 +29,7 @@ const CelebrationStep: Step = ( { flow, navigation } ) => {

const {
data: { checklist_statuses: checklistStatuses },
} = useLaunchpad( siteSlug );
} = useLaunchpad( wpcom, siteSlug );

const {
title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { useSourceMigrationStatusQuery } from 'calypso/data/site-migration/use-s
import { useQuery } from 'calypso/landing/stepper/hooks/use-query';
import { ONBOARD_STORE } from 'calypso/landing/stepper/stores';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import wpcom from 'calypso/lib/wp';
import {
retrieveSignupDestination,
getSignupCompleteFlowName,
Expand Down Expand Up @@ -198,7 +199,7 @@ const CreateSite: Step = function CreateSite( { navigation, flow, data } ) {
const slug = getSignupCompleteSlug();

if ( planCartItem && slug ) {
await addPlanToCart( slug, flow, true, theme, planCartItem );
await addPlanToCart( wpcom, slug, flow, true, theme, planCartItem );
}

return {
Expand All @@ -212,6 +213,7 @@ const CreateSite: Step = function CreateSite( { navigation, flow, data } ) {

const sourceSlug = hasSourceSlug( data ) ? data.sourceSlug : undefined;
const site = await createSiteWithCart(
wpcom,
flow,
true,
isPaidDomainItem,
Expand Down Expand Up @@ -249,7 +251,7 @@ const CreateSite: Step = function CreateSite( { navigation, flow, data } ) {
}

if ( planCartItem && site?.siteSlug ) {
await addPlanToCart( site.siteSlug, flow, true, theme, planCartItem );
await addPlanToCart( wpcom, site.siteSlug, flow, true, theme, planCartItem );
}

if ( productCartItems?.length && site?.siteSlug ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { useExperiment } from 'calypso/lib/explat';
import { navigate } from 'calypso/lib/navigate';
import { urlToSlug } from 'calypso/lib/url';
import wpcom from 'calypso/lib/wp';
import { useDispatch as useReduxDispatch, useSelector } from 'calypso/state';
import { getEligibility } from 'calypso/state/automated-transfer/selectors';
import {
Expand Down Expand Up @@ -633,7 +634,7 @@ const UnifiedDesignPickerStep: Step = ( { navigation, flow, stepName } ) => {
setSelectedDesign( _selectedDesign );

if ( siteSlugOrId ) {
await updateLaunchpadSettings( siteSlugOrId, {
await updateLaunchpadSettings( wpcom, siteSlugOrId, {
checklist_statuses: { design_completed: true },
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useSiteSlugParam } from 'calypso/landing/stepper/hooks/use-site-slug-pa
import { SITE_STORE } from 'calypso/landing/stepper/stores';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { urlToSlug } from 'calypso/lib/url';
import wpcom from 'calypso/lib/wp';
import { useSelector, useDispatch } from 'calypso/state';
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';
import { successNotice } from 'calypso/state/notices/actions';
Expand Down Expand Up @@ -43,7 +44,7 @@ const Launchpad: Step = ( { navigation, flow }: LaunchpadProps ) => {
const {
isError: launchpadFetchError,
data: { launchpad_screen: launchpadScreenOption, checklist: launchpadChecklist } = {},
} = useLaunchpad( launchpadKey, siteIntentOption );
} = useLaunchpad( wpcom, launchpadKey, siteIntentOption );

const dispatch = useDispatch();
const { saveSiteSettings } = useWPDispatch( SITE_STORE );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { type NavigationControls } from 'calypso/landing/stepper/declarative-flo
import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import { ONBOARD_STORE } from 'calypso/landing/stepper/stores';
import { type ResponseDomain } from 'calypso/lib/domains/types';
import wpcom from 'calypso/lib/wp';
import RecurringPaymentsPlanAddEditModal from 'calypso/my-sites/earn/components/add-edit-plan-modal';
import { TYPE_TIER } from 'calypso/my-sites/earn/memberships/constants';
import { useSelector } from 'calypso/state';
Expand Down Expand Up @@ -75,7 +76,7 @@ const Sidebar = ( {

const {
data: { checklist_statuses: checklistStatuses, checklist: launchpadChecklist },
} = useLaunchpad( launchpadKey, siteIntentOption, {
} = useLaunchpad( wpcom, launchpadKey, siteIntentOption, {
onSuccess: sortLaunchpadTasksByCompletionStatus,
} );

Expand Down Expand Up @@ -282,6 +283,7 @@ const Sidebar = ( {
</div>
) }
<LaunchpadInternal
wpcom={ wpcom }
flow={ flow }
site={ site }
siteSlug={ launchpadKey }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { updateLaunchpadSettings } from '@automattic/data-stores/src/queries/use-launchpad';
import { isNewsletterFlow } from '@automattic/onboarding';
import wpcom from 'calypso/lib/wp';
import { TaskAction } from '../../types';

const completeMigrateContentTask = async ( siteSlug: string | null ) => {
if ( siteSlug ) {
await updateLaunchpadSettings( siteSlug, {
await updateLaunchpadSettings( wpcom, siteSlug, {
checklist_statuses: { migrate_content: true },
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { QueryClient } from '@tanstack/react-query';
import { ExternalLink } from '@wordpress/components';
import { addQueryArgs } from '@wordpress/url';
import { translate } from 'i18n-calypso';
import wpcom from 'calypso/lib/wp';
import { ADD_TIER_PLAN_HASH } from 'calypso/my-sites/earn/memberships/constants';
import { getSiteIdOrSlug } from '../../task-helper';
import { recordGlobalStylesGattingPlanSelectedResetStylesEvent } from '../../tracking';
Expand Down Expand Up @@ -102,7 +103,7 @@ const getPlanCompletedTask: TaskAction = ( task, flow, context ) => {
//TODO: Move the updateLaunchpadSettings to be a hoook and use queryclient to invalidate the hook.
const completePaidNewsletterTask = async ( siteSlug: string | null, queryClient: QueryClient ) => {
if ( siteSlug ) {
await updateLaunchpadSettings( siteSlug, {
await updateLaunchpadSettings( wpcom, siteSlug, {
checklist_statuses: { newsletter_plan_created: true },
} );
queryClient?.invalidateQueries( { queryKey: [ 'launchpad' ] } );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StepContainer } from '@automattic/onboarding';
import { Button } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import clsx from 'clsx';
import { translate } from 'i18n-calypso';
import { useTranslate } from 'i18n-calypso';
import React, { useState } from 'react';
import useUrlQueryParam from 'calypso/a8c-for-agencies/hooks/use-url-query-param';
import DocumentHead from 'calypso/components/data/document-head';
Expand Down Expand Up @@ -34,6 +34,7 @@ const ReadymadeTemplateGenerateContent: React.FC< ReadymadeTemplateGenerateConte
siteSlug,
next = () => {},
} ) => {
const translate = useTranslate();
const [ aiContext, setAiContext ] = useState( '' );
const [ numberOfGenerations, setNumberOfGenerations ] = useState( 0 );
const [ isGeneratingContent, setIsGeneratingContent ] = useState( false );
Expand All @@ -44,7 +45,7 @@ const ReadymadeTemplateGenerateContent: React.FC< ReadymadeTemplateGenerateConte
const locale = useLocale();

const markContentGenerationTaskComplete = () =>
updateLaunchpadSettings( siteSlug, {
updateLaunchpadSettings( wpcom, siteSlug, {
checklist_statuses: { generate_content: true },
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useQuery } from 'calypso/landing/stepper/hooks/use-query';
import { useSite } from 'calypso/landing/stepper/hooks/use-site';
import { useSiteSlug } from 'calypso/landing/stepper/hooks/use-site-slug';
import { ONBOARD_STORE, SITE_STORE } from 'calypso/landing/stepper/stores';
import wpcom from 'calypso/lib/wp';
import { getHidePlanPropsBasedOnThemeType } from 'calypso/my-sites/plans-features-main/components/utils/utils';
import { getSignupCompleteSiteID, getSignupCompleteSlug } from 'calypso/signup/storageUtils';
import { useSelector, useDispatch as useReduxDispatch } from 'calypso/state';
Expand Down Expand Up @@ -108,7 +109,7 @@ export default function PlansStepAdaptor( props: StepProps ) {
return setDesignOnSite( site?.ID, defaultDesign, {
styleVariation: defaultDesign?.style_variations?.[ 0 ],
} ).then( async ( theme: ActiveTheme ) => {
await updateLaunchpadSettings( site?.ID || '', {
await updateLaunchpadSettings( wpcom, site?.ID || '', {
checklist_statuses: { design_completed: false },
} );
return reduxDispatch( setActiveTheme( site?.ID || -1, theme ) );
Expand Down
3 changes: 2 additions & 1 deletion client/landing/stepper/declarative-flow/newsletter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useLaunchpadDecider } from 'calypso/landing/stepper/declarative-flow/in
import { useQuery } from 'calypso/landing/stepper/hooks/use-query';
import { skipLaunchpad } from 'calypso/landing/stepper/utils/skip-launchpad';
import { triggerGuidesForStep } from 'calypso/lib/guides/trigger-guides-for-step';
import wpcom from 'calypso/lib/wp';
import {
clearSignupDestinationCookie,
setSignupCompleteSlug,
Expand Down Expand Up @@ -94,7 +95,7 @@ const newsletter: Flow = {

const completeSubscribersTask = async () => {
if ( siteSlug ) {
await updateLaunchpadSettings( siteSlug, {
await updateLaunchpadSettings( wpcom, siteSlug, {
checklist_statuses: { subscribers_added: true },
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ const readymadeTemplateFlow: Flow = {
}

case 'plans': {
await updateLaunchpadSettings( siteId, {
await updateLaunchpadSettings( wpcom, siteId, {
checklist_statuses: { plan_completed: true },
} );

return navigate( 'launchpad' );
}

case 'domains': {
await updateLaunchpadSettings( siteId, {
await updateLaunchpadSettings( wpcom, siteId, {
checklist_statuses: { domain_upsell_deferred: true },
} );

Expand Down
5 changes: 3 additions & 2 deletions client/landing/stepper/declarative-flow/site-setup-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useIsBigSkyEligible } from 'calypso/landing/stepper/hooks/use-is-site-b
import { useQuery } from 'calypso/landing/stepper/hooks/use-query';
import { ImporterMainPlatform } from 'calypso/lib/importer/types';
import { addQueryArgs } from 'calypso/lib/route';
import wpcom from 'calypso/lib/wp';
import { useDispatch as reduxDispatch, useSelector } from 'calypso/state';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import { getInitialQueryArguments } from 'calypso/state/selectors/get-initial-query-arguments';
Expand Down Expand Up @@ -727,7 +728,7 @@ const siteSetupFlow: Flow = {

// Complete the "Select a design" task only when there is a selected design.
const design_completed = selectedDesign?.default ? false : true;
await updateLaunchpadSettings( siteSlugOrId, {
await updateLaunchpadSettings( wpcom, siteSlugOrId, {
checklist_statuses: { design_completed },
} );

Expand Down Expand Up @@ -757,7 +758,7 @@ const siteSetupFlow: Flow = {
} )
.then( async ( theme: ActiveTheme ) => {
const design_completed = selectedDesign?.default ? false : true;
await updateLaunchpadSettings( siteSlugOrId, {
await updateLaunchpadSettings( wpcom, siteSlugOrId, {
checklist_statuses: { design_completed },
} );
return dispatch( setActiveTheme( siteId, theme ) );
Expand Down
Loading

0 comments on commit 9d68270

Please sign in to comment.