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 1 commit
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: 16 additions & 6 deletions src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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 { __ } from '@wordpress/i18n';
// eslint-disable-next-line import/no-extraneous-dependencies
import { orderBy, filter } from 'lodash';

import {
Expand All @@ -25,6 +26,7 @@ const StepDesignThemeStylesPreview = () => {
const location = useLocation();
const [ pattern, setPattern ] = useState();
const [ customize, setCustomize ] = useState( false );
const navigate = useNavigate();

const {
currentStep,
Expand Down Expand Up @@ -60,7 +62,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 Down Expand Up @@ -134,10 +136,14 @@ const StepDesignThemeStylesPreview = () => {
};
};

const handleCheckbox = ( customize, updateOnboardingData = true ) => {
const handleCheckbox = (
selected,
updateOnboardingData = true,
context = 'click'
) => {
let updates;

if ( customize ) {
if ( selected ) {
updates = addColorAndTypographyRoutes();
} else {
updates = removeColorAndTypographyRoutes();
Expand All @@ -146,12 +152,16 @@ const StepDesignThemeStylesPreview = () => {
updateRoutes( updates.routes );
updateDesignSteps( updates.designSteps );
updateAllSteps( updates.allSteps );
setCustomize( customize );
setCustomize( selected );

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

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

useEffect( () => {
Expand Down