From 0b1ee5604eb3e2f51619ba31143b382a5ce4ab35 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 9 Feb 2024 19:24:14 +0530 Subject: [PATCH] Fix duplicate API calls in error state handling --- .../components/NewfoldInterfaceSkeleton/SiteGen/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 3a543826d..1b28cdd1c 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -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'; @@ -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 @@ -72,7 +74,6 @@ const SiteGen = () => { case SKIP_FLOW_ERROR_CODE_20: break; default: - currentData.sitegen.siteGenErrorStatus = true; updateSiteGenErrorStatus( true ); break; } @@ -111,7 +112,6 @@ const SiteGen = () => { retryCount + 1 ); } else { - currentData.sitegen.siteGenErrorStatus = true; updateSiteGenErrorStatus( true ); } } @@ -181,10 +181,11 @@ const SiteGen = () => { }, [ location.pathname ] ); useEffect( () => { - if ( ! siteGenErrorStatus ) { + if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) { generateSiteGenData(); syncStoreToDB(); } + prevSiteGenErrorStatus.current = siteGenErrorStatus; }, [ siteGenErrorStatus ] ); useEffect( () => {