From 2f59264228ef196c8486671cceb29bd828eaab8f Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Thu, 29 Feb 2024 17:20:44 +0530 Subject: [PATCH 1/2] added ai capability check in flow state handler --- .../SiteBuildHeader/step-navigation.js | 16 +++------ .../components/SiteGenError/index.js | 1 - .../components/StartOptions/index.js | 2 +- .../components/StateHandlers/Flow/index.js | 33 ++++++++++++++++++- src/OnboardingSPA/data/flows/utils.js | 26 +++++++++++++++ src/OnboardingSPA/steps/TheFork/index.js | 28 ---------------- 6 files changed, 63 insertions(+), 43 deletions(-) diff --git a/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js b/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js index 77f33c2ca..eabe62714 100644 --- a/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js +++ b/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js @@ -126,19 +126,9 @@ const StepNavigation = () => { showErrorDialog: select( nfdOnboardingStore ).getShowErrorDialog(), }; }, [] ); - let isFirstStep = null === previousStep || false === previousStep; + const isFirstStep = null === previousStep || false === previousStep; const isLastStep = null === nextStep || false === nextStep; - let isDisabled = false; - if ( currentStep === stepWelcome ) { - if ( currentData.continueWithoutAi === true ) { - isFirstStep = false; - isDisabled = false; - } else { - isFirstStep = true; - } - } - return (
@@ -146,7 +136,9 @@ const StepNavigation = () => { ) } { isLastStep ? ( diff --git a/src/OnboardingSPA/components/SiteGenError/index.js b/src/OnboardingSPA/components/SiteGenError/index.js index ffe239d2b..99cd36188 100644 --- a/src/OnboardingSPA/components/SiteGenError/index.js +++ b/src/OnboardingSPA/components/SiteGenError/index.js @@ -77,7 +77,6 @@ const SiteGenSiteError = () => { window.nfdOnboarding.currentFlow = newFlow; currentData.activeFlow = newFlow; currentData.continueWithoutAi = true; - setContinueWithoutAi( true ); setCurrentOnboardingData( currentData ); updateSiteGenErrorStatus( false ); if ( SITEGEN_FLOW !== newFlow ) { diff --git a/src/OnboardingSPA/components/StartOptions/index.js b/src/OnboardingSPA/components/StartOptions/index.js index 2c9918619..3d400e248 100644 --- a/src/OnboardingSPA/components/StartOptions/index.js +++ b/src/OnboardingSPA/components/StartOptions/index.js @@ -48,7 +48,7 @@ const StartOptions = ( { questionnaire, oldFlow, options } ) => { window.nfdOnboarding.currentFlow = newFlow; currentData.activeFlow = newFlow; - currentData.continueWithoutAi = true; + currentData.continueWithoutAi = false; setCurrentOnboardingData( currentData ); if ( SITEGEN_FLOW !== newFlow ) { updateInitialize( true ); diff --git a/src/OnboardingSPA/components/StateHandlers/Flow/index.js b/src/OnboardingSPA/components/StateHandlers/Flow/index.js index 673daf52a..6d21a54bc 100644 --- a/src/OnboardingSPA/components/StateHandlers/Flow/index.js +++ b/src/OnboardingSPA/components/StateHandlers/Flow/index.js @@ -17,7 +17,9 @@ import { commerce } from '../../../chapters/commerce'; import EcommerceStepLoader from '../../Loaders/Step/Ecommerce'; import SiteBuild from '../../NewfoldInterfaceSkeleton/SiteBuild'; import SiteGen from '../../NewfoldInterfaceSkeleton/SiteGen'; -import { validateFlow } from '../../../data/flows/utils'; +import { validateFlow, removeFromAllSteps, removeFromTopSteps, removeFromRoutes } from '../../../data/flows/utils'; +import { resolveGetDataForFlow } from '../../../data/flows'; +import { stepTheFork } from '../../../steps/TheFork/step'; const FlowStateHandler = () => { const location = useLocation(); @@ -37,6 +39,9 @@ const FlowStateHandler = () => { setSidebarActiveView, setActiveFlow, setActiveStep, + updateAllSteps, + updateTopSteps, + updateRoutes, } = useDispatch( nfdOnboardingStore ); const handleCommerceFlow = async ( flow, retries = 0 ) => { @@ -79,6 +84,31 @@ const FlowStateHandler = () => { setSidebarActiveView( false ); }; + const checkCapability = () => { + if ( ! validateFlow( brandConfig, SITEGEN_FLOW ) ) { + const getData = resolveGetDataForFlow( DEFAULT_FLOW ); + const data = getData(); + + const updateAllStep = removeFromAllSteps( + data.steps, + [ stepTheFork ] + ); + updateAllSteps( updateAllStep.allSteps ); + + const updateTopStep = removeFromTopSteps( + data?.topSteps, + [ stepTheFork ] + ); + updateTopSteps( updateTopStep.topSteps ); + + const updateRoute = removeFromRoutes( + data.routes, + [ stepTheFork ] + ); + updateRoutes( updateRoute.routes ); + } + }; + useEffect( () => { if ( window.nfdOnboarding?.newFlow ) { const flow = window.nfdOnboarding.newFlow; @@ -102,6 +132,7 @@ const FlowStateHandler = () => { switch ( window.nfdOnboarding.currentFlow ) { case DEFAULT_FLOW: case ECOMMERCE_FLOW: + checkCapability(); return ; case SITEGEN_FLOW: return ; diff --git a/src/OnboardingSPA/data/flows/utils.js b/src/OnboardingSPA/data/flows/utils.js index 4fe3d68d0..2736a2a98 100644 --- a/src/OnboardingSPA/data/flows/utils.js +++ b/src/OnboardingSPA/data/flows/utils.js @@ -50,3 +50,29 @@ export const validateFlow = ( brandConfig, flow ) => { } return true; }; + +export const removeFromTopSteps = ( topSteps, conditionalSteps ) => { + const conditionalStepsPaths = new Set( + conditionalSteps.map( ( a ) => a.path ) + ); + + return { + topSteps: filter( + topSteps, + ( topStep ) => ! conditionalStepsPaths.has( topStep.path ) + ), + }; +}; + +export const removeFromRoutes = ( routes, conditionalSteps ) => { + const conditionalStepsPaths = new Set( + conditionalSteps.map( ( a ) => a.path ) + ); + + return { + routes: filter( + routes, + ( route ) => ! conditionalStepsPaths.has( route.path ) + ), + }; +}; diff --git a/src/OnboardingSPA/steps/TheFork/index.js b/src/OnboardingSPA/steps/TheFork/index.js index aef522165..62edd1f41 100644 --- a/src/OnboardingSPA/steps/TheFork/index.js +++ b/src/OnboardingSPA/steps/TheFork/index.js @@ -21,8 +21,6 @@ import { trackOnboardingEvent, } from '../../utils/analytics/hiive'; import { ACTION_SITEGEN_FORK_OPTION_SELECTED } from '../../utils/analytics/hiive/constants'; -import { validateFlow } from '../../data/flows/utils'; -import { resolveGetDataForFlow } from '../../data/flows'; import { useNavigate } from 'react-router-dom'; const TheFork = () => { @@ -46,18 +44,11 @@ const TheFork = () => { setIsHeaderNavigationEnabled, setFooterActiveView, setHideFooterNav, - updateAllSteps, - updateTopSteps, - updateRoutes, - updateDesignRoutes, - updateInitialize, - setCurrentOnboardingData, } = useDispatch( nfdOnboardingStore ); const navigate = useNavigate(); useEffect( () => { - checkHasAiAccess(); setHideFooterNav( true ); setIsHeaderEnabled( false ); setSidebarActiveView( false ); @@ -67,25 +58,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; From b580097a94668fe06ff80ff91ec2f7e9289dc593 Mon Sep 17 00:00:00 2001 From: "lokapure.girish" Date: Thu, 29 Feb 2024 17:39:19 +0530 Subject: [PATCH 2/2] lint --- .../SiteBuildHeader/step-navigation.js | 8 ++++-- .../components/SiteGenError/index.js | 1 - .../components/StateHandlers/Flow/index.js | 28 ++++++++++--------- src/OnboardingSPA/steps/TheFork/index.js | 21 ++++---------- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js b/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js index eabe62714..940c5543e 100644 --- a/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js +++ b/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js @@ -136,9 +136,11 @@ const StepNavigation = () => { ) } { isLastStep ? ( diff --git a/src/OnboardingSPA/components/SiteGenError/index.js b/src/OnboardingSPA/components/SiteGenError/index.js index 99cd36188..788723f94 100644 --- a/src/OnboardingSPA/components/SiteGenError/index.js +++ b/src/OnboardingSPA/components/SiteGenError/index.js @@ -33,7 +33,6 @@ const SiteGenSiteError = () => { updateInitialize, setCurrentOnboardingData, updateSiteGenErrorStatus, - setContinueWithoutAi, } = useDispatch( nfdOnboardingStore ); useEffect( () => { diff --git a/src/OnboardingSPA/components/StateHandlers/Flow/index.js b/src/OnboardingSPA/components/StateHandlers/Flow/index.js index 6d21a54bc..88b095d70 100644 --- a/src/OnboardingSPA/components/StateHandlers/Flow/index.js +++ b/src/OnboardingSPA/components/StateHandlers/Flow/index.js @@ -17,7 +17,12 @@ import { commerce } from '../../../chapters/commerce'; import EcommerceStepLoader from '../../Loaders/Step/Ecommerce'; import SiteBuild from '../../NewfoldInterfaceSkeleton/SiteBuild'; import SiteGen from '../../NewfoldInterfaceSkeleton/SiteGen'; -import { validateFlow, removeFromAllSteps, removeFromTopSteps, removeFromRoutes } from '../../../data/flows/utils'; +import { + validateFlow, + removeFromAllSteps, + removeFromTopSteps, + removeFromRoutes, +} from '../../../data/flows/utils'; import { resolveGetDataForFlow } from '../../../data/flows'; import { stepTheFork } from '../../../steps/TheFork/step'; @@ -89,22 +94,19 @@ const FlowStateHandler = () => { const getData = resolveGetDataForFlow( DEFAULT_FLOW ); const data = getData(); - const updateAllStep = removeFromAllSteps( - data.steps, - [ stepTheFork ] - ); + const updateAllStep = removeFromAllSteps( data.steps, [ + stepTheFork, + ] ); updateAllSteps( updateAllStep.allSteps ); - const updateTopStep = removeFromTopSteps( - data?.topSteps, - [ stepTheFork ] - ); + const updateTopStep = removeFromTopSteps( data?.topSteps, [ + stepTheFork, + ] ); updateTopSteps( updateTopStep.topSteps ); - const updateRoute = removeFromRoutes( - data.routes, - [ stepTheFork ] - ); + const updateRoute = removeFromRoutes( data.routes, [ + stepTheFork, + ] ); updateRoutes( updateRoute.routes ); } }; diff --git a/src/OnboardingSPA/steps/TheFork/index.js b/src/OnboardingSPA/steps/TheFork/index.js index 62edd1f41..81dcfbc8b 100644 --- a/src/OnboardingSPA/steps/TheFork/index.js +++ b/src/OnboardingSPA/steps/TheFork/index.js @@ -10,7 +10,7 @@ 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'; @@ -21,20 +21,13 @@ 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, brandConfig, currentData } = useSelect( - ( select ) => { - return { - migrationUrl: select( nfdOnboardingStore ).getMigrationUrl(), - brandConfig: - select( nfdOnboardingStore ).getNewfoldBrandConfig(), - currentData: - select( nfdOnboardingStore ).getCurrentOnboardingData(), - }; - } - ); + const { migrationUrl } = useSelect( ( select ) => { + return { + migrationUrl: select( nfdOnboardingStore ).getMigrationUrl(), + }; + } ); const { setIsHeaderEnabled, @@ -46,8 +39,6 @@ const TheFork = () => { setHideFooterNav, } = useDispatch( nfdOnboardingStore ); - const navigate = useNavigate(); - useEffect( () => { setHideFooterNav( true ); setIsHeaderEnabled( false );