Skip to content

Commit

Permalink
Merge pull request #457 from newfold-labs/fix/duplicate-calls-sitegen
Browse files Browse the repository at this point in the history
Fix duplicate API calls in error state handling
  • Loading branch information
arunshenoy99 authored Feb 9, 2024
2 parents 7d4e4eb + 0b1ee56 commit 33df58e
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from '@wordpress/element';
import { useEffect, useRef } from '@wordpress/element';
import { useLocation } from 'react-router-dom';
import { useSelect, useDispatch } from '@wordpress/data';

Expand Down Expand Up @@ -61,6 +61,8 @@ const SiteGen = () => {
const { setCurrentOnboardingData, updateSiteGenErrorStatus } =
useDispatch( nfdOnboardingStore );

const prevSiteGenErrorStatus = useRef();

async function syncStoreToDB() {
if ( currentData ) {
//Set the Flow Data and sync store and DB
Expand All @@ -72,7 +74,6 @@ const SiteGen = () => {
case SKIP_FLOW_ERROR_CODE_20:
break;
default:
currentData.sitegen.siteGenErrorStatus = true;
updateSiteGenErrorStatus( true );
break;
}
Expand Down Expand Up @@ -111,7 +112,6 @@ const SiteGen = () => {
retryCount + 1
);
} else {
currentData.sitegen.siteGenErrorStatus = true;
updateSiteGenErrorStatus( true );
}
}
Expand Down Expand Up @@ -181,10 +181,11 @@ const SiteGen = () => {
}, [ location.pathname ] );

Check warning on line 181 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData', 'handlePreviousStepTracking', and 'syncStoreToDB'. Either include them or remove the dependency array

useEffect( () => {
if ( ! siteGenErrorStatus ) {
if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) {
generateSiteGenData();
syncStoreToDB();
}
prevSiteGenErrorStatus.current = siteGenErrorStatus;
}, [ siteGenErrorStatus ] );

Check warning on line 189 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has missing dependencies: 'generateSiteGenData' and 'syncStoreToDB'. Either include them or remove the dependency array

useEffect( () => {
Expand Down

0 comments on commit 33df58e

Please sign in to comment.