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

Enhance preview step to auto advance on custom design checkbox selection #228

Merged
merged 3 commits into from
May 4, 2023
Merged
Changes from all 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
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