Skip to content

Commit

Permalink
Merge pull request #490 from newfold-labs/skip-fork-ai-disabled
Browse files Browse the repository at this point in the history
updated fork: redirect to old flow if ai sitegen is false
  • Loading branch information
officiallygod authored Feb 28, 2024
2 parents d62e789 + 4ac77bd commit 6cfcbde
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
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,7 +10,7 @@ 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';
Expand All @@ -21,13 +21,22 @@ 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 = () => {
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 @@ -37,9 +46,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 @@ -49,6 +67,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
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ describe( 'Get Started Welcome Page', function () {
GetPluginName();
} );

it( 'Check navigation back is visible', () => {
cy.get( '.navigation-buttons_back' ).should('exist');
it( 'Check navigation back is not visible', () => {
cy.get( '.navigation-buttons_back' ).should('not.exist');
} );

it( 'Check if next step loads on clicking navigation next', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ describe( 'Get Started Welcome Page', function () {
GetPluginName();
} );

it( 'Check navigation back is visible', () => {
cy.get( '.navigation-buttons_back' ).should( 'exist' );
it( 'Check navigation back is not visible', () => {
cy.get( '.navigation-buttons_back' ).should( 'not.exist' );
} );

it( 'Check if next step loads on clicking navigation next', () => {
Expand Down

0 comments on commit 6cfcbde

Please sign in to comment.