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

Fix Wonder Theme Initialization #531

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions src/OnboardingSPA/components/StateHandlers/Flow/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
// WordPress
import { useEffect, useState } from '@wordpress/element';
import { useLocation } from 'react-router-dom';
import { useSelect, useDispatch } from '@wordpress/data';
import { getFragment } from '@wordpress/url';

// Third-party
import { useLocation } from 'react-router-dom';
import { HiiveAnalytics } from '@newfold-labs/js-utility-ui-analytics';

import { store as nfdOnboardingStore } from '../../../store';
// Classes and functions
import { switchFlow } from '../../../utils/api/flow';
import { MAX_RETRIES_FLOW_SWITCH } from '../../../../constants';
import {
DEFAULT_FLOW,
ECOMMERCE_FLOW,
SITEGEN_FLOW,
} from '../../../data/flows/constants';
import { removeQueryParam } from '../../../utils';
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 { resolveGetDataForFlow } from '../../../data/flows';

// Components
import EcommerceStepLoader from '../../Loaders/Step/Ecommerce';
import SiteBuild from '../../NewfoldInterfaceSkeleton/SiteBuild';
import SiteGen from '../../NewfoldInterfaceSkeleton/SiteGen';

// Misc
import { store as nfdOnboardingStore } from '../../../store';
import { MAX_RETRIES_FLOW_SWITCH } from '../../../../constants';
import {
DEFAULT_FLOW,
ECOMMERCE_FLOW,
SITEGEN_FLOW,
} from '../../../data/flows/constants';
import { commerce } from '../../../chapters/commerce';
import { stepTheFork } from '../../../steps/TheFork/step';

const FlowStateHandler = () => {
const location = useLocation();
const [ newFlow, setNewFlow ] = useState( false );

const { brandConfig, onboardingFlow } = useSelect( ( select ) => {
Expand All @@ -47,8 +54,24 @@
updateAllSteps,
updateTopSteps,
updateRoutes,
updateInitialize,
} = useDispatch( nfdOnboardingStore );

const location = useLocation();

useEffect( () => {
if ( window.nfdOnboarding?.newFlow ) {
const flow = window.nfdOnboarding.newFlow;
disableNavigation();
setNewFlow( flow );
switchToNewFlow( flow );
window.nfdOnboarding.newFlow = undefined;
} else if ( location.pathname.includes( '/step' ) ) {
setActiveFlow( onboardingFlow );
setActiveStep( location.pathname );
}
}, [ location.pathname ] );

Check warning on line 73 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'disableNavigation', 'onboardingFlow', 'setActiveFlow', 'setActiveStep', and 'switchToNewFlow'. Either include them or remove the dependency array

Check warning on line 73 in src/OnboardingSPA/components/StateHandlers/Flow/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'disableNavigation', 'onboardingFlow', 'setActiveFlow', 'setActiveStep', and 'switchToNewFlow'. Either include them or remove the dependency array

const handleCommerceFlow = async ( flow, retries = 0 ) => {
if ( retries >= MAX_RETRIES_FLOW_SWITCH ) {
return setNewFlow( false );
Expand Down Expand Up @@ -110,22 +133,10 @@
stepTheFork,
] );
updateRoutes( updateRoute.routes );
updateInitialize( true );
}
};

useEffect( () => {
if ( window.nfdOnboarding?.newFlow ) {
const flow = window.nfdOnboarding.newFlow;
disableNavigation();
setNewFlow( flow );
switchToNewFlow( flow );
window.nfdOnboarding.newFlow = undefined;
} else if ( location.pathname.includes( '/step' ) ) {
setActiveFlow( onboardingFlow );
setActiveStep( location.pathname );
}
}, [ location.pathname ] );

// TODO: Remove handleRender and replace with only children once Chapter Prioritization is enabled.
const handleRender = () => {
switch ( newFlow ) {
Expand Down
Loading