From 37fada5b3960de55ce17b2f4753800fc661fb94c Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 13 May 2024 16:46:05 +0530 Subject: [PATCH 1/8] Use the new SiteGenErrorMeta object --- src/OnboardingSPA/store/reducer.js | 10 +++++++++- src/OnboardingSPA/store/selectors.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/store/reducer.js b/src/OnboardingSPA/store/reducer.js index f4c36a80a..6bd66b5f3 100644 --- a/src/OnboardingSPA/store/reducer.js +++ b/src/OnboardingSPA/store/reducer.js @@ -187,7 +187,15 @@ export function data( state = {}, action ) { ...state.flowData, sitegen: { ...state.flowData.sitegen, - siteGenErrorStatus: action.siteGenErrorStatus, + siteGenErrorMeta: { + status: action.siteGenErrorStatus, + retryCount: + true === action.siteGenErrorStatus + ? 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 ) { From d95c8b68cec23bea6a6da6fc25dd8820a90256f8 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 13 May 2024 16:50:19 +0530 Subject: [PATCH 2/8] Linttt --- src/OnboardingSPA/store/reducer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/store/reducer.js b/src/OnboardingSPA/store/reducer.js index 6bd66b5f3..7536b7e8b 100644 --- a/src/OnboardingSPA/store/reducer.js +++ b/src/OnboardingSPA/store/reducer.js @@ -192,9 +192,9 @@ export function data( state = {}, action ) { retryCount: true === action.siteGenErrorStatus ? state.flowData.sitegen.siteGenErrorMeta - .retryCount + 1 + .retryCount + 1 : state.flowData.sitegen.siteGenErrorMeta - .retryCount, + .retryCount, }, }, }, From cddeaef6faf89f608f88dd90a278d61d00355002 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 14 May 2024 13:02:00 +0530 Subject: [PATCH 3/8] Use maxRetryCount from backend --- .../components/ErrorState/Step/SiteGen/index.js | 8 +++++++- src/OnboardingSPA/store/reducer.js | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js index 8076c124a..680be6517 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'; @@ -31,6 +31,7 @@ import { const SiteGenStepErrorState = () => { const navigate = useNavigate(); const isLargeViewport = useViewportMatch( 'small' ); + const [ disableRetry, setDisableRetry ] = useState( false ); const { setIsHeaderEnabled, @@ -55,6 +56,10 @@ const SiteGenStepErrorState = () => { setIsHeaderNavigationEnabled( true ); setDrawerActiveView( false ); setSidebarActiveView( false ); + setDisableRetry( + currentData.sitegen.siteGenErrorMeta.retryCount >= + currentData.sitegen.siteGenErrorMeta.maxRetryCount + ); }, [] ); const { brandConfig, currentData, currentStep, previousStep, allSteps } = @@ -186,6 +191,7 @@ const SiteGenStepErrorState = () => { onClick={ () => { handleRetry(); } } + disabled={ true === disableRetry } >

{ content.buttonText } diff --git a/src/OnboardingSPA/store/reducer.js b/src/OnboardingSPA/store/reducer.js index 7536b7e8b..070c4bf60 100644 --- a/src/OnboardingSPA/store/reducer.js +++ b/src/OnboardingSPA/store/reducer.js @@ -188,6 +188,7 @@ export function data( state = {}, action ) { sitegen: { ...state.flowData.sitegen, siteGenErrorMeta: { + ...state.flowData.sitegen.siteGenErrorMeta, status: action.siteGenErrorStatus, retryCount: true === action.siteGenErrorStatus From 762c2c82089ff7d79f8d20cf69db7556026eef26 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 15 May 2024 12:16:02 +0530 Subject: [PATCH 4/8] Update index.js --- src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js index 680be6517..2abd77710 100644 --- a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js +++ b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js @@ -57,8 +57,8 @@ const SiteGenStepErrorState = () => { setDrawerActiveView( false ); setSidebarActiveView( false ); setDisableRetry( - currentData.sitegen.siteGenErrorMeta.retryCount >= - currentData.sitegen.siteGenErrorMeta.maxRetryCount + currentData.sitegen?.siteGenErrorMeta?.retryCount >= + currentData.sitegen?.siteGenErrorMeta?.maxRetryCount ); }, [] ); From 58f528ae701f4b76ea121a23435e917e2a821f85 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 17 May 2024 10:30:40 +0530 Subject: [PATCH 5/8] Fix Mobile Screen Issue --- src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js index 2abd77710..8f957f5b8 100644 --- a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js +++ b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js @@ -206,6 +206,7 @@ const SiteGenStepErrorState = () => { onClick={ () => { handleRetry(); } } + disabled={ true === disableRetry } >

{ content.buttonText } From ade0450800bf1dfb7b5826e8d02e5ef5390a6a48 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 17 May 2024 11:03:07 +0530 Subject: [PATCH 6/8] Code Review Comments --- .../components/ErrorState/Step/SiteGen/index.js | 2 +- src/OnboardingSPA/store/reducer.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js index 8f957f5b8..9d2ebccee 100644 --- a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js +++ b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js @@ -57,7 +57,7 @@ const SiteGenStepErrorState = () => { setDrawerActiveView( false ); setSidebarActiveView( false ); setDisableRetry( - currentData.sitegen?.siteGenErrorMeta?.retryCount >= + currentData.sitegen?.siteGenErrorMeta?.retryCount > currentData.sitegen?.siteGenErrorMeta?.maxRetryCount ); }, [] ); diff --git a/src/OnboardingSPA/store/reducer.js b/src/OnboardingSPA/store/reducer.js index 070c4bf60..4e5ad5435 100644 --- a/src/OnboardingSPA/store/reducer.js +++ b/src/OnboardingSPA/store/reducer.js @@ -181,6 +181,10 @@ 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: { @@ -191,11 +195,11 @@ export function data( state = {}, action ) { ...state.flowData.sitegen.siteGenErrorMeta, status: action.siteGenErrorStatus, retryCount: - true === action.siteGenErrorStatus + shouldUpdateRetryCount === true ? state.flowData.sitegen.siteGenErrorMeta - .retryCount + 1 + .retryCount + 1 : state.flowData.sitegen.siteGenErrorMeta - .retryCount, + .retryCount, }, }, }, From c9458947fe1cc9ef3bffdfc0bbb88034ddd8d4ef Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 17 May 2024 11:09:59 +0530 Subject: [PATCH 7/8] Update reducer.js --- src/OnboardingSPA/store/reducer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/store/reducer.js b/src/OnboardingSPA/store/reducer.js index 4e5ad5435..4cc0ddefb 100644 --- a/src/OnboardingSPA/store/reducer.js +++ b/src/OnboardingSPA/store/reducer.js @@ -197,9 +197,9 @@ export function data( state = {}, action ) { retryCount: shouldUpdateRetryCount === true ? state.flowData.sitegen.siteGenErrorMeta - .retryCount + 1 + .retryCount + 1 : state.flowData.sitegen.siteGenErrorMeta - .retryCount, + .retryCount, }, }, }, From 90c6d400389ed77ccea8e83538246910f3198748 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 17 May 2024 18:52:35 +0530 Subject: [PATCH 8/8] Changes to ensure refresh doesn't bypass things --- .../components/ErrorState/Step/SiteGen/index.js | 4 +++- .../components/NewfoldInterfaceSkeleton/SiteGen/index.js | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js index 9d2ebccee..ef56822cd 100644 --- a/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js +++ b/src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js @@ -27,6 +27,7 @@ import { HEADER_SITEGEN, pluginDashboardPage, } from '../../../../../constants'; +import { setFlow } from '../../../../utils/api/flow'; const SiteGenStepErrorState = () => { const navigate = useNavigate(); @@ -105,8 +106,9 @@ const SiteGenStepErrorState = () => { navigate( data.steps[ 1 ].path ); }; - const handleRetry = () => { + const handleRetry = async () => { updateSiteGenErrorStatus( false ); + await setFlow( currentData ); }; const handleGoBack = () => { 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 ) {