-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding migrationHandler step to the importer-flow to handle redirects (…
…#73214) * Modify font size * Moving API into the helper function file * Modify addTempSiteToSourceOption function to use id instead of site slug * Refactor data layer to using React Query hooks * Remove unused functions
- Loading branch information
Showing
10 changed files
with
218 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useCallback } from 'react'; | ||
import { useMutation, useQueryClient } from 'react-query'; | ||
import wp from 'calypso/lib/wp'; | ||
|
||
interface TempSiteToSourceOption { | ||
targetBlogId: number; | ||
sourceBlogId: number; | ||
} | ||
|
||
function useAddTempSiteToSourceOptionMutation() { | ||
const queryClient = useQueryClient(); | ||
const mutation = useMutation( | ||
( { targetBlogId, sourceBlogId }: TempSiteToSourceOption ) => | ||
wp.req.post( | ||
`/migrations/from-source/${ sourceBlogId }`, | ||
{ | ||
apiNamespace: 'wpcom/v2', | ||
}, | ||
{ target_blog_id: targetBlogId } | ||
), | ||
{ | ||
onSuccess( data, { sourceBlogId } ) { | ||
queryClient.setQueryData( [ 'temp-target-site', sourceBlogId ], data ); | ||
}, | ||
} | ||
); | ||
|
||
const { mutate } = mutation; | ||
const addTempSiteToSourceOption = useCallback( | ||
( targetBlogId: number, sourceBlogId: number ) => mutate( { targetBlogId, sourceBlogId } ), | ||
[ mutate ] | ||
); | ||
|
||
return { addTempSiteToSourceOption, ...mutation }; | ||
} | ||
|
||
export default useAddTempSiteToSourceOptionMutation; |
21 changes: 21 additions & 0 deletions
21
client/data/site-migration/use-source-migration-status-query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { SourceSiteMigrationDetails } from '@automattic/data-stores/src/site'; | ||
import { useQuery } from 'react-query'; | ||
import wp from 'calypso/lib/wp'; | ||
import type { SiteId } from 'calypso/types'; | ||
|
||
export const useSourceMigrationStatusQuery = ( sourceId: SiteId | undefined ) => { | ||
return useQuery( | ||
[ 'source-migration-status', sourceId ], | ||
(): Promise< SourceSiteMigrationDetails > => | ||
wp.req.get( { | ||
path: '/migrations/from-source/' + encodeURIComponent( sourceId as number ), | ||
apiNamespace: 'wpcom/v2', | ||
} ), | ||
{ | ||
meta: { | ||
persist: false, | ||
}, | ||
enabled: !! sourceId, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { SiteDetails } from '@automattic/data-stores/src/site'; | ||
import { useQuery } from 'react-query'; | ||
import wp from 'calypso/lib/wp'; | ||
|
||
export const useSiteQuery = ( sourceSiteSlug: string, enabled = true ) => { | ||
return useQuery( | ||
[ 'site-details', sourceSiteSlug ], | ||
(): Promise< SiteDetails > => | ||
wp.req.get( { | ||
path: '/sites/' + encodeURIComponent( sourceSiteSlug as string ), | ||
} ), | ||
{ | ||
meta: { | ||
persist: false, | ||
}, | ||
enabled, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...t/landing/stepper/declarative-flow/internals/steps-repository/migration-handler/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { StepContainer, Title } from '@automattic/onboarding'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { useI18n } from '@wordpress/react-i18n'; | ||
import { useEffect } from 'react'; | ||
import DocumentHead from 'calypso/components/data/document-head'; | ||
import { LoadingEllipsis } from 'calypso/components/loading-ellipsis'; | ||
import { useSourceMigrationStatusQuery } from 'calypso/data/site-migration/use-source-migration-status-query'; | ||
import { useSiteQuery } from 'calypso/data/sites/use-site-query'; | ||
import { ONBOARD_STORE } from 'calypso/landing/stepper/stores'; | ||
import { recordTracksEvent } from 'calypso/lib/analytics/tracks'; | ||
import type { Step } from '../../types'; | ||
import './styles.scss'; | ||
|
||
const MigrationHandler: Step = function MigrationHandler( { navigation } ) { | ||
const { submit } = navigation; | ||
const { __ } = useI18n(); | ||
const stepProgress = useSelect( ( select ) => select( ONBOARD_STORE ).getStepProgress() ); | ||
const { setIsMigrateFromWp } = useDispatch( ONBOARD_STORE ); | ||
const search = window.location.search; | ||
const sourceSiteSlug = new URLSearchParams( search ).get( 'from' ) || ''; | ||
const { data: sourceSite, isError: isErrorSourcSite } = useSiteQuery( sourceSiteSlug ); | ||
const { data: sourceSiteMigrationStatus, isError: isErrorSourceSiteMigrationStatus } = | ||
useSourceMigrationStatusQuery( sourceSite?.ID ); | ||
const errorDependency = { | ||
isFromMigrationPlugin: true, | ||
hasError: true, | ||
}; | ||
|
||
useEffect( () => { | ||
setIsMigrateFromWp( true ); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [] ); | ||
|
||
useEffect( () => { | ||
if ( submit ) { | ||
if ( isErrorSourcSite || isErrorSourceSiteMigrationStatus ) { | ||
return submit( errorDependency ); | ||
} | ||
if ( sourceSiteMigrationStatus ) { | ||
submit( { | ||
isFromMigrationPlugin: true, | ||
status: sourceSiteMigrationStatus?.status, | ||
targetBlogId: sourceSiteMigrationStatus?.target_blog_id, | ||
isAdminOnTarget: sourceSiteMigrationStatus?.is_target_blog_admin, | ||
isTargetBlogUpgraded: sourceSiteMigrationStatus?.is_target_blog_upgraded, | ||
targetBlogSlug: sourceSiteMigrationStatus?.target_blog_slug, | ||
} ); | ||
} | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [ isErrorSourcSite, isErrorSourceSiteMigrationStatus, sourceSiteMigrationStatus ] ); | ||
|
||
const getCurrentMessage = () => { | ||
return __( 'Scanning your site' ); | ||
}; | ||
|
||
return ( | ||
<> | ||
<DocumentHead title={ getCurrentMessage() } /> | ||
<StepContainer | ||
shouldHideNavButtons={ true } | ||
hideFormattedHeader={ true } | ||
stepName="migration-handler" | ||
isHorizontalLayout={ true } | ||
recordTracksEvent={ recordTracksEvent } | ||
stepContent={ | ||
<> | ||
<Title>{ getCurrentMessage() }</Title> | ||
<LoadingEllipsis /> | ||
</> | ||
} | ||
stepProgress={ stepProgress } | ||
showFooterWooCommercePowered={ false } | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default MigrationHandler; |
16 changes: 16 additions & 0 deletions
16
...landing/stepper/declarative-flow/internals/steps-repository/migration-handler/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@import "../style"; | ||
|
||
.migration-handler { | ||
max-width: 540px; | ||
text-align: center; | ||
margin: 16vh auto 0; | ||
|
||
.step-container__content { | ||
.onboarding-title { | ||
font-size: 1.625rem; /* stylelint-disable-line scales/font-sizes */ | ||
/* stylelint-disable-next-line declaration-property-unit-allowed-list */ | ||
line-height: 1em; | ||
margin-bottom: 1.5rem; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters