Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site error page #445

Merged
merged 16 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@
}, [ newfoldBrand ] );
const location = useLocation();

const { currentData, initialize, pluginInstallHash } = useSelect(
( select ) => {
const { currentData, initialize, pluginInstallHash, siteGenErrorStatus } =
useSelect( ( select ) => {
return {
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
initialize: select( nfdOnboardingStore ).getInitialize(),
pluginInstallHash:
select( nfdOnboardingStore ).getPluginInstallHash(),
siteGenErrorStatus:
select( nfdOnboardingStore ).getSiteGenErrorStatus(),
};
}
);
} );

const { setCurrentOnboardingData } = useDispatch( nfdOnboardingStore );
const { setCurrentOnboardingData, updateSiteGenErrorStatus } =
useDispatch( nfdOnboardingStore );

async function syncStoreToDB() {
if ( currentData ) {
Expand All @@ -68,33 +70,35 @@
skipCache,
retryCount = 1
) {
return new Promise( () =>
generateSiteGenMeta( siteInfo, identifier, skipCache )
.then( ( data ) => {
if ( data.body !== null ) {
currentData.sitegen.siteGenMetaStatus.currentStatus += 1;
if (
currentData.sitegen.siteGenMetaStatus
.currentStatus ===
currentData.sitegen.siteGenMetaStatus.totalCount
) {
currentData.sitegen.skipCache = false;
}
setCurrentOnboardingData( currentData );
} else if ( retryCount < MAX_RETRIES_SITE_GEN ) {
performSiteGenMetaGeneration(
siteInfo,
identifier,
skipCache,
retryCount + 1
);
}
} )
.catch( ( err ) => {
/* eslint-disable no-console */
console.log( err );
} )
);
try {
const data = await generateSiteGenMeta(
siteInfo,
identifier,
skipCache
);
if ( data.body !== null ) {
currentData.sitegen.siteGenMetaStatus.currentStatus += 1;
if (
currentData.sitegen.siteGenMetaStatus.currentStatus ===
currentData.sitegen.siteGenMetaStatus.totalCount
) {
currentData.sitegen.skipCache = false;
}
setCurrentOnboardingData( currentData );
}
} catch ( err ) {
if ( retryCount < MAX_RETRIES_SITE_GEN ) {
performSiteGenMetaGeneration(
siteInfo,
identifier,
skipCache,
retryCount + 1
);
} else {
currentData.sitegen.siteGenErrorStatus = true;
updateSiteGenErrorStatus( true );
}
}
}

async function generateSiteGenData() {
Expand All @@ -107,7 +111,6 @@
) {
return;
}

let identifiers = await getSiteGenIdentifiers();
identifiers = identifiers.body;

Expand Down Expand Up @@ -153,14 +156,20 @@
initializePlugins( pluginInstallHash );
setInterval( cronTrigger, 45000 );
}
}, [ initialize ] );

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

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'pluginInstallHash'. Either include it or remove the dependency array

useEffect( () => {
syncStoreToDB();
generateSiteGenData();
handlePreviousStepTracking();
}, [ location.pathname ] );

Check warning on line 165 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 ) {
generateSiteGenData();
}
}, [ siteGenErrorStatus ] );

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

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'generateSiteGenData'. Either include it or remove the dependency array

useEffect( () => {
initializeThemes();
initializeSettings();
Expand Down
23 changes: 23 additions & 0 deletions src/OnboardingSPA/components/SiteGenError/contents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { __ } from '@wordpress/i18n';

const getContents = () => {
return {
heading: __(
"Sorry, we're having trouble communicating with our AI service.",
'wp-module-onboarding'
),
subHeading: __(
'Do you keep getting this error?',
'wp-module-onboarding'
),
message: __(
'If you continue to get this error, you may either continue creating your site without using our AI assistant, or you can ',
'wp-module-onboarding'
),
buttonText: __( 'Try again', 'wp-module-onboarding' ),
buttonSkip: __( 'Continue without AI', 'wp-module-onboarding' ),
buttonExit: __( 'exit to WordPress', 'wp-module-onboarding' ),
};
};

export default getContents;
152 changes: 152 additions & 0 deletions src/OnboardingSPA/components/SiteGenError/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { useViewportMatch } from '@wordpress/compose';
import { useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import getContents from './contents';
import { Button, Fill } from '@wordpress/components';
import { store as nfdOnboardingStore } from '../../store';
import CommonLayout from '../Layouts/Common';
import OrbAnimation from '../OrbAnimation';
import { SITEGEN_FLOW, DEFAULT_FLOW } from '../../data/flows/constants';
import { validateFlow } from '../../data/flows/utils';
import { resolveGetDataForFlow } from '../../data/flows';
import { useNavigate } from 'react-router-dom';
import {
FOOTER_SITEGEN,
FOOTER_END,
HEADER_SITEGEN,
pluginDashboardPage,
} from '../../../constants';

const SiteGenSiteError = () => {
const navigate = useNavigate();
const {
setIsHeaderEnabled,
setSidebarActiveView,
setHeaderActiveView,
setDrawerActiveView,
setHideFooterNav,
setIsHeaderNavigationEnabled,
updateAllSteps,
updateTopSteps,
updateRoutes,
updateDesignRoutes,
updateInitialize,
setCurrentOnboardingData,
updateSiteGenErrorStatus,
} = useDispatch( nfdOnboardingStore );

useEffect( () => {
setHideFooterNav( true );
setIsHeaderEnabled( true );
setSidebarActiveView( false );
setHeaderActiveView( HEADER_SITEGEN );
setIsHeaderNavigationEnabled( true );
setDrawerActiveView( false );
} );

const { brandConfig, currentData } = useSelect( ( select ) => {
return {
brandConfig: select( nfdOnboardingStore ).getNewfoldBrandConfig(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
};
} );
const isLargeViewport = useViewportMatch( 'small' );

const content = getContents();
const oldFlow = window.nfdOnboarding?.oldFlow
? window.nfdOnboarding.oldFlow
: DEFAULT_FLOW;

const switchFlow = ( newFlow ) => {
if ( ! validateFlow( brandConfig, newFlow ) ) {
return false;
}
const currentFlow = window.nfdOnboarding.currentFlow;
const getData = resolveGetDataForFlow( newFlow );
const data = getData();
updateAllSteps( data.steps );
updateTopSteps( data?.topSteps );
updateRoutes( data.routes );
updateDesignRoutes( data?.designRoutes );
if ( SITEGEN_FLOW !== currentFlow ) {
window.nfdOnboarding.oldFlow = currentFlow;
}

window.nfdOnboarding.currentFlow = newFlow;
currentData.activeFlow = newFlow;
setCurrentOnboardingData( currentData );
if ( SITEGEN_FLOW !== newFlow ) {
updateInitialize( true );
}
navigate( data.steps[ 1 ].path );
};
const handleRetry = () => {
updateSiteGenErrorStatus( false );
};
return (
<CommonLayout className="nfd-onboarding-step--site-gen__error">
<div className="nfd-onboarding-step--site-gen__error__container">
<div className="nfd-onboarding-step--site-gen__error__container__orb">
<OrbAnimation height={ `100px` } />
</div>
<div className="nfd-onboarding-step--site-gen__error__container__heading">
<p className="nfd-onboarding-step--site-gen__error__container__heading__text">
{ content.heading }
</p>
</div>
<div className="nfd-onboarding-step--site-gen__error__container__sub-heading">
<p className="nfd-onboarding-step--site-gen__error__container__sub-heading__text">
{ content.subHeading }
</p>
<p className="nfd-onboarding-step--site-gen__error__container__sub-heading__message">
{ content.message }
<a
className="nfd-onboarding-step--site-gen__error__container__sub-heading__exit"
href={ pluginDashboardPage }
>
{ content.buttonExit }
</a>
</p>
</div>
<div className="nfd-onboarding-step--site-gen__error__container__buttons">
<Button
className="nfd-onboarding-step--site-gen__error__container__buttons__skip"
onClick={ () => {
switchFlow( oldFlow );
} }
>
{ content.buttonSkip }
</Button>
{ isLargeViewport ? (
<Button
className="nfd-onboarding-step--site-gen__error__container__buttons__retry"
onClick={ () => {
handleRetry();
} }
>
<p className="nfd-onboarding-button--site-gen-next--text">
{ content.buttonText }
</p>
</Button>
) : (
<Fill name={ `${ FOOTER_SITEGEN }/${ FOOTER_END }` }>
<Button
className="nfd-onboarding-step--site-gen__error__container__buttons__retry"
onClick={ () => {
handleRetry();
} }
>
<p className="nfd-onboarding-button--site-gen-next--text">
{ content.buttonText }
</p>
</Button>
</Fill>
) }
</div>
</div>
</CommonLayout>
);
};

export default SiteGenSiteError;
Loading
Loading