diff --git a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js index 8076c124a..ef56822cd 100644 --- a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js +++ b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js @@ -1,6 +1,6 @@ // WordPress import { useViewportMatch } from '@wordpress/compose'; -import { useEffect } from '@wordpress/element'; +import { useState, useEffect } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; import { Button, Fill } from '@wordpress/components'; @@ -27,10 +27,12 @@ import { HEADER_SITEGEN, pluginDashboardPage, } from '../../../../../constants'; +import { setFlow } from '../../../../utils/api/flow'; const SiteGenStepErrorState = () => { const navigate = useNavigate(); const isLargeViewport = useViewportMatch( 'small' ); + const [ disableRetry, setDisableRetry ] = useState( false ); const { setIsHeaderEnabled, @@ -55,6 +57,10 @@ const SiteGenStepErrorState = () => { setIsHeaderNavigationEnabled( true ); setDrawerActiveView( false ); setSidebarActiveView( false ); + setDisableRetry( + currentData.sitegen?.siteGenErrorMeta?.retryCount > + currentData.sitegen?.siteGenErrorMeta?.maxRetryCount + ); }, [] ); const { brandConfig, currentData, currentStep, previousStep, allSteps } = @@ -100,8 +106,9 @@ const SiteGenStepErrorState = () => { navigate( data.steps[ 1 ].path ); }; - const handleRetry = () => { + const handleRetry = async () => { updateSiteGenErrorStatus( false ); + await setFlow( currentData ); }; const handleGoBack = () => { @@ -186,6 +193,7 @@ const SiteGenStepErrorState = () => { onClick={ () => { handleRetry(); } } + disabled={ true === disableRetry } >

{ content.buttonText } @@ -200,6 +208,7 @@ const SiteGenStepErrorState = () => { onClick={ () => { handleRetry(); } } + disabled={ true === disableRetry } >

{ content.buttonText } diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index e1b0f14c6..420290866 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -261,6 +261,15 @@ const SiteGen = () => { return; } + // If retries are exhausted don't make requests + if ( + currentData.sitegen?.siteGenErrorMeta?.retryCount >= + currentData.sitegen?.siteGenErrorMeta?.maxRetryCount + ) { + updateSiteGenErrorStatus( true ); + return; + } + setIsGeneratingSiteMeta( true ); if ( ! window.nfdOnboarding?.siteGenTimerInterval ) { diff --git a/src/OnboardingSPA/store/reducer.js b/src/OnboardingSPA/store/reducer.js index f4c36a80a..4cc0ddefb 100644 --- a/src/OnboardingSPA/store/reducer.js +++ b/src/OnboardingSPA/store/reducer.js @@ -181,13 +181,26 @@ export function data( state = {}, action ) { }; case 'SET_SITEGEN_AI_ERROR_STATUS': + // Only update if the prev value was false and now there is an error else don't + const shouldUpdateRetryCount = + ! state.flowData.sitegen.siteGenErrorMeta.status && + action.siteGenErrorStatus; return { ...state, flowData: { ...state.flowData, sitegen: { ...state.flowData.sitegen, - siteGenErrorStatus: action.siteGenErrorStatus, + siteGenErrorMeta: { + ...state.flowData.sitegen.siteGenErrorMeta, + status: action.siteGenErrorStatus, + retryCount: + shouldUpdateRetryCount === true + ? state.flowData.sitegen.siteGenErrorMeta + .retryCount + 1 + : state.flowData.sitegen.siteGenErrorMeta + .retryCount, + }, }, }, }; diff --git a/src/OnboardingSPA/store/selectors.js b/src/OnboardingSPA/store/selectors.js index 7bc818005..ad8751886 100644 --- a/src/OnboardingSPA/store/selectors.js +++ b/src/OnboardingSPA/store/selectors.js @@ -451,7 +451,7 @@ export function getCustomizeSidebarData( state ) { } export function getSiteGenErrorStatus( state ) { - return state.data.flowData.sitegen.siteGenErrorStatus; + return state.data.flowData.sitegen.siteGenErrorMeta.status; } export function getInteractionDisabled( state ) {