From 2ee26d01f4e3ab123b9e331e0e3eb3b14cac7509 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Thu, 7 Dec 2023 11:43:22 +0530 Subject: [PATCH 1/2] Sitegen Save and Continue --- includes/RestApi/FlowController.php | 23 ++++++- includes/RestApi/SitePagesController.php | 2 +- .../components/Loaders/Spinner/index.js | 13 +++- .../data/sitegen/homepages/homepages.js | 31 +++++----- .../data/sitegen/sitemeta/siteMeta.js | 60 +++++++++---------- .../steps/SiteGen/Editor/Header/index.js | 54 ++++++++++++++--- .../SiteGen/Editor/Header/stylesheet.scss | 20 +++++++ src/constants.js | 1 + 8 files changed, 144 insertions(+), 60 deletions(-) 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/data/sitegen/homepages/homepages.js b/src/OnboardingSPA/data/sitegen/homepages/homepages.js index 34f9ab1e9..7a7454c11 100644 --- a/src/OnboardingSPA/data/sitegen/homepages/homepages.js +++ b/src/OnboardingSPA/data/sitegen/homepages/homepages.js @@ -1,25 +1,22 @@ -import {getRandomColorPalette} from '../sitemeta/siteMeta'; +import { getRandomColorPalette } from '../sitemeta/siteMeta'; import one from './1.json'; import two from './2.json'; import three from './3.json'; import four from './4.json'; const getHomepages = () => { - return [one, two, three]; -} + return [ one, two, three ]; +}; const getRandom = ( homepage ) => { - console.log('homepage', homepage); - if ( homepage?.favorite ) { - homepage.slug = homepage.slug + '-copy' - homepage.title = homepage.title + ' Copy' - homepage.favorite = false; - homepage.color = getRandomColorPalette( homepage?.color?.slug ); - return homepage; - } - four.color = getRandomColorPalette( homepage?.color?.slug ); - return four; + if ( homepage?.favorite ) { + homepage.slug = homepage.slug + '-copy'; + homepage.title = homepage.title + ' Copy'; + homepage.favorite = false; + homepage.color = getRandomColorPalette( homepage?.color?.slug ); + return homepage; + } + four.color = getRandomColorPalette( homepage?.color?.slug ); + return four; +}; - -} - -export { getHomepages, getRandom }; \ No newline at end of file +export { getHomepages, getRandom }; diff --git a/src/OnboardingSPA/data/sitegen/sitemeta/siteMeta.js b/src/OnboardingSPA/data/sitegen/sitemeta/siteMeta.js index 83156a301..dafb24e51 100644 --- a/src/OnboardingSPA/data/sitegen/sitemeta/siteMeta.js +++ b/src/OnboardingSPA/data/sitegen/sitemeta/siteMeta.js @@ -1,39 +1,39 @@ import siteMeta from './siteMeta.json'; const getSiteMeta = () => { - return siteMeta; -} + return siteMeta; +}; const getColorPalettes = () => { - let colorPalettes = {}; - Object.keys( siteMeta.colorpalette ).forEach((colorPalette) => { - colorPalettes[colorPalette] = Object.keys(siteMeta.colorpalette[colorPalette]).map(( slug ) => { - return { - slug, - title: slug[0].toUpperCase() + slug.slice(1), - color: siteMeta.colorpalette[colorPalette][slug] - } - }) - }) + const colorPalettes = {}; + Object.keys( siteMeta.colorpalette ).forEach( ( colorPalette ) => { + colorPalettes[ colorPalette ] = Object.keys( + siteMeta.colorpalette[ colorPalette ] + ).map( ( slug ) => { + return { + slug, + title: slug[ 0 ].toUpperCase() + slug.slice( 1 ), + color: siteMeta.colorpalette[ colorPalette ][ slug ], + }; + } ); + } ); - return colorPalettes; -} + return colorPalettes; +}; const getRandomColorPalette = ( activeColorPaletteSlug ) => { - const colorPalettes = getColorPalettes(); - console.log(colorPalettes) - let keys = Object.keys( colorPalettes ); - if ( activeColorPaletteSlug ) { - keys = keys.filter(( key ) => { - return key != activeColorPaletteSlug - }) - } + const colorPalettes = getColorPalettes(); + let keys = Object.keys( colorPalettes ); + if ( activeColorPaletteSlug ) { + keys = keys.filter( ( key ) => { + return key != activeColorPaletteSlug; + } ); + } - const rand = Math.floor( Math.random() * keys.length ); - console.log(rand) - return { - slug: keys[2], - palette: colorPalettes[ keys[ 2 ] ] - } -} + const rand = Math.floor( Math.random() * keys.length ); + return { + slug: keys[ 2 ], + palette: colorPalettes[ keys[ 2 ] ], + }; +}; -export {getSiteMeta, getColorPalettes, getRandomColorPalette}; \ No newline at end of file +export { getSiteMeta, getColorPalettes, getRandomColorPalette }; diff --git a/src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js b/src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js index 6f55d84fe..5025ffab6 100644 --- a/src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js +++ b/src/OnboardingSPA/steps/SiteGen/Editor/Header/index.js @@ -4,6 +4,7 @@ import { HEADER_END, HEADER_SITEGEN, HEADER_START, + wpEditorPage, } from '../../../../../constants'; import { Icon, chevronDown, chevronRight, home } from '@wordpress/icons'; import { store as nfdOnboardingStore } from '../../../../store'; @@ -12,9 +13,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 } = useDispatch( nfdOnboardingStore ); const { currentData } = useSelect( ( select ) => { @@ -25,12 +29,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; @@ -38,7 +48,12 @@ const StepSiteGenEditorHeader = () => { setCurrentOnboardingData( currentData ); }; - const generateChildThemes = () => {}; + const saveAndContinue = async () => { + setIsSaving( true ); + await setFlow( currentData ); + await completeFlow(); + window.location.replace( wpEditorPage ); + }; useEffect( () => { if ( currentData?.sitegen?.homepages?.active ) { @@ -50,7 +65,10 @@ const StepSiteGenEditorHeader = () => {
handleRegenerate() } >
{ ); } } renderContent={ () => ( -
+

Rename

@@ -111,7 +134,12 @@ const StepSiteGenEditorHeader = () => {
-
+
Customize @@ -120,14 +148,22 @@ const StepSiteGenEditorHeader = () => {
Save & Continue
- + { isSaving ? ( + + ) : ( + + ) }
diff --git a/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss b/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss index c068666e5..8866c799e 100644 --- a/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss +++ b/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss @@ -22,6 +22,10 @@ align-items: center; justify-content: space-evenly; width: 130px; + + &__disabled { + cursor: disabled; + } } } @@ -74,6 +78,10 @@ &__view-all { border-top: 1px solid var(--nfd-onboarding-secondary); } + + &__disabled { + cursor: disabled; + } } } } @@ -99,6 +107,10 @@ width: 16px; margin-right: 8px; } + + &__disabled { + cursor: disabled; + } } &__save-button { @@ -112,6 +124,14 @@ padding: 0px 12px 0px 12px; height: 36px; border-radius: 8px; + + &__spinner { + height: 8px; + width: 8px; + border-color: var(--nfd-onboarding-secondary); + border-width: 3px; + margin-left: 8px; + } } } } 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, From b8ea39345780dc4241ac93d3466ff183ffacd47b Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Thu, 7 Dec 2023 12:32:25 +0530 Subject: [PATCH 2/2] Lint fixes --- .../steps/SiteGen/Editor/Header/stylesheet.scss | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss b/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss index 6127e7272..fc6a8b8e9 100644 --- a/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss +++ b/src/OnboardingSPA/steps/SiteGen/Editor/Header/stylesheet.scss @@ -30,8 +30,8 @@ width: 130px; &__disabled { - cursor: disabled; - } + cursor: disabled; + } } } @@ -121,8 +121,8 @@ } &__disabled { - cursor: disabled; - } + cursor: disabled; + } } &__save-button {