Skip to content

Commit

Permalink
Call migration store option API after siteCreationStep if it's from m…
Browse files Browse the repository at this point in the history
…igration plugin (#73080)
  • Loading branch information
ouikhuan authored Feb 12, 2023
1 parent 69605ec commit 7e247c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 );
} );
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ),
Expand Down

0 comments on commit 7e247c5

Please sign in to comment.