From dcafcf443053f90c74f6ae9d7174a609373e34a0 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Wed, 28 Feb 2024 12:41:11 +0530 Subject: [PATCH] added handling in flows --- .../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, 24 insertions(+), 42 deletions(-) diff --git a/src/OnboardingSPA/components/StartOptions/index.js b/src/OnboardingSPA/components/StartOptions/index.js index 6dbb43305..ab4514145 100644 --- a/src/OnboardingSPA/components/StartOptions/index.js +++ b/src/OnboardingSPA/components/StartOptions/index.js @@ -30,6 +30,7 @@ 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(); @@ -46,8 +47,10 @@ 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 f7b3740c1..7ace3da04 100644 --- a/src/OnboardingSPA/data/flows/default.js +++ b/src/OnboardingSPA/data/flows/default.js @@ -13,6 +13,8 @@ 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 ]; @@ -20,7 +22,9 @@ export const initialChapters = [ demographic, design, layoutContent, features ]; export const getSteps = ( chapters = initialChapters ) => { let steps = []; - steps.push( stepTheFork ); + if ( validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) ) { + steps.push( stepTheFork ); + } steps.push( stepWelcome ); chapters.forEach( ( chapter ) => { steps = steps.concat( [ @@ -34,7 +38,9 @@ export const getSteps = ( chapters = initialChapters ) => { export const getRoutes = ( chapters = initialChapters ) => { let routes = [ ...pages ]; - routes.push( stepTheFork ); + if ( validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) ) { + 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 68bca7e04..687358b89 100644 --- a/src/OnboardingSPA/data/flows/ecommerce.js +++ b/src/OnboardingSPA/data/flows/ecommerce.js @@ -19,6 +19,8 @@ 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 ]; @@ -32,7 +34,10 @@ export const initialChapters = [ export const getSteps = ( chapters = initialChapters ) => { let steps = []; - steps.push( stepTheFork ); + if ( validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) ) { + steps.push( stepTheFork ); + } + steps.push( stepWelcome ); chapters.forEach( ( chapter ) => { steps = steps.concat( [ @@ -49,7 +54,9 @@ export const getSteps = ( chapters = initialChapters ) => { export const getRoutes = ( chapters = initialChapters ) => { let routes = [ ...pages ]; - routes.push( stepTheFork ); + if ( validateFlow( window.nfdOnboarding.currentBrand.config, SITEGEN_FLOW ) ) { + 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 a0cba9a21..2002aa8fa 100644 --- a/src/OnboardingSPA/steps/TheFork/index.js +++ b/src/OnboardingSPA/steps/TheFork/index.js @@ -10,24 +10,18 @@ import { pluginDashboardPage, } from '../../../constants'; -import { DEFAULT_FLOW, SITEGEN_FLOW } from '../../data/flows/constants'; +import { DEFAULT_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, brandConfig, currentData } = useSelect( + const { migrationUrl } = useSelect( ( select ) => { return { migrationUrl: select( nfdOnboardingStore ).getMigrationUrl(), - brandConfig: - select( nfdOnboardingStore ).getNewfoldBrandConfig(), - currentData: - select( nfdOnboardingStore ).getCurrentOnboardingData(), + }; } ); @@ -40,18 +34,9 @@ const TheFork = () => { setIsHeaderNavigationEnabled, setFooterActiveView, setHideFooterNav, - updateAllSteps, - updateTopSteps, - updateRoutes, - updateDesignRoutes, - updateInitialize, - setCurrentOnboardingData, } = useDispatch( nfdOnboardingStore ); - const navigate = useNavigate(); - useEffect( () => { - checkHasAiAccess(); setHideFooterNav( true ); setIsHeaderEnabled( false ); setSidebarActiveView( false ); @@ -61,25 +46,6 @@ 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;