Skip to content

Commit

Permalink
Merge branch 'trunk' into PRESS0-1328-default-to-light-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayadav09 committed May 22, 2024
2 parents 50df3ca + 2cc9877 commit 5f15250
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/OnboardingSPA/components/ErrorState/Step/SiteGen/index.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
Expand All @@ -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 } =
Expand Down Expand Up @@ -100,8 +106,9 @@ const SiteGenStepErrorState = () => {
navigate( data.steps[ 1 ].path );
};

const handleRetry = () => {
const handleRetry = async () => {
updateSiteGenErrorStatus( false );
await setFlow( currentData );
};

const handleGoBack = () => {
Expand Down Expand Up @@ -186,6 +193,7 @@ const SiteGenStepErrorState = () => {
onClick={ () => {
handleRetry();
} }
disabled={ true === disableRetry }
>
<p className="nfd-onboarding-button--site-gen-next--text">
{ content.buttonText }
Expand All @@ -200,6 +208,7 @@ const SiteGenStepErrorState = () => {
onClick={ () => {
handleRetry();
} }
disabled={ true === disableRetry }
>
<p className="nfd-onboarding-button--site-gen-next--text">
{ content.buttonText }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
15 changes: 14 additions & 1 deletion src/OnboardingSPA/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/OnboardingSPA/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit 5f15250

Please sign in to comment.