diff --git a/includes/RestApi/FlowController.php b/includes/RestApi/FlowController.php index e03baeed6..c4a6fb317 100644 --- a/includes/RestApi/FlowController.php +++ b/includes/RestApi/FlowController.php @@ -1,9 +1,11 @@ get_param('flow'); + if ( 'sitegen' === $flow ) { + $flow_data_option = \get_option( Options::get_option_name( 'flow' ), false ); + if ( false === $flow_data_option || ! isset( $flow_data_option['data'] ) ) { + return new \WP_Error( + 'nfd_onboarding_error', + 'Flow data does not exist to generate a child theme.', + array( 'status' => 500 ) + ); + } + $homepage_data = $flow_data_option['sitegen']['homepages']['data']; + $active_homepage = $flow_data_option['sitegen']['homepages']['active']; + SiteGenService::complete( $active_homepage, $homepage_data ); + return new \WP_REST_Response( + array(), + 201 + ); + } + $site_pages_publish_request = new \WP_REST_Request( 'POST', '/newfold-onboarding/v1/site-pages/publish' diff --git a/includes/RestApi/SitePagesController.php b/includes/RestApi/SitePagesController.php index d839bf89b..274891a5d 100644 --- a/includes/RestApi/SitePagesController.php +++ b/includes/RestApi/SitePagesController.php @@ -54,7 +54,7 @@ public function publish_site_pages() { if ( false === $flow_data_option || ! isset( $flow_data_option['data'] ) ) { return new \WP_Error( 'nfd_onboarding_error', - 'Flow data does not exist to generate a child theme.', + 'Flow data does not exist to publish site pages', array( 'status' => 500 ) ); } diff --git a/src/OnboardingSPA/components/Loaders/Spinner/index.js b/src/OnboardingSPA/components/Loaders/Spinner/index.js index 33eeec4e0..fcd838488 100644 --- a/src/OnboardingSPA/components/Loaders/Spinner/index.js +++ b/src/OnboardingSPA/components/Loaders/Spinner/index.js @@ -1,5 +1,14 @@ -const Spinner = () => { - return
; +import classNames from 'classnames'; + +const Spinner = ( { className } ) => { + return ( +
+ ); }; export default Spinner; diff --git a/src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js b/src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js index 4914cb0f8..5d7da8b09 100644 --- a/src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js @@ -5,6 +5,7 @@ import { HEADER_END, HEADER_SITEGEN, HEADER_START, + wpEditorPage, SIDEBAR_SITEGEN_EDITOR_PATTERNS, } from '../../../../../constants'; import { Icon, chevronDown, chevronRight } from '@wordpress/icons'; @@ -14,9 +15,12 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { useEffect, useState } from '@wordpress/element'; import { getRandom } from '../../../../data/sitegen/homepages/homepages'; +import { setFlow, completeFlow } from '../../../../utils/api/flow'; +import Spinner from '../../../../components/Loaders/Spinner'; const StepSiteGenEditorHeader = () => { const [ homepage, setHomepage ] = useState(); + const [ isSaving, setIsSaving ] = useState( false ); const { setCurrentOnboardingData, @@ -31,12 +35,18 @@ const StepSiteGenEditorHeader = () => { } ); const handleFavorite = () => { + if ( isSaving ) { + return; + } homepage.favorite = ! homepage.favorite; currentData.sitegen.homepages.data[ homepage.slug ] = homepage; setCurrentOnboardingData( currentData ); }; const handleRegenerate = () => { + if ( isSaving ) { + return; + } const newPage = getRandom( { ...homepage } ); setHomepage( newPage ); currentData.sitegen.homepages.data[ newPage.slug ] = newPage; @@ -44,13 +54,17 @@ const StepSiteGenEditorHeader = () => { setCurrentOnboardingData( currentData ); }; + const saveAndContinue = async () => { + setIsSaving( true ); + await setFlow( currentData ); + await completeFlow(); + window.location.replace( wpEditorPage ); + }; const handleViewAll = () => { setSidebarActiveView( SIDEBAR_SITEGEN_EDITOR_PATTERNS ); setIsSidebarOpened( true ); }; - const generateChildThemes = () => {}; - useEffect( () => { if ( currentData?.sitegen?.homepages?.active ) { setHomepage( currentData.sitegen.homepages.active ); @@ -61,7 +75,10 @@ const StepSiteGenEditorHeader = () => {
handleRegenerate() } @@ -116,7 +133,12 @@ const StepSiteGenEditorHeader = () => { ); } } renderContent={ () => ( -
+

{ __( 'Rename', @@ -143,7 +165,12 @@ const StepSiteGenEditorHeader = () => {

-
+
{ __( 'Customize', 'wp-module-onboarding' ) } @@ -152,17 +179,25 @@ const StepSiteGenEditorHeader = () => {
{ __( 'Save & Continue', 'wp-module-onboarding' ) }
- + { isSaving ? ( + + ) : ( + + ) }
diff --git a/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss b/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss index df44f103d..fc6a8b8e9 100644 --- a/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss +++ b/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss @@ -28,6 +28,10 @@ align-items: center; justify-content: space-evenly; width: 130px; + + &__disabled { + cursor: disabled; + } } } @@ -84,6 +88,10 @@ &__view-all { border-top: 1px solid var(--nfd-onboarding-secondary); } + + &__disabled { + cursor: disabled; + } } } } @@ -111,6 +119,10 @@ width: 16px; margin-right: 8px; } + + &__disabled { + cursor: disabled; + } } &__save-button { diff --git a/src/constants.js b/src/constants.js index 666eff7c6..d5ceaab2e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -17,6 +17,7 @@ export const wpAdminPage = addQueryArgs( `${ wpAdminUrl }index.php`, window.nfdOnboarding.currentBrand?.dashboardRedirectParams ); +export const wpEditorPage = `${ wpAdminUrl }site-editor.php?canvas=edit`; export const pluginDashboardPage = addQueryArgs( window.nfdOnboarding.currentBrand?.pluginDashboardPage,