From 7e247c535b0552a6d2b18c0baed2b4c430d74d79 Mon Sep 17 00:00:00 2001 From: ouikhuan Date: Sun, 12 Feb 2023 17:59:16 +0800 Subject: [PATCH] Call migration store option API after siteCreationStep if it's from migration plugin (#73080) --- .../internals/steps-repository/import/helper.ts | 16 ++++++++++++++++ .../site-creation-step/index.tsx | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/client/landing/stepper/declarative-flow/internals/steps-repository/import/helper.ts b/client/landing/stepper/declarative-flow/internals/steps-repository/import/helper.ts index bb571c0a04f78..20293bb550d38 100644 --- a/client/landing/stepper/declarative-flow/internals/steps-repository/import/helper.ts +++ b/client/landing/stepper/declarative-flow/internals/steps-repository/import/helper.ts @@ -8,6 +8,7 @@ import { getWpOrgImporterUrl, } from 'calypso/blocks/import/util'; import { WPImportOption } from 'calypso/blocks/importer/wordpress/types'; +import wpcom from 'calypso/lib/wp'; import { BASE_ROUTE } from './config'; export function getFinalImporterUrl( @@ -62,3 +63,18 @@ export function generateStepPath( stepName: string, stepSectionName?: string ) { return camelCase( path ) as string; } + +export async function addTempSiteToSourceOption( targetBlogId: number, sourceSiteSlug: string ) { + return wpcom.req + .post( { + path: `/migrations/from-source/${ sourceSiteSlug }`, + apiNamespace: 'wpcom/v2', + body: { + target_blog_id: targetBlogId, + }, + } ) + .catch( ( error: Error ) => { + // eslint-disable-next-line no-console + console.error( 'Unable to store option in source site', error ); + } ); +} diff --git a/client/landing/stepper/declarative-flow/internals/steps-repository/site-creation-step/index.tsx b/client/landing/stepper/declarative-flow/internals/steps-repository/site-creation-step/index.tsx index db0b56a6ca012..64f92796df27e 100644 --- a/client/landing/stepper/declarative-flow/internals/steps-repository/site-creation-step/index.tsx +++ b/client/landing/stepper/declarative-flow/internals/steps-repository/site-creation-step/index.tsx @@ -28,6 +28,7 @@ import { getSignupCompleteSlug, } from 'calypso/signup/storageUtils'; import { getCurrentUserName } from 'calypso/state/current-user/selectors'; +import { addTempSiteToSourceOption } from '../import/helper'; import type { Step } from '../../types'; import './styles.scss'; @@ -122,6 +123,13 @@ const SiteCreationStep: Step = function SiteCreationStep( { navigation, flow, da await addProductsToCart( site?.siteSlug as string, flow as string, productCartItems ); } + if ( isMigrationFlow( flow ) ) { + const search = window.location.search; + const sourceSiteSlug = new URLSearchParams( search ).get( 'from' ); + // Store temporary target blog id to source site option + await addTempSiteToSourceOption( site?.siteId as number, sourceSiteSlug as string ); + } + return { siteSlug: site?.siteSlug, goToCheckout: Boolean( planCartItem ),