From e4734793d84b272a4adc2d7da581ce9fb0517f05 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Wed, 28 Feb 2024 16:31:41 +0530 Subject: [PATCH 1/2] Revert "lint fixes" This reverts commit 0c195cf9641963bf31cf72e0c9e099d430211640. --- src/OnboardingSPA/data/flows/default.js | 8 ++------ src/OnboardingSPA/data/flows/ecommerce.js | 8 ++------ src/OnboardingSPA/steps/TheFork/index.js | 13 ++++++++----- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/OnboardingSPA/data/flows/default.js b/src/OnboardingSPA/data/flows/default.js index a5d1c865c..7ace3da04 100644 --- a/src/OnboardingSPA/data/flows/default.js +++ b/src/OnboardingSPA/data/flows/default.js @@ -22,9 +22,7 @@ export const initialChapters = [ demographic, design, layoutContent, features ]; export const getSteps = ( chapters = initialChapters ) => { let steps = []; - if ( - validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) - ) { + if ( validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) ) { steps.push( stepTheFork ); } steps.push( stepWelcome ); @@ -40,9 +38,7 @@ export const getSteps = ( chapters = initialChapters ) => { export const getRoutes = ( chapters = initialChapters ) => { let routes = [ ...pages ]; - if ( - validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) - ) { + if ( validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) ) { routes.push( stepTheFork ); } routes.push( stepWelcome ); diff --git a/src/OnboardingSPA/data/flows/ecommerce.js b/src/OnboardingSPA/data/flows/ecommerce.js index a63543778..687358b89 100644 --- a/src/OnboardingSPA/data/flows/ecommerce.js +++ b/src/OnboardingSPA/data/flows/ecommerce.js @@ -34,9 +34,7 @@ export const initialChapters = [ export const getSteps = ( chapters = initialChapters ) => { let steps = []; - if ( - validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) - ) { + if ( validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) ) { steps.push( stepTheFork ); } @@ -56,9 +54,7 @@ export const getSteps = ( chapters = initialChapters ) => { export const getRoutes = ( chapters = initialChapters ) => { let routes = [ ...pages ]; - if ( - validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) - ) { + if ( validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) ) { routes.push( stepTheFork ); } routes.push( stepWelcome ); diff --git a/src/OnboardingSPA/steps/TheFork/index.js b/src/OnboardingSPA/steps/TheFork/index.js index 1ee659af7..2002aa8fa 100644 --- a/src/OnboardingSPA/steps/TheFork/index.js +++ b/src/OnboardingSPA/steps/TheFork/index.js @@ -17,11 +17,14 @@ import getContents from './contents'; import SitegenAiStateHandler from '../../components/StateHandlers/SitegenAi'; const TheFork = () => { - const { migrationUrl } = useSelect( ( select ) => { - return { - migrationUrl: select( nfdOnboardingStore ).getMigrationUrl(), - }; - } ); + const { migrationUrl } = useSelect( + ( select ) => { + return { + migrationUrl: select( nfdOnboardingStore ).getMigrationUrl(), + + }; + } + ); const { setIsHeaderEnabled, From 830b87bfdd20d624299cbefed4666690ec49037f Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Wed, 28 Feb 2024 16:31:48 +0530 Subject: [PATCH 2/2] Revert "added handling in flows" This reverts commit dcafcf443053f90c74f6ae9d7174a609373e34a0. --- .../components/StartOptions/index.js | 5 +-- src/OnboardingSPA/data/flows/default.js | 10 +---- src/OnboardingSPA/data/flows/ecommerce.js | 11 +---- src/OnboardingSPA/steps/TheFork/index.js | 40 +++++++++++++++++-- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/OnboardingSPA/components/StartOptions/index.js b/src/OnboardingSPA/components/StartOptions/index.js index ab4514145..6dbb43305 100644 --- a/src/OnboardingSPA/components/StartOptions/index.js +++ b/src/OnboardingSPA/components/StartOptions/index.js @@ -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(); @@ -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 ) { diff --git a/src/OnboardingSPA/data/flows/default.js b/src/OnboardingSPA/data/flows/default.js index 7ace3da04..f7b3740c1 100644 --- a/src/OnboardingSPA/data/flows/default.js +++ b/src/OnboardingSPA/data/flows/default.js @@ -13,8 +13,6 @@ 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 ]; @@ -22,9 +20,7 @@ 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( [ @@ -38,9 +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( [ diff --git a/src/OnboardingSPA/data/flows/ecommerce.js b/src/OnboardingSPA/data/flows/ecommerce.js index 687358b89..68bca7e04 100644 --- a/src/OnboardingSPA/data/flows/ecommerce.js +++ b/src/OnboardingSPA/data/flows/ecommerce.js @@ -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 ]; @@ -34,10 +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( [ @@ -54,9 +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( [ diff --git a/src/OnboardingSPA/steps/TheFork/index.js b/src/OnboardingSPA/steps/TheFork/index.js index 2002aa8fa..a0cba9a21 100644 --- a/src/OnboardingSPA/steps/TheFork/index.js +++ b/src/OnboardingSPA/steps/TheFork/index.js @@ -10,18 +10,24 @@ 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( + const { migrationUrl, brandConfig, currentData } = useSelect( ( select ) => { return { migrationUrl: select( nfdOnboardingStore ).getMigrationUrl(), - + brandConfig: + select( nfdOnboardingStore ).getNewfoldBrandConfig(), + currentData: + select( nfdOnboardingStore ).getCurrentOnboardingData(), }; } ); @@ -34,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 ); @@ -46,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;