diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js
index c30791eb9..e1b0f14c6 100644
--- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js
+++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js
@@ -1,36 +1,44 @@
+// WordPress
import { useEffect, useRef, useState } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
-import { useLocation } from 'react-router-dom';
import { useSelect, useDispatch } from '@wordpress/data';
-import Header from '../../Header';
-import Content from '../../Content';
-import Sidebar from '../../Sidebar';
-import themeToggleHOC from '../themeToggleHOC';
-import NewfoldInterfaceSkeleton from '../index';
-import { ThemeProvider } from '../../ThemeContextProvider';
-import { store as nfdOnboardingStore } from '../../../store';
+// Third-party
+import { useLocation } from 'react-router-dom';
import classNames from 'classnames';
+
+// Classes and functions
import { setFlow } from '../../../utils/api/flow';
+import themeToggleHOC from '../themeToggleHOC';
import {
generateSiteGenMeta,
getHomepages,
getSiteGenIdentifiers,
} from '../../../utils/api/siteGen';
-import Footer from '../../Footer';
import { initialize as initializeSettings } from '../../../utils/api/settings';
import { init as initializePlugins } from '../../../utils/api/plugins';
import { init as initializeThemes } from '../../../utils/api/themes';
import { trigger as cronTrigger } from '../../../utils/api/cronTrigger';
+import {
+ OnboardingEvent,
+ trackOnboardingEvent,
+} from '../../../utils/analytics/hiive';
+
+// Components
+import Header from '../../Header';
+import Content from '../../Content';
+import Sidebar from '../../Sidebar';
+import Footer from '../../Footer';
+import NewfoldInterfaceSkeleton from '../index';
+import { ThemeProvider } from '../../ThemeContextProvider';
+
+// Misc
+import { store as nfdOnboardingStore } from '../../../store';
import {
MAX_RETRIES_SITE_GEN,
SKIP_FLOW_ERROR_CODE_DATABASE,
SKIP_FLOW_ERROR_CODE_20,
} from '../../../../constants';
-import {
- OnboardingEvent,
- trackOnboardingEvent,
-} from '../../../utils/analytics/hiive';
import {
ACTION_ONBOARDING_CHAPTER_COMPLETE,
ACTION_ONBOARDING_CHAPTER_STARTED,
@@ -46,8 +54,8 @@ const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
);
const SiteGen = () => {
- const [ failedApi, setFailedApi ] = useState( [] );
- const location = useLocation();
+ const [ failedSiteMetaAPIs, setFailedSiteMetaAPIs ] = useState( [] );
+ const [ isGeneratingSiteMeta, setIsGeneratingSiteMeta ] = useState( false );
const {
currentData,
@@ -79,35 +87,73 @@ const SiteGen = () => {
setCurrentOnboardingData,
updateSiteGenErrorStatus,
setActiveChapter,
+ setIsGeneratingHomepages,
} = useDispatch( nfdOnboardingStore );
- // Update Title and Tagline on the site.
- const { editEntityRecord } = useDispatch( coreStore );
const { getEditedEntityRecord } = useSelect( ( select ) => {
return select( coreStore );
}, [] );
+ const { editEntityRecord } = useDispatch( coreStore );
+
+ const location = useLocation();
+ const prevSiteGenErrorStatus = useRef();
+
+ useEffect( () => {
+ initializeThemes();
+ initializeSettings();
+ getEditedEntityRecord( 'root', 'site' );
+ }, [] );
+
useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
}, [ newfoldBrand ] );
- const prevSiteGenErrorStatus = useRef();
+ useEffect( () => {
+ trackChapters();
+ }, [ currentStep ] );
+
+ useEffect( () => {
+ if ( initialize ) {
+ initializePlugins( pluginInstallHash );
+ setInterval( cronTrigger, 45000 );
+ }
+ }, [ initialize ] );
+
+ useEffect( () => {
+ syncStoreToDB();
+ generateSiteGenData();
+ handlePreviousStepTracking();
+ }, [ location.pathname ] );
+
+ useEffect( () => {
+ if (
+ prevSiteGenErrorStatus.current === true &&
+ siteGenErrorStatus === false
+ ) {
+ generateSiteGenData();
+ }
+ prevSiteGenErrorStatus.current = siteGenErrorStatus;
+ }, [ siteGenErrorStatus ] );
async function syncStoreToDB() {
// The First Fork Step doesn't have any Store changes
if ( currentData && location?.pathname !== stepTheFork.path ) {
//Set the Flow Data and sync store and DB
const result = await setFlow( currentData );
- if ( result?.error !== null ) {
- switch ( result?.error.code ) {
- case SKIP_FLOW_ERROR_CODE_DATABASE:
- break;
- case SKIP_FLOW_ERROR_CODE_20:
- break;
- default:
- updateSiteGenErrorStatus( true );
- break;
- }
+ if ( result.body !== null ) {
+ return true;
+ }
+
+ switch ( result.error.code ) {
+ case SKIP_FLOW_ERROR_CODE_DATABASE:
+ case SKIP_FLOW_ERROR_CODE_20:
+ return true;
+ }
+
+ if ( false === siteGenErrorStatus ) {
+ updateSiteGenErrorStatus( true );
+ return false;
}
}
}
@@ -118,49 +164,13 @@ const SiteGen = () => {
skipCache,
retryCount = 1
) {
- try {
- const data = await generateSiteGenMeta(
- siteInfo,
- identifier,
- skipCache
- );
- if ( data !== null ) {
- // A Identifier request was sucessfuly made with valid response
- currentData.sitegen.siteGenMetaStatus.currentStatus += 1;
- if (
- currentData.sitegen.siteGenMetaStatus.currentStatus ===
- currentData.sitegen.siteGenMetaStatus.totalCount
- ) {
- // Once all requests are completed use cache to get data
- currentData.sitegen.skipCache = false;
-
- // Increase count after site meta calls to ensure systematic call of homepages
- currentData.sitegen.siteGenMetaStatus.totalCount += 1;
- setCurrentOnboardingData( currentData );
-
- // Get the homepages and set that in flow
- getHomepages( currentData.sitegen.siteDetails.prompt ).then(
- ( response ) => {
- if ( response.body ) {
- currentData.sitegen.homepages.data =
- response.body;
- }
- currentData.sitegen.siteGenMetaStatus.currentStatus += 1;
- }
- );
- }
- // Sync the current request changed to State
- setCurrentOnboardingData( currentData );
+ const data = await generateSiteGenMeta(
+ siteInfo,
+ identifier,
+ skipCache
+ );
- // Sets the Site Title and Taglin in Live Preview
- if ( identifier === 'site_config' ) {
- editEntityRecord( 'root', 'site', undefined, {
- title: data.site_title,
- description: data.tagline,
- } );
- }
- }
- } catch ( err ) {
+ if ( data.error ) {
// Check if it failed then retry again
if ( retryCount < MAX_RETRIES_SITE_GEN ) {
return performSiteGenMetaGeneration(
@@ -172,25 +182,74 @@ const SiteGen = () => {
}
// If the retry also did not work show the error state
- setFailedApi( ( prevState ) => {
+ setFailedSiteMetaAPIs( ( prevState ) => {
// If the error doesn't exist add it to the Failed List
if ( ! prevState.includes( identifier ) ) {
return [ ...prevState, identifier ];
}
+
return prevState;
} );
- // Activate the Error Page
- currentData.sitegen.siteGenErrorStatus = true;
- setCurrentOnboardingData( currentData );
+
+ if ( siteGenErrorStatus === false ) {
+ updateSiteGenErrorStatus( true );
+ setIsGeneratingSiteMeta( false );
+ }
+
+ if ( window.nfdOnboarding.siteGenTimerInterval ) {
+ clearInterval( window.nfdOnboarding.siteGenTimerInterval );
+ }
+
+ return;
}
- }
- async function generateSiteGenData( forceRun = false ) {
- // ForceRun tells us to bypass the page check or not
- // because the requests failed on Logo step is retried in Experience step
+ // Sets the Site Title and Taglin in Live Preview
+ if ( identifier === 'site_config' ) {
+ editEntityRecord( 'root', 'site', undefined, {
+ title: data.body.site_title,
+ description: data.body.tagline,
+ } );
+ }
+
+ // A Identifier request was successfully made with valid response
+ currentData.sitegen.siteGenMetaStatus.currentStatus += 1;
+
+ if (
+ currentData.sitegen.siteGenMetaStatus.currentStatus ===
+ currentData.sitegen.siteGenMetaStatus.totalCount
+ ) {
+ // Once all requests are completed use cache to get data
+ currentData.sitegen.skipCache = false;
+ setIsGeneratingSiteMeta( false );
+ // Increase count after site meta calls to ensure systematic call of homepages
+ // Get the homepages and set that in flow
+ setIsGeneratingHomepages( true );
+ const response = await getHomepages(
+ currentData.sitegen.siteDetails.prompt
+ );
+ if ( response.error ) {
+ updateSiteGenErrorStatus( true );
+ setIsGeneratingHomepages( false );
+ setCurrentOnboardingData( currentData );
+ return;
+ }
+
+ currentData.sitegen.homepages.data = response.body;
+ setIsGeneratingHomepages( false );
+ }
+ // Sync the current request changed to State
+ setCurrentOnboardingData( currentData );
+ }
+
+ async function generateSiteGenData() {
// Start the API Requests when the loader is shown.
- if ( ! location.pathname.includes( 'site-logo' ) && ! forceRun ) {
+ if (
+ true === siteGenErrorStatus ||
+ true === isGeneratingSiteMeta ||
+ ( ! location.pathname.includes( 'site-logo' ) &&
+ ! location.pathname.includes( 'experience' ) )
+ ) {
return;
}
@@ -202,6 +261,8 @@ const SiteGen = () => {
return;
}
+ setIsGeneratingSiteMeta( true );
+
if ( ! window.nfdOnboarding?.siteGenTimerInterval ) {
window.nfdOnboarding.siteGenTime = 0;
window.nfdOnboarding.siteGenTimerInterval = setInterval( () => {
@@ -210,9 +271,12 @@ const SiteGen = () => {
}
let identifiers;
- if ( Array.isArray( failedApi ) && failedApi.length > 0 ) {
- identifiers = failedApi;
- setFailedApi( [] );
+ if (
+ Array.isArray( failedSiteMetaAPIs ) &&
+ failedSiteMetaAPIs.length > 0
+ ) {
+ identifiers = failedSiteMetaAPIs;
+ setFailedSiteMetaAPIs( [] );
} else {
identifiers = await getSiteGenIdentifiers();
identifiers = identifiers.body;
@@ -293,41 +357,6 @@ const SiteGen = () => {
}
};
- useEffect( () => {
- trackChapters();
- }, [ currentStep ] );
-
- useEffect( () => {
- if ( initialize ) {
- initializePlugins( pluginInstallHash );
- setInterval( cronTrigger, 45000 );
- }
- }, [ initialize ] );
-
- useEffect( () => {
- syncStoreToDB();
- generateSiteGenData();
- handlePreviousStepTracking();
- }, [ location.pathname ] );
-
- useEffect( () => {
- if (
- prevSiteGenErrorStatus.current === true &&
- siteGenErrorStatus === false
- ) {
- generateSiteGenData( true );
- syncStoreToDB();
- }
- prevSiteGenErrorStatus.current = siteGenErrorStatus;
- }, [ siteGenErrorStatus ] );
-
- useEffect( () => {
- initializeThemes();
- initializeSettings();
- getEditedEntityRecord( 'root', 'site' );
- updateSiteGenErrorStatus( false );
- }, [] );
-
return (
{
+const SiteGenStateHandler = ( { children } ) => {
const { siteGenErrorStatus } = useSelect( ( select ) => {
return {
siteGenErrorStatus:
@@ -20,7 +25,7 @@ const SitegenAiStateHandler = ( { children } ) => {
} );
useEffect( () => {
- if ( siteGenErrorStatus === true ) {
+ if ( true === siteGenErrorStatus ) {
trackOnboardingEvent(
new OnboardingEvent(
ACTION_SITEGEN_ERROR_STATE_TRIGGERED,
@@ -35,7 +40,7 @@ const SitegenAiStateHandler = ( { children } ) => {
const handleRender = () => {
if ( siteGenErrorStatus ) {
- return ;
+ return ;
}
return children;
@@ -43,4 +48,4 @@ const SitegenAiStateHandler = ( { children } ) => {
return { handleRender() };
};
-export default SitegenAiStateHandler;
+export default SiteGenStateHandler;
diff --git a/src/OnboardingSPA/components/StateHandlers/index.js b/src/OnboardingSPA/components/StateHandlers/index.js
index b18f3eb9a..f4d0967be 100644
--- a/src/OnboardingSPA/components/StateHandlers/index.js
+++ b/src/OnboardingSPA/components/StateHandlers/index.js
@@ -1 +1,3 @@
export { default as DesignStateHandler } from './Design';
+export { default as FlowStateHandler } from './Flow';
+export { default as SiteGenStateHandler } from './SiteGen';
diff --git a/src/OnboardingSPA/steps/SiteGen/Experience/index.js b/src/OnboardingSPA/steps/SiteGen/Experience/index.js
index 6be5ffaca..204f1318d 100644
--- a/src/OnboardingSPA/steps/SiteGen/Experience/index.js
+++ b/src/OnboardingSPA/steps/SiteGen/Experience/index.js
@@ -1,29 +1,36 @@
+// WordPress
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
+// Classes and functions
import getContents from './contents';
-import { HEADER_SITEGEN } from '../../../../constants';
-import { store as nfdOnboardingStore } from '../../../store';
-import CommonLayout from '../../../components/Layouts/Common';
-import CardWithOptions from '../../../components/CardWithOptions';
-import SiteGenLoader from '../../../components/Loaders/SiteGenLoader';
-import SitegenAiStateHandler from '../../../components/StateHandlers/SitegenAi';
import {
OnboardingEvent,
trackOnboardingEvent,
} from '../../../utils/analytics/hiive';
+
+// Components
+import CommonLayout from '../../../components/Layouts/Common';
+import CardWithOptions from '../../../components/CardWithOptions';
+import SiteGenLoader from '../../../components/Loaders/SiteGenLoader';
+import { SiteGenStateHandler } from '../../../components/StateHandlers';
+
+// Misc
+import { HEADER_SITEGEN } from '../../../../constants';
+import { store as nfdOnboardingStore } from '../../../store';
import { ACTION_EXPERIENCE_LEVEL_SET } from '../../../utils/analytics/hiive/constants';
import { SITEGEN_FLOW } from '../../../data/flows/constants';
const SiteGenExperience = () => {
- const content = getContents();
// Index of the selection user makes
const [ selection, setSelection ] = useState( 0 );
- const { currentData } = useSelect( ( select ) => {
+ const { currentData, siteGenErrorStatus } = useSelect( ( select ) => {
return {
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
+ siteGenErrorStatus:
+ select( nfdOnboardingStore ).getSiteGenErrorStatus(),
};
} );
@@ -44,11 +51,17 @@ const SiteGenExperience = () => {
setIsHeaderNavigationEnabled( false );
setHeaderActiveView( HEADER_SITEGEN );
setDrawerActiveView( false );
+ }, [] );
+
+ useEffect( () => {
+ if ( true === siteGenErrorStatus ) {
+ return;
+ }
if ( currentData.sitegen.experience?.level ) {
setSelection( currentData.sitegen.experience.level );
}
- } );
+ }, [ siteGenErrorStatus ] );
const checkAndNavigate = ( idx ) => {
// 0 - Not Selected
@@ -83,8 +96,10 @@ const SiteGenExperience = () => {
}
};
+ const content = getContents();
+
return (
-
+
{
/>
-
+
);
};
diff --git a/src/OnboardingSPA/steps/SiteGen/Preview/index.js b/src/OnboardingSPA/steps/SiteGen/Preview/index.js
index de1ef8720..d95c54be4 100644
--- a/src/OnboardingSPA/steps/SiteGen/Preview/index.js
+++ b/src/OnboardingSPA/steps/SiteGen/Preview/index.js
@@ -1,24 +1,33 @@
+// WordPress
import { useEffect, useState, useRef } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
+
+// Third-party
import { useNavigate } from 'react-router-dom';
// eslint-disable-next-line import/no-extraneous-dependencies
import { cloneDeep, isEmpty } from 'lodash';
-import CommonLayout from '../../../components/Layouts/Common';
-import { store as nfdOnboardingStore } from '../../../store';
-import { HEADER_SITEGEN, THEME_STATUS_ACTIVE } from '../../../../constants';
-import { SiteGenPreviewSelectableCard } from '../../../components/LivePreview';
+// Classes and functions
import getContents from './contents';
-import HeartAnimation from './heartAnimation';
-import RegeneratingSiteCard from './regeneratingCard';
import { getHomepages, regenerateHomepage } from '../../../utils/api/siteGen';
import { getGlobalStyles } from '../../../utils/api/themes';
-import SitegenAiStateHandler from '../../../components/StateHandlers/SitegenAi';
-import Animate from '../../../components/Animate';
import {
OnboardingEvent,
trackOnboardingEvent,
} from '../../../utils/analytics/hiive';
+
+// Components
+import CommonLayout from '../../../components/Layouts/Common';
+import { SiteGenPreviewSelectableCard } from '../../../components/LivePreview';
+import HeartAnimation from './heartAnimation';
+import RegeneratingSiteCard from './regeneratingCard';
+import Animate from '../../../components/Animate';
+import {
+ DesignStateHandler,
+ SiteGenStateHandler,
+} from '../../../components/StateHandlers';
+
+// Misc
import {
ACTION_SITEGEN_HOMEPAGE_FAVORITED,
ACTION_SITEGEN_HOMEPAGE_REGENERATED,
@@ -26,29 +35,18 @@ import {
ACTION_SITEGEN_SITE_GENERATION_TIME,
} from '../../../utils/analytics/hiive/constants';
import { SITEGEN_FLOW } from '../../../data/flows/constants';
-import { DesignStateHandler } from '../../../components/StateHandlers';
+import { store as nfdOnboardingStore } from '../../../store';
+import { HEADER_SITEGEN, THEME_STATUS_ACTIVE } from '../../../../constants';
const SiteGenPreview = () => {
- const navigate = useNavigate();
const [ homepages, setHomepages ] = useState( false );
const [ isRegenerating, setIsRegenerating ] = useState( false );
const [ isPreviewLoading, setIsPreviewLoading ] = useState( false );
const [ globalStyles, setGlobalStyles ] = useState( false );
+ const navigate = useNavigate();
const prevSiteGenErrorStatus = useRef();
- const {
- setIsHeaderEnabled,
- setSidebarActiveView,
- setHeaderActiveView,
- setDrawerActiveView,
- setCurrentOnboardingData,
- updateInitialize,
- setHideFooterNav,
- updateSiteGenErrorStatus,
- setIsHeaderNavigationEnabled,
- } = useDispatch( nfdOnboardingStore );
-
const { currentData, nextStep, siteGenErrorStatus, themeStatus } =
useSelect( ( select ) => {
return {
@@ -61,6 +59,18 @@ const SiteGenPreview = () => {
};
} );
+ const {
+ setIsHeaderEnabled,
+ setSidebarActiveView,
+ setHeaderActiveView,
+ setDrawerActiveView,
+ setCurrentOnboardingData,
+ updateInitialize,
+ setHideFooterNav,
+ updateSiteGenErrorStatus,
+ setIsHeaderNavigationEnabled,
+ } = useDispatch( nfdOnboardingStore );
+
useEffect( () => {
setIsHeaderEnabled( true );
setHideFooterNav( true );
@@ -68,8 +78,7 @@ const SiteGenPreview = () => {
setHeaderActiveView( HEADER_SITEGEN );
setDrawerActiveView( false );
updateInitialize( true );
- setIsHeaderNavigationEnabled( false );
- }, [ currentData ] );
+ }, [] );
useEffect( () => {
if (
@@ -78,6 +87,7 @@ const SiteGenPreview = () => {
) {
loadHomepages();
loadGlobalStyles();
+ setIsHeaderNavigationEnabled( false );
}
prevSiteGenErrorStatus.current = siteGenErrorStatus;
}, [ siteGenErrorStatus ] );
@@ -297,8 +307,8 @@ const SiteGenPreview = () => {
const content = getContents();
return (
-
-
+
+
{ ! isPreviewLoading && (
@@ -330,8 +340,8 @@ const SiteGenPreview = () => {
{ content.favouriteNote }
-
-
+
+
);
};
diff --git a/src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js b/src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js
index de6343386..2b324d0ed 100644
--- a/src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js
+++ b/src/OnboardingSPA/steps/SiteGen/SiteDetails/index.js
@@ -1,29 +1,34 @@
+// WordPress
import { useViewportMatch } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';
+// Classes and functions
+import {
+ OnboardingEvent,
+ trackOnboardingEvent,
+} from '../../../utils/analytics/hiive';
import getContents from './contents';
+
+// Components
import Animate from '../../../components/Animate';
-import { HEADER_SITEGEN } from '../../../../constants';
-import { store as nfdOnboardingStore } from '../../../store';
import AIHeading from '../../../components/Heading/AIHeading';
import CommonLayout from '../../../components/Layouts/Common';
import TextInputSiteGen from '../../../components/TextInput/TextInputSiteGen';
import NextButtonSiteGen from '../../../components/Button/NextButtonSiteGen';
-import SitegenAiStateHandler from '../../../components/StateHandlers/SitegenAi';
-import {
- OnboardingEvent,
- trackOnboardingEvent,
-} from '../../../utils/analytics/hiive';
+import { SiteGenStateHandler } from '../../../components/StateHandlers';
+
+// Misc
+import { HEADER_SITEGEN } from '../../../../constants';
+import { store as nfdOnboardingStore } from '../../../store';
import { ACTION_SITEGEN_SITE_DETAILS_PROMPT_SET } from '../../../utils/analytics/hiive/constants';
import { SITEGEN_FLOW } from '../../../data/flows/constants';
const SiteGenSiteDetails = () => {
- const content = getContents();
- const isLargeViewport = useViewportMatch( 'small' );
const [ customerInput, setCustomerInput ] = useState();
const [ customerInputStrength, setCustomerInputStrength ] = useState( 0 );
const [ isValidInput, setIsValidInput ] = useState( false );
+
const { currentData } = useSelect( ( select ) => {
return {
currentData:
@@ -42,6 +47,8 @@ const SiteGenSiteDetails = () => {
setIsHeaderNavigationEnabled,
} = useDispatch( nfdOnboardingStore );
+ const isLargeViewport = useViewportMatch( 'small' );
+
useEffect( () => {
setHideFooterNav( false );
setIsHeaderEnabled( true );
@@ -57,6 +64,23 @@ const SiteGenSiteDetails = () => {
setIsFooterNavAllowed( false );
}, [] );
+ useEffect( () => {
+ if (
+ customerInput !== undefined &&
+ customerInput !== '' &&
+ customerInput !== currentData.sitegen.siteDetails.prompt
+ ) {
+ currentData.sitegen.siteDetails.prompt = customerInput?.trim();
+ currentData.sitegen.siteDetails.mode = 'simple';
+ currentData.sitegen.skipCache = true;
+ currentData.sitegen.sitemapPagesGenerated = false;
+ currentData.sitegen.homepages.active = {};
+ currentData.sitegen.homepages.data = {};
+ setCurrentOnboardingData( currentData );
+ }
+ setIsFooterNavAllowed( isValidInput );
+ }, [ customerInput ] );
+
const trackPromptSetEvent = () => {
let customerInputStrengthForEvent = false;
switch ( customerInputStrength ) {
@@ -82,25 +106,10 @@ const SiteGenSiteDetails = () => {
}
};
- useEffect( () => {
- if (
- customerInput !== undefined &&
- customerInput !== '' &&
- customerInput !== currentData.sitegen.siteDetails.prompt
- ) {
- currentData.sitegen.siteDetails.prompt = customerInput?.trim();
- currentData.sitegen.siteDetails.mode = 'simple';
- currentData.sitegen.skipCache = true;
- currentData.sitegen.sitemapPagesGenerated = false;
- currentData.sitegen.homepages.active = {};
- currentData.sitegen.homepages.data = {};
- setCurrentOnboardingData( currentData );
- }
- setIsFooterNavAllowed( isValidInput );
- }, [ customerInput ] );
+ const content = getContents();
return (
-
+
@@ -135,7 +144,7 @@ const SiteGenSiteDetails = () => {
-
+
);
};
diff --git a/src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js b/src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js
index 52c95fb39..96fdf63be 100644
--- a/src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js
+++ b/src/OnboardingSPA/steps/SiteGen/SiteLogo/index.js
@@ -1,20 +1,26 @@
+// WordPress
import { useViewportMatch } from '@wordpress/compose';
import { useEffect, useState } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
+// Classes and functions
import getContents from './contents';
-import { HEADER_SITEGEN } from '../../../../constants';
+import {
+ OnboardingEvent,
+ trackOnboardingEvent,
+} from '../../../utils/analytics/hiive';
+
+// Components
import SkipButton from '../../../components/SkipButton';
-import { store as nfdOnboardingStore } from '../../../store';
import AIHeading from '../../../components/Heading/AIHeading';
import CommonLayout from '../../../components/Layouts/Common';
import NextButtonSiteGen from '../../../components/Button/NextButtonSiteGen';
import ImageUploaderWithText from '../../../components/ImageUploader/components/ImageUploaderWithText';
-import {
- OnboardingEvent,
- trackOnboardingEvent,
-} from '../../../utils/analytics/hiive';
+
+// Misc
+import { store as nfdOnboardingStore } from '../../../store';
+import { HEADER_SITEGEN } from '../../../../constants';
import {
ACTION_LOGO_ADDED,
ACTION_SITEGEN_LOGO_SKIPPED,
@@ -23,6 +29,7 @@ import { SITEGEN_FLOW } from '../../../data/flows/constants';
const SiteGenSiteLogo = () => {
const [ siteLogo, setSiteLogo ] = useState();
+
const isLargeViewport = useViewportMatch( 'small' );
const { currentData } = useSelect( ( select ) => {
@@ -32,12 +39,12 @@ const SiteGenSiteLogo = () => {
};
} );
- const { editEntityRecord } = useDispatch( coreStore );
-
const { getEditedEntityRecord } = useSelect( ( select ) => {
return select( coreStore );
}, [] );
+ const { editEntityRecord } = useDispatch( coreStore );
+
const {
setIsFooterNavAllowed,
setIsHeaderEnabled,
@@ -47,8 +54,24 @@ const SiteGenSiteLogo = () => {
setHideFooterNav,
setCurrentOnboardingData,
setIsHeaderNavigationEnabled,
+ updateSiteGenErrorStatus,
} = useDispatch( nfdOnboardingStore );
+ useEffect( () => {
+ setHideFooterNav( false );
+ setIsHeaderEnabled( true );
+ setSidebarActiveView( false );
+ setIsHeaderNavigationEnabled( true );
+ setHeaderActiveView( HEADER_SITEGEN );
+ setDrawerActiveView( false );
+ if ( currentData.sitegen.siteLogo?.id !== 0 ) {
+ setIsFooterNavAllowed( true );
+ return setSiteLogo( currentData.sitegen.siteLogo );
+ }
+ setIsFooterNavAllowed( false );
+ getEditedEntityRecord( 'root', 'site' );
+ }, [] );
+
const resetSiteLogo = () => {
const currentDataCopy = { ...currentData };
currentDataCopy.sitegen.siteLogo = {
@@ -67,21 +90,6 @@ const SiteGenSiteLogo = () => {
);
};
- useEffect( () => {
- setHideFooterNav( false );
- setIsHeaderEnabled( true );
- setSidebarActiveView( false );
- setIsHeaderNavigationEnabled( true );
- setHeaderActiveView( HEADER_SITEGEN );
- setDrawerActiveView( false );
- if ( currentData.sitegen.siteLogo?.id !== 0 ) {
- setIsFooterNavAllowed( true );
- return setSiteLogo( currentData.sitegen.siteLogo );
- }
- setIsFooterNavAllowed( false );
- getEditedEntityRecord( 'root', 'site' );
- }, [] );
-
const handleSiteLogo = ( siteLogoNew ) => {
const currentDataCopy = { ...currentData };
currentDataCopy.sitegen.siteLogo.id = siteLogoNew.id;
@@ -96,7 +104,12 @@ const SiteGenSiteLogo = () => {
setSiteLogo( siteLogoNew );
};
+ const handleFailure = () => {
+ updateSiteGenErrorStatus( true );
+ };
+
const content = getContents();
+
return (
{
{
- const isLargeViewport = useViewportMatch( 'small' );
- const navigate = useNavigate();
const [ connected, setConnected ] = useState( false );
const [ interacted, setInteracted ] = useState( false );
+ const isLargeViewport = useViewportMatch( 'small' );
+ const navigate = useNavigate();
+
+ const { nextStep } = useSelect( ( select ) => {
+ return {
+ nextStep: select( nfdOnboardingStore ).getNextStep(),
+ };
+ } );
+
const {
setIsHeaderEnabled,
setSidebarActiveView,
@@ -46,11 +61,12 @@ const SiteGenSiteSocialMedia = () => {
setIsHeaderNavigationEnabled( true );
} );
- const { nextStep } = useSelect( ( select ) => {
- return {
- nextStep: select( nfdOnboardingStore ).getNextStep(),
- };
- } );
+ useEffect( () => {
+ setIsFooterNavAllowed( connected );
+ if ( interacted && connected ) {
+ navigate( nextStep.path );
+ }
+ }, [ interacted, connected ] );
const handleConnect = () => {
trackOnboardingEvent(
@@ -78,16 +94,10 @@ const SiteGenSiteSocialMedia = () => {
);
};
- useEffect( () => {
- setIsFooterNavAllowed( connected );
- if ( interacted && connected ) {
- navigate( nextStep.path );
- }
- }, [ interacted, connected ] );
-
const content = getContents();
+
return (
-
+
{
-
+
);
};
diff --git a/src/OnboardingSPA/store/actions.js b/src/OnboardingSPA/store/actions.js
index af82d6321..fe61075e8 100644
--- a/src/OnboardingSPA/store/actions.js
+++ b/src/OnboardingSPA/store/actions.js
@@ -292,24 +292,10 @@ export function resetNavError() {
};
}
-export const setHomepagesData = ( homepagesData ) => {
+export const setIsGeneratingHomepages = ( isGeneratingHomepages ) => {
return {
- type: 'SET_HOMEPAGES_DATA',
- homepagesData,
- };
-};
-
-export const setActiveHomepage = ( activeHomepage ) => {
- return {
- type: 'SET_ACTIVE_HOMEPAGE',
- activeHomepage,
- };
-};
-
-export const toggleFavorite = ( slug ) => {
- return {
- type: 'TOGGLE_FAVORITE',
- slug,
+ type: 'SET_IS_GENERATING_HOMEPAGES',
+ isGeneratingHomepages,
};
};
diff --git a/src/OnboardingSPA/store/reducer.js b/src/OnboardingSPA/store/reducer.js
index ce5158fa2..f4c36a80a 100644
--- a/src/OnboardingSPA/store/reducer.js
+++ b/src/OnboardingSPA/store/reducer.js
@@ -162,6 +162,7 @@ export function drawer(
return state;
}
+
export function data( state = {}, action ) {
switch ( action.type ) {
case 'SET_CURRENT_DATA':
@@ -178,42 +179,23 @@ export function data( state = {}, action ) {
...action.socialData,
},
};
- case 'SET_HOMEPAGES_DATA':
- return {
- ...state,
- flowData: {
- ...state.flowData,
- sitegen: {
- ...state.flowData.sitegen,
- homepages: action.homepagesData,
- },
- },
- };
- case 'SET_ACTIVE_HOMEPAGE':
+ case 'SET_SITEGEN_AI_ERROR_STATUS':
return {
...state,
flowData: {
...state.flowData,
sitegen: {
...state.flowData.sitegen,
- homepages: {
- ...state.flowData.sitegen.homepages,
- active: action.activeHomepage,
- },
+ siteGenErrorStatus: action.siteGenErrorStatus,
},
},
};
- case 'SET_SITEGEN_AI_ERROR_STATUS':
+
+ case 'SET_IS_GENERATING_HOMEPAGES':
return {
...state,
- flowData: {
- ...state.flowData,
- sitegen: {
- ...state.flowData.sitegen,
- siteGenErrorStatus: action.siteGenErrorStatus,
- },
- },
+ isGeneratingHomepages: action.isGeneratingHomepages,
};
}
diff --git a/src/OnboardingSPA/store/selectors.js b/src/OnboardingSPA/store/selectors.js
index 020b8ef2b..4884bfd2e 100644
--- a/src/OnboardingSPA/store/selectors.js
+++ b/src/OnboardingSPA/store/selectors.js
@@ -431,36 +431,8 @@ export function getCurrentUserDetails( state ) {
return currentUserInfo;
}
-/**
- * Gets homepages
- *
- * @param {*} state
- * @return {Object} homepages
- */
-export const getHomepagesData = ( state ) => {
- return state.data.flowData.sitegen.homepages;
-};
-
-/**
- * Gets actove homepage
- *
- * @param {*} state
- * @return {Object} active
- */
-
-export const getActiveHomepage = ( state ) => {
- return state.data.flowData.sitegen.homepages.active;
-};
-
-/**
- * Gets all homepage
- *
- * @param {*} state
- * @return {Object} data
- */
-
-export const getAllHomepages = ( state ) => {
- return state.data.flowData.sitegen.homepages.data;
+export const isGeneratingHomepages = ( state ) => {
+ return state.data.isGeneratingHomepages;
};
export function getCustomizeSidebarData( state ) {
diff --git a/src/OnboardingSPA/styles/app.scss b/src/OnboardingSPA/styles/app.scss
index 09ae7c727..80e31765c 100644
--- a/src/OnboardingSPA/styles/app.scss
+++ b/src/OnboardingSPA/styles/app.scss
@@ -33,6 +33,7 @@
@import "../components/Button/NavCardButton/stylesheet";
@import "../steps/Ecommerce/stylesheet";
@import "../components/ErrorState/stylesheet";
+@import "../components/ErrorState/Step/SiteGen/stylesheet";
@import "../components/ErrorModal/stylesheet";
@import "../components/CheckboxTemplate/CheckboxItem/stylesheet";
@import "../components/CheckboxTemplate/CheckboxList/stylesheet";
@@ -65,7 +66,6 @@
@import "../components/TextInput/TextAreaSiteGenDetails/stylesheet";
@import "../components/TextInput/TextInputSiteGenDetails/stylesheet";
@import "../components/OrbAnimation/stylesheet";
-@import "../components/SiteGenError/stylesheet";
// CSS for Pages
@import "../steps/BasicInfo/stylesheet";
diff --git a/src/OnboardingSPA/utils/api/siteGen.js b/src/OnboardingSPA/utils/api/siteGen.js
index 64893f1c0..70a403dbc 100644
--- a/src/OnboardingSPA/utils/api/siteGen.js
+++ b/src/OnboardingSPA/utils/api/siteGen.js
@@ -16,15 +16,17 @@ export async function generateSiteGenMeta(
identifier,
skipCache = true
) {
- const data = await apiFetch( {
- url: onboardingRestURL( 'sitegen/generate' ),
- method: 'POST',
- data: {
- site_info: siteInfo,
- identifier,
- skip_cache: skipCache,
- },
- } );
+ const data = await resolve(
+ apiFetch( {
+ url: onboardingRestURL( 'sitegen/generate' ),
+ method: 'POST',
+ data: {
+ site_info: siteInfo,
+ identifier,
+ skip_cache: skipCache,
+ },
+ } )
+ );
return data;
}