Skip to content

Commit

Permalink
added ai capability check in flow state handler
Browse files Browse the repository at this point in the history
  • Loading branch information
girish-lokapure committed Feb 29, 2024
1 parent aa10d23 commit 2f59264
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,19 @@ 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 (
<div className="nfd-onboarding-header__step-navigation">
<ButtonGroup style={ { display: 'flex', columnGap: '0.5rem' } }>
{ isFirstStep || isLastStep ? null : (
<Back
path={ previousStep.path }
showErrorDialog={ showErrorDialog }
disabled={ isDisabled }
disabled={ currentStep === stepWelcome

Check failure on line 139 in src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `·` with `⏎↹↹↹↹↹↹↹`

Check failure on line 139 in src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `·` with `⏎↹↹↹↹↹↹↹`
? currentData.continueWithoutAi

Check failure on line 140 in src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Insert `↹`

Check failure on line 140 in src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Insert `↹`
: false }

Check failure on line 141 in src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `:·false·` with `↹:·false⏎↹↹↹↹↹↹`

Check failure on line 141 in src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `:·false·` with `↹:·false⏎↹↹↹↹↹↹`
/>
) }
{ isLastStep ? (
Expand Down
1 change: 0 additions & 1 deletion src/OnboardingSPA/components/SiteGenError/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/OnboardingSPA/components/StartOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
33 changes: 32 additions & 1 deletion src/OnboardingSPA/components/StateHandlers/Flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 20 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `·validateFlow,·removeFromAllSteps,·removeFromTopSteps,·removeFromRoutes·` with `⏎↹validateFlow,⏎↹removeFromAllSteps,⏎↹removeFromTopSteps,⏎↹removeFromRoutes,⏎`

Check failure on line 20 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `·validateFlow,·removeFromAllSteps,·removeFromTopSteps,·removeFromRoutes·` with `⏎↹validateFlow,⏎↹removeFromAllSteps,⏎↹removeFromTopSteps,⏎↹removeFromRoutes,⏎`
import { resolveGetDataForFlow } from '../../../data/flows';
import { stepTheFork } from '../../../steps/TheFork/step';

const FlowStateHandler = () => {
const location = useLocation();
Expand All @@ -37,6 +39,9 @@ const FlowStateHandler = () => {
setSidebarActiveView,
setActiveFlow,
setActiveStep,
updateAllSteps,
updateTopSteps,
updateRoutes,
} = useDispatch( nfdOnboardingStore );

const handleCommerceFlow = async ( flow, retries = 0 ) => {
Expand Down Expand Up @@ -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(

Check failure on line 92 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `⏎↹↹↹↹data.steps,` with `·data.steps,·[`

Check failure on line 92 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `⏎↹↹↹↹data.steps,` with `·data.steps,·[`
data.steps,
[ stepTheFork ]

Check failure on line 94 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `[·stepTheFork·]` with `stepTheFork,`

Check failure on line 94 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `[·stepTheFork·]` with `stepTheFork,`
);

Check failure on line 95 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Insert `]·`

Check failure on line 95 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Insert `]·`
updateAllSteps( updateAllStep.allSteps );

const updateTopStep = removeFromTopSteps(

Check failure on line 98 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `⏎↹↹↹↹data?.topSteps,` with `·data?.topSteps,·[`

Check failure on line 98 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `⏎↹↹↹↹data?.topSteps,` with `·data?.topSteps,·[`
data?.topSteps,
[ stepTheFork ]

Check failure on line 100 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `[·stepTheFork·]` with `stepTheFork,`

Check failure on line 100 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

Replace `[·stepTheFork·]` with `stepTheFork,`
);
updateTopSteps( updateTopStep.topSteps );

const updateRoute = removeFromRoutes(
data.routes,
[ stepTheFork ]
);
updateRoutes( updateRoute.routes );
}
};

useEffect( () => {
if ( window.nfdOnboarding?.newFlow ) {
const flow = window.nfdOnboarding.newFlow;
Expand All @@ -102,6 +132,7 @@ const FlowStateHandler = () => {
switch ( window.nfdOnboarding.currentFlow ) {
case DEFAULT_FLOW:
case ECOMMERCE_FLOW:
checkCapability();
return <SiteBuild />;
case SITEGEN_FLOW:
return <SiteGen />;
Expand Down
26 changes: 26 additions & 0 deletions src/OnboardingSPA/data/flows/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
),
};
};
28 changes: 0 additions & 28 deletions src/OnboardingSPA/steps/TheFork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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 );
Expand All @@ -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;
Expand Down

0 comments on commit 2f59264

Please sign in to comment.