Skip to content

Commit

Permalink
migration screen added
Browse files Browse the repository at this point in the history
  • Loading branch information
ramyakrishnai committed Apr 4, 2024
1 parent c0f0ac6 commit 4a06bdf
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ import StepNavigation from './step-navigation';

// eslint-disable-next-line import/no-extraneous-dependencies
import { findIndex } from 'lodash';
import { stepMigration } from '../../../../steps/SiteGen/Migration/step';

/**
* Interface header rendered into header render prop in <InterfaceSkeleton />.
*
* @return {WPComponent} Header
*/
const SiteGenHeader = () => {
const { isHeaderNavigationEnabled, currentStep, allSteps } = useSelect(
( select ) => {
const { isHeaderNavigationEnabled, currentStep, allSteps, currentRoute } =
useSelect( ( select ) => {
return {
currentStep: select( nfdOnboardingStore ).getCurrentStep(),
currentRoute: select( nfdOnboardingStore ).getCurrentStepPath(),
isHeaderNavigationEnabled:
select( nfdOnboardingStore ).isHeaderNavigationEnabled(),
allSteps: select( nfdOnboardingStore ).getAllSteps(),
};
}
);
} );

const currentStepIndex = findIndex( allSteps, {
path: currentStep?.path,
Expand All @@ -45,9 +46,10 @@ const SiteGenHeader = () => {
<Fill name={ `${ HEADER_SITEGEN }/${ HEADER_TOP }` }>
<>
<AdminBar />
{ currentStep !== stepTheFork && (
<ProgressBar progress={ progress } />
) }
{ currentStep !== stepTheFork &&
currentRoute !== stepMigration.path && (
<ProgressBar progress={ progress } />
) }
</>
</Fill>
<Fill name={ `${ HEADER_SITEGEN }/${ HEADER_START }` }>
Expand Down
3 changes: 2 additions & 1 deletion src/OnboardingSPA/data/flows/sitegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { siteGenCore } from '../../chapters/siteGen/core';
import { errorPage } from '../../pages/ErrorPage/page';
import { indexPage } from '../../pages/IndexPage/page';
import { stepSiteGenWelcome } from '../../steps/SiteGen/Welcome/step';
import { stepMigration } from '../../steps/SiteGen/Migration/step';
import { stepTheFork } from '../../steps/TheFork/step';

export const pages = [ indexPage, errorPage ];
Expand All @@ -24,7 +25,7 @@ export const getSteps = ( chapters = initialChapters ) => {

export const getRoutes = ( chapters = initialChapters ) => {
let routes = [ ...pages ];
routes.push( stepTheFork, stepSiteGenWelcome );
routes.push( stepTheFork, stepSiteGenWelcome, stepMigration );
chapters.forEach( ( chapter ) => {
routes = routes.concat( [
...chapter.steps,
Expand Down
17 changes: 17 additions & 0 deletions src/OnboardingSPA/steps/SiteGen/Migration/contents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { __ } from '@wordpress/i18n';

const getContents = () => {
return {
heading: __(
"Let's migrate your existing site to your new account",
'wp-module-onboarding'
),
description: __(
'Please wait a few seconds while we get your new account ready to import your existing WordPress site. ',
'wp-module-onboarding'
),
importtext: __( 'Preparing your account', 'wp-module-onboarding' ),
};
};

export default getContents;
56 changes: 56 additions & 0 deletions src/OnboardingSPA/steps/SiteGen/Migration/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import CommonLayout from '../../../components/Layouts/Common';

import { useEffect } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';

import { store as nfdOnboardingStore } from '../../../store';
import { FOOTER_SITEGEN, HEADER_SITEGEN } from '../../../../constants';

import getContents from './contents';
import HeadingWithSubHeading from '../../../components/HeadingWithSubHeading/SiteGen';
import { getSiteMigrateUrl } from '../../../utils/api/siteGen';

const Migrate = () => {
const {
setIsHeaderEnabled,
setSidebarActiveView,
setHeaderActiveView,
setDrawerActiveView,
setIsHeaderNavigationEnabled,
setFooterActiveView,
setHideFooterNav,
} = useDispatch( nfdOnboardingStore );

const loadData = async () => {
const migrateUrl = await getSiteMigrateUrl();
migrateUrl?.body && window.open(migrateUrl?.body, "_self")
};

useEffect( () => {
setHideFooterNav( true );
setIsHeaderEnabled( false );
setSidebarActiveView( false );
setIsHeaderNavigationEnabled( false );
setHeaderActiveView( HEADER_SITEGEN );
setDrawerActiveView( false );
setFooterActiveView( FOOTER_SITEGEN );
loadData()
} );

const content = getContents();
return (
<CommonLayout
// isCentered
className="nfd-onboarding-step--site-gen__migration"
>
<HeadingWithSubHeading title={ content?.heading } />
<div className="nfd-onboarding-step--site-gen__migration__contain">
<div className="nfd-onboarding-step--site-gen__migration__loader"></div>{ ' ' }
<p className="importtext">{ content?.importtext }</p>
</div>
<p className="description">{ content?.description }</p>
</CommonLayout>
);
};

export default Migrate;
19 changes: 19 additions & 0 deletions src/OnboardingSPA/steps/SiteGen/Migration/step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { copy } from '@wordpress/icons';
import { lazy } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Step } from '../../../data/models/Step';

const StepMigration = lazy( () => import( './index' ) );

export const stepMigration = new Step( {
path: '/sitegen/step/migration',
title: __( 'Migration', 'wp-module-onboarding' ),
Component: StepMigration,
icon: copy,
drawerNavigation: false,
sidebars: {
LearnMore: {
SidebarComponents: [],
},
},
} );
41 changes: 41 additions & 0 deletions src/OnboardingSPA/steps/SiteGen/Migration/stylesheet.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.nfd-onboarding-step--site-gen__migration {
display: flex;
align-items: center;
flex-direction: column;
justify-content: flex-start;
font-weight: 500;
.description{
font-size: 18px;
color: var(--nfd-onboarding-primary);
margin: 50px 0;
}
.nfd-onboarding-step--site-gen__migration__contain {
display: flex;
align-items: center;
border-radius: 12px;
gap: 16px;
padding: 24px;
background-color: var(--nfd-onboarding-card-background);
justify-content: center;
width: 436px;
.importtext{
color: var(--nfd-onboarding-primary);
font-size: 16px;
font-weight: 500;
}
.nfd-onboarding-step--site-gen__migration__loader {
border: 5px solid var(--nfd-onboarding-progress-bar-background);
border-top: 5px solid var(--nfd-onboarding-progress-bar-fill);
border-radius: 50%;
width: 29px;
height: 28px;
animation: spin 2s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
}

}
20 changes: 12 additions & 8 deletions src/OnboardingSPA/steps/TheFork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
trackOnboardingEvent,
} from '../../utils/analytics/hiive';
import { ACTION_SITEGEN_FORK_OPTION_SELECTED } from '../../utils/analytics/hiive/constants';
import { useNavigate } from 'react-router-dom';

const TheFork = () => {
const { migrationUrl } = useSelect( ( select ) => {
Expand Down Expand Up @@ -63,6 +64,8 @@ const TheFork = () => {
window.location.replace( pluginDashboardPage );
};
const content = getContents();
const navigate = useNavigate();

return (
<CommonLayout
isCentered
Expand All @@ -80,22 +83,23 @@ const TheFork = () => {
<br />
<br />
{ migrationUrl && (
<a
<div
className="nfd-onboarding-step--site-gen__fork__importsite"
href={ migrationUrl }
target={ '_blank' }
rel={ 'noreferrer' }
onClick={ () =>
// href={ migrationUrl }
// target={ '_blank' }
// rel={ 'noreferrer' }
onClick={ () => {
navigate( '/sitegen/step/migration' );
trackOnboardingEvent(
new OnboardingEvent(
ACTION_SITEGEN_FORK_OPTION_SELECTED,
'MIGRATE'
)
)
}
);
} }
>
{ content.importtext }
</a>
</div>
) }
<span
role="button"
Expand Down
1 change: 1 addition & 0 deletions src/OnboardingSPA/steps/TheFork/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
text-align: center;
margin: 25px !important;
color: var(--nfd-onboarding-primary);
text-decoration: underline;
}

&__exit {
Expand Down
1 change: 1 addition & 0 deletions src/OnboardingSPA/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
@import "../steps/SiteGen/Welcome/stylesheet";
@import "../steps/SiteGen/Editor/stylesheet";
@import "../steps/SiteGen/Editor/Header/stylesheet";
@import "../steps/SiteGen/Migration/stylesheet.scss";

.nfd-onboarding-container {
display: flex;
Expand Down
8 changes: 7 additions & 1 deletion src/OnboardingSPA/utils/api/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onboardingRestBase, wpRestBase, installerRestBase } from '../../../constants';
import { onboardingRestBase, wpRestBase, installerRestBase, migrateRestBase } from '../../../constants';

export const onboardingRestURL = ( api ) => {
return (
Expand All @@ -15,6 +15,12 @@ export const installerRestURL = ( api ) => {
);
};

export const migrateRestURL = ( api ) => {
return (
`${ migrateRestBase }/${ api }`
);
};

export const wpRestURL = ( api ) => {
return `${ wpRestBase }/${ api }`;
};
10 changes: 9 additions & 1 deletion src/OnboardingSPA/utils/api/siteGen.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import apiFetch from '@wordpress/api-fetch';

import { resolve } from './resolve.js';
import { onboardingRestURL } from './common';
import { onboardingRestURL, migrateRestURL } from './common';

export async function getSiteGenIdentifiers() {
return await resolve(
Expand Down Expand Up @@ -88,3 +88,11 @@ export async function publishSitemapPages( siteDescription ) {
} ).then()
);
}

export async function getSiteMigrateUrl() {
return await resolve(
apiFetch( {
url: migrateRestURL( 'migrate/connect' ),
} ).then()
);
}
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export const wpRestURL = window.nfdOnboarding.restUrl;
export const wpRestRoute = 'wp/v2';
export const onboardingRestRoute = 'newfold-onboarding/v1';
export const installerRestRoute = 'newfold-installer/v1';
export const migrationRestRoute = 'newfold-migration/v1';
export const wpRestBase = `${ wpRestURL }/${ wpRestRoute }`;
export const onboardingRestBase = `${ wpRestURL }/${ onboardingRestRoute }`;
export const installerRestBase = `${ wpRestURL }/${ installerRestRoute }`;
export const migrateRestBase = `${ wpRestURL }/${ migrationRestRoute }`;
export const wpAdminPage = addQueryArgs(
`${ wpAdminUrl }index.php`,
window.nfdOnboarding.currentBrand?.dashboardRedirectParams
Expand Down

0 comments on commit 4a06bdf

Please sign in to comment.