Adding delayed spotlight to feedback button on current product page (#35865)

This commit is contained in:
Joel Thiessen 2022-12-15 16:09:21 -08:00 committed by GitHub
parent 03d52ff13b
commit 54f22aa437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 143 additions and 7 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Adding isHidden option for primary button in TourKit component.

View File

@ -25,7 +25,7 @@ const StepNavigation: React.FunctionComponent< Props > = ( {
const isFirstStep = currentStepIndex === 0;
const isLastStep = currentStepIndex === steps.length - 1;
const { primaryButton = { text: '', isDisabled: false } } =
const { primaryButton = { text: '', isDisabled: false, isHidden: false } } =
steps[ currentStepIndex ].meta;
const NextButton = (
@ -80,6 +80,10 @@ const StepNavigation: React.FunctionComponent< Props > = ( {
);
};
if ( primaryButton.isHidden ) {
return null;
}
return (
<div className="woocommerce-tour-kit-step-navigation">
<div className="woocommerce-tour-kit-step-navigation__step">

View File

@ -22,6 +22,7 @@ export interface WooStep extends Step {
text?: string;
/** Disable the button or not. Default to False */
isDisabled?: boolean;
isHidden?: boolean;
};
};
/** Auto apply the focus state for the element. Default to null */

View File

@ -49,6 +49,7 @@ import { LayoutContext } from '~/layout';
import { getSegmentsFromPath } from '~/utils/url-helpers';
import { FeedbackIcon } from '~/products/images/feedback-icon';
import { STORE_KEY as CES_STORE_KEY } from '~/customer-effort-score-tracks/data/constants';
import { ProductFeedbackTour } from '~/guided-tours/add-product-feedback-tour';
const HelpPanel = lazy( () =>
import( /* webpackChunkName: "activity-panels-help" */ './panels/help' )
@ -250,6 +251,16 @@ export const ActivityPanel = ( { isEmbedded, query } ) => {
);
};
const isAddProductPage = () => {
const urlParams = getUrlParams( window.location.search );
return (
isEmbedded &&
/post-new\.php$/.test( window.location.pathname ) &&
urlParams?.post_type === 'product'
);
};
const isPerformingSetupTask = () => {
return (
query.task &&
@ -262,8 +273,6 @@ export const ActivityPanel = ( { isEmbedded, query } ) => {
// @todo Pull in dynamic unread status/count
const getTabs = () => {
const urlParams = getUrlParams( window.location.search );
const activity = {
name: 'activity',
title: __( 'Activity', 'woocommerce' ),
@ -314,10 +323,7 @@ export const ActivityPanel = ( { isEmbedded, query } ) => {
}
);
},
visible:
isEmbedded &&
urlParams?.post_type === 'product' &&
! urlParams?.taxonomy,
visible: isAddProductPage(),
};
const setup = {
@ -485,6 +491,9 @@ export const ActivityPanel = ( { isEmbedded, query } ) => {
clearPanel={ () => clearPanel() }
/>
</Section>
{ isAddProductPage() && (
<ProductFeedbackTour currentTab={ currentTab } />
) }
{ showHelpHighlightTooltip ? (
<HighlightTooltip
delay={ 1000 }

View File

@ -0,0 +1,114 @@
/**
* External dependencies
*/
import { TourKit } from '@woocommerce/components';
import { __ } from '@wordpress/i18n';
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
import { useState, useEffect, useRef } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
const FEEDBACK_TOUR_OPTION = 'woocommerce_ces_product_feedback_shown';
const FEEDBACK_TIMEOUT_MS = 7 * 60 * 1000;
const useShowProductFeedbackTour = (): undefined | boolean => {
const { hasShownTour } = useSelect( ( select ) => {
const { getOption } = select( OPTIONS_STORE_NAME );
return {
hasShownTour: getOption( FEEDBACK_TOUR_OPTION ) as
| boolean
| undefined,
};
} );
return hasShownTour;
};
type ProductFeedbackTourProps = {
currentTab: string;
};
export const ProductFeedbackTour: React.FC< ProductFeedbackTourProps > = ( {
currentTab,
} ) => {
const hasShownTour = useShowProductFeedbackTour();
const [ isTourVisible, setIsTourVisible ] = useState( false );
const tourTimeout = useRef< ReturnType< typeof setTimeout > | null >(
null
);
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
const clearTourTimeout = () => {
clearTimeout( tourTimeout.current as ReturnType< typeof setTimeout > );
tourTimeout.current = null;
};
useEffect( () => {
if ( hasShownTour !== false ) {
return;
}
tourTimeout.current = setTimeout( () => {
setIsTourVisible( true );
}, FEEDBACK_TIMEOUT_MS );
return () => clearTourTimeout();
}, [ hasShownTour ] );
useEffect( () => {
if ( ! isTourVisible ) {
return;
}
updateOptions( {
[ FEEDBACK_TOUR_OPTION ]: true,
} );
}, [ isTourVisible ] );
if (
currentTab === 'feedback' &&
( isTourVisible || tourTimeout.current )
) {
setIsTourVisible( false );
clearTourTimeout();
}
if ( ! isTourVisible ) {
return null;
}
return (
<TourKit
config={ {
steps: [
{
referenceElements: {
desktop: '#activity-panel-tab-feedback',
},
meta: {
name: 'product-feedback-tour-1',
heading: __( '🫣 Feeling stuck?', 'woocommerce' ),
descriptions: {
desktop: __(
"You have been working on this product for a few minutes now. Is there something you're struggling with? Share your feedback.",
'woocommerce'
),
},
primaryButton: {
isHidden: true,
},
},
},
],
placement: 'bottom-start',
options: {
effects: {
liveResize: { mutation: true, resize: true },
},
},
closeHandler: () => {
setIsTourVisible( false );
},
} }
/>
);
};

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Adding delayed spotlight to feedback button on current product page.