Skip to content

Commit

Permalink
Merge branch 'skip-fork-ai-disabled' of https://github.com/newfold-la…
Browse files Browse the repository at this point in the history
…bs/wp-module-onboarding into skip-fork-ai-disabled
  • Loading branch information
avneet-raj committed Feb 28, 2024
2 parents 0574173 + 830b87b commit 39c7be0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
5 changes: 1 addition & 4 deletions src/OnboardingSPA/components/StartOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const StartOptions = ( { questionnaire, oldFlow, options } ) => {
if ( ! validateFlow( brandConfig, newFlow ) ) {
return false;
}
window.nfdOnboarding.currentBrand = brandConfig;
const currentFlow = window.nfdOnboarding.currentFlow;
const getData = resolveGetDataForFlow( newFlow );
const data = getData();
Expand All @@ -47,10 +46,8 @@ const StartOptions = ( { questionnaire, oldFlow, options } ) => {
setCurrentOnboardingData( currentData );
if ( SITEGEN_FLOW !== newFlow ) {
updateInitialize( true );
navigate( data.steps[ 0 ].path );
} else {
navigate( data.steps[ 1 ].path );
}
navigate( data.steps[ 1 ].path );
};
const selectFlow = ( flow ) => {
switch ( flow ) {
Expand Down
14 changes: 2 additions & 12 deletions src/OnboardingSPA/data/flows/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ import { indexPage } from '../../pages/IndexPage/page';
import { brush } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { stepTheFork } from '../../steps/TheFork/step';
import { validateFlow } from '../../data/flows/utils';
import { SITEGEN_FLOW } from '../../data/flows/constants';

export const pages = [ indexPage, errorPage ];

export const initialChapters = [ demographic, design, layoutContent, features ];

export const getSteps = ( chapters = initialChapters ) => {
let steps = [];
if (
validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW )
) {
steps.push( stepTheFork );
}
steps.push( stepTheFork );
steps.push( stepWelcome );
chapters.forEach( ( chapter ) => {
steps = steps.concat( [
Expand All @@ -40,11 +34,7 @@ export const getSteps = ( chapters = initialChapters ) => {

export const getRoutes = ( chapters = initialChapters ) => {
let routes = [ ...pages ];
if (
validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW )
) {
routes.push( stepTheFork );
}
routes.push( stepTheFork );
routes.push( stepWelcome );
chapters.forEach( ( chapter ) => {
routes = routes.concat( [
Expand Down
15 changes: 2 additions & 13 deletions src/OnboardingSPA/data/flows/ecommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import { filter } from 'lodash';
import { store } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { stepTheFork } from '../../steps/TheFork/step';
import { validateFlow } from '../../data/flows/utils';
import { SITEGEN_FLOW } from '../../data/flows/constants';

export const pages = [ indexPage, errorPage ];

Expand All @@ -34,12 +32,7 @@ export const initialChapters = [

export const getSteps = ( chapters = initialChapters ) => {
let steps = [];
if (
validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW )
) {
steps.push( stepTheFork );
}

steps.push( stepTheFork );
steps.push( stepWelcome );
chapters.forEach( ( chapter ) => {
steps = steps.concat( [
Expand All @@ -56,11 +49,7 @@ export const getSteps = ( chapters = initialChapters ) => {

export const getRoutes = ( chapters = initialChapters ) => {
let routes = [ ...pages ];
if (
validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW )
) {
routes.push( stepTheFork );
}
routes.push( stepTheFork );
routes.push( stepWelcome );
chapters.forEach( ( chapter ) => {
routes = routes.concat( [
Expand Down
49 changes: 43 additions & 6 deletions src/OnboardingSPA/steps/TheFork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@ import {
pluginDashboardPage,
} from '../../../constants';

import { DEFAULT_FLOW } from '../../data/flows/constants';
import { DEFAULT_FLOW, SITEGEN_FLOW } from '../../data/flows/constants';
import HeadingWithSubHeading from '../../components/HeadingWithSubHeading/SiteGen/index';
import StartOptions from '../../components/StartOptions';
import getContents from './contents';
import SitegenAiStateHandler from '../../components/StateHandlers/SitegenAi';
import { validateFlow } from '../../data/flows/utils';
import { resolveGetDataForFlow } from '../../data/flows';
import { useNavigate } from 'react-router-dom';

const TheFork = () => {
const { migrationUrl } = useSelect( ( select ) => {
return {
migrationUrl: select( nfdOnboardingStore ).getMigrationUrl(),
};
} );
const { migrationUrl, brandConfig, currentData } = useSelect(
( select ) => {
return {
migrationUrl: select( nfdOnboardingStore ).getMigrationUrl(),
brandConfig:
select( nfdOnboardingStore ).getNewfoldBrandConfig(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
};
}
);

const {
setIsHeaderEnabled,
Expand All @@ -31,9 +40,18 @@ const TheFork = () => {
setIsHeaderNavigationEnabled,
setFooterActiveView,
setHideFooterNav,
updateAllSteps,
updateTopSteps,
updateRoutes,
updateDesignRoutes,
updateInitialize,
setCurrentOnboardingData,
} = useDispatch( nfdOnboardingStore );

const navigate = useNavigate();

useEffect( () => {
checkHasAiAccess();
setHideFooterNav( true );
setIsHeaderEnabled( false );
setSidebarActiveView( false );
Expand All @@ -43,6 +61,25 @@ const TheFork = () => {
setFooterActiveView( FOOTER_SITEGEN );
} );

const checkHasAiAccess = () => {
if ( false === validateFlow( brandConfig, SITEGEN_FLOW ) ) {
const currentFlow = window.nfdOnboarding.currentFlow;
const getData = resolveGetDataForFlow( DEFAULT_FLOW );
const data = getData();
updateAllSteps( data.steps );
updateTopSteps( data?.topSteps );
updateRoutes( data.routes );
updateDesignRoutes( data?.designRoutes );
if ( SITEGEN_FLOW !== currentFlow ) {
window.nfdOnboarding.oldFlow = currentFlow;
}
window.nfdOnboarding.currentFlow = DEFAULT_FLOW;
currentData.activeFlow = DEFAULT_FLOW;
setCurrentOnboardingData( currentData );
updateInitialize( true );
navigate( data.steps[ 1 ].path );
}
};
const oldFlow = window.nfdOnboarding?.oldFlow
? window.nfdOnboarding.oldFlow
: DEFAULT_FLOW;
Expand Down

0 comments on commit 39c7be0

Please sign in to comment.