Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated fork: redirect to old flow if ai sitegen is false #490

Merged
merged 11 commits into from
Feb 28, 2024
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
Loading