Skip to content

Commit

Permalink
Merge pull request #531 from newfold-labs/fix/wonder-theme-detection
Browse files Browse the repository at this point in the history
Fix Wonder Theme Initialization
  • Loading branch information
arunshenoy99 authored Apr 4, 2024
2 parents bf86dbe + 4bfac4c commit 10d748b
Showing 1 changed file with 37 additions and 26 deletions.
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 @@ const FlowStateHandler = () => {
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

const handleCommerceFlow = async ( flow, retries = 0 ) => {
if ( retries >= MAX_RETRIES_FLOW_SWITCH ) {
return setNewFlow( false );
Expand Down Expand Up @@ -110,22 +133,10 @@ const FlowStateHandler = () => {
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

0 comments on commit 10d748b

Please sign in to comment.