Skip to content

Commit

Permalink
Merge pull request #228 from newfold-labs/enhance/auto-advance-on-cus…
Browse files Browse the repository at this point in the history
…tom-design-selection

Enhance preview step to auto advance on custom design checkbox selection
  • Loading branch information
arunshenoy99 authored May 4, 2023
2 parents ee2b421 + 9dc4603 commit 9932d56
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useSelect, useDispatch } from '@wordpress/data';
import { useState, useEffect } from '@wordpress/element';
import { useLocation } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { CheckboxControl } from '@wordpress/components';
import {
addColorAndTypographyRoutes,
removeColorAndTypographyRoutes,
} from '../utils';

import { conditionalSteps } from '../../../../data/routes';
import {
LivePreview,
GlobalStylesProvider,
Expand All @@ -28,6 +28,7 @@ const StepDesignThemeStylesPreview = () => {
const location = useLocation();
const [ pattern, setPattern ] = useState();
const [ customize, setCustomize ] = useState( false );
const navigate = useNavigate();

const {
currentStep,
Expand Down Expand Up @@ -63,7 +64,7 @@ const StepDesignThemeStylesPreview = () => {
useEffect( () => {
setSidebarActiveView( SIDEBAR_LEARN_MORE );
setDrawerActiveView( VIEW_DESIGN_THEME_STYLES_PREVIEW );
handleCheckbox( currentData.data.customDesign, false );
handleCheckbox( currentData.data.customDesign, false, 'flow' );
}, [] );

const getStylesAndPatterns = async () => {
Expand All @@ -78,11 +79,12 @@ const StepDesignThemeStylesPreview = () => {
};

const handleCheckbox = (
customizeSelection,
updateOnboardingData = true
selected,
updateOnboardingData = true,
context = 'click'
) => {
let updates;
if ( customizeSelection ) {
if ( selected ) {
updates = addColorAndTypographyRoutes(
routes,
allSteps,
Expand All @@ -99,12 +101,16 @@ const StepDesignThemeStylesPreview = () => {
updateRoutes( updates.routes );
updateDesignSteps( updates.designSteps );
updateAllSteps( updates.allSteps );
setCustomize( customizeSelection );
setCustomize( selected );

if ( updateOnboardingData ) {
currentData.data.customDesign = customizeSelection;
currentData.data.customDesign = selected;
setCurrentOnboardingData( currentData );
}

if ( selected && 'click' === context ) {
navigate( conditionalSteps.designColors.path );
}
};

useEffect( () => {
Expand Down

0 comments on commit 9932d56

Please sign in to comment.