* Revert "Show feedback bar only once (#41787)"
This reverts commit defa590f32
.
* Add changelog
This commit is contained in:
parent
c58b0cf936
commit
cb9bd1ae76
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: fix
|
||||
|
||||
Revert "Show feedback bar only once (#41787)" #43178
|
|
@ -12,7 +12,6 @@ import {
|
|||
createElement,
|
||||
createInterpolateElement,
|
||||
Fragment,
|
||||
useState,
|
||||
} from '@wordpress/element';
|
||||
import { closeSmall } from '@wordpress/icons';
|
||||
import { Pill } from '@woocommerce/components';
|
||||
|
@ -31,10 +30,9 @@ export type FeedbackBarProps = {
|
|||
};
|
||||
|
||||
export function FeedbackBar( { productType }: FeedbackBarProps ) {
|
||||
const { shouldShowFeedbackBar } = useFeedbackBar();
|
||||
const { hideFeedbackBar, shouldShowFeedbackBar } = useFeedbackBar();
|
||||
const { showCesModal, showProductMVPFeedbackModal } =
|
||||
useCustomerEffortScoreModal();
|
||||
const [ isFeedbackBarHidden, setIsFeedbackBarHidden ] = useState( false );
|
||||
|
||||
const getProductTracksProps = () => {
|
||||
const tracksProps = {
|
||||
|
@ -177,7 +175,6 @@ export function FeedbackBar( { productType }: FeedbackBarProps ) {
|
|||
type: 'snackbar',
|
||||
}
|
||||
);
|
||||
setIsFeedbackBarHidden( true );
|
||||
};
|
||||
|
||||
const onTurnOffEditorClick = () => {
|
||||
|
@ -185,7 +182,7 @@ export function FeedbackBar( { productType }: FeedbackBarProps ) {
|
|||
...getProductTracksProps(),
|
||||
} );
|
||||
|
||||
setIsFeedbackBarHidden( true );
|
||||
hideFeedbackBar();
|
||||
|
||||
showProductMVPFeedbackModal();
|
||||
};
|
||||
|
@ -195,12 +192,12 @@ export function FeedbackBar( { productType }: FeedbackBarProps ) {
|
|||
...getProductTracksProps(),
|
||||
} );
|
||||
|
||||
setIsFeedbackBarHidden( true );
|
||||
hideFeedbackBar();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{ shouldShowFeedbackBar && ! isFeedbackBarHidden && (
|
||||
{ shouldShowFeedbackBar && (
|
||||
<div className="woocommerce-product-mvp-ces-footer">
|
||||
<Pill>Beta</Pill>
|
||||
<div className="woocommerce-product-mvp-ces-footer__message">
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { resolveSelect, useDispatch } from '@wordpress/data';
|
||||
import { useEffect, useState, useCallback } from '@wordpress/element';
|
||||
import { resolveSelect, useDispatch, useSelect } from '@wordpress/data';
|
||||
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
|
||||
|
||||
/**
|
||||
|
@ -12,8 +11,26 @@ import { PRODUCT_EDITOR_SHOW_FEEDBACK_BAR_OPTION_NAME } from '../../constants';
|
|||
|
||||
export const useFeedbackBar = () => {
|
||||
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME );
|
||||
const [ shouldShowFeedbackBar, setShouldShowFeedbackBar ] =
|
||||
useState( false );
|
||||
|
||||
const { shouldShowFeedbackBar } = useSelect( ( select ) => {
|
||||
const { getOption, hasFinishedResolution } =
|
||||
select( OPTIONS_STORE_NAME );
|
||||
|
||||
const showFeedbackBarOption = getOption(
|
||||
PRODUCT_EDITOR_SHOW_FEEDBACK_BAR_OPTION_NAME
|
||||
) as string;
|
||||
|
||||
const resolving = ! hasFinishedResolution( 'getOption', [
|
||||
PRODUCT_EDITOR_SHOW_FEEDBACK_BAR_OPTION_NAME,
|
||||
] );
|
||||
|
||||
return {
|
||||
shouldShowFeedbackBar:
|
||||
! resolving &&
|
||||
window.wcTracks?.isEnabled &&
|
||||
showFeedbackBarOption === 'yes',
|
||||
};
|
||||
}, [] );
|
||||
|
||||
const showFeedbackBar = () => {
|
||||
updateOptions( {
|
||||
|
@ -41,32 +58,15 @@ export const useFeedbackBar = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const showFeedbackBarOnce = () => {
|
||||
const hideFeedbackBar = () => {
|
||||
updateOptions( {
|
||||
[ PRODUCT_EDITOR_SHOW_FEEDBACK_BAR_OPTION_NAME ]: 'no',
|
||||
} );
|
||||
setShouldShowFeedbackBar( true );
|
||||
};
|
||||
|
||||
const fetchShowFeedbackBarOption = useCallback( () => {
|
||||
return resolveSelect( OPTIONS_STORE_NAME )
|
||||
.getOption< string >( PRODUCT_EDITOR_SHOW_FEEDBACK_BAR_OPTION_NAME )
|
||||
.then( ( showFeedbackBarOption ) => {
|
||||
if (
|
||||
window.wcTracks?.isEnabled &&
|
||||
showFeedbackBarOption === 'yes'
|
||||
) {
|
||||
showFeedbackBarOnce();
|
||||
}
|
||||
} );
|
||||
}, [] );
|
||||
|
||||
useEffect( () => {
|
||||
fetchShowFeedbackBarOption();
|
||||
}, [] );
|
||||
|
||||
return {
|
||||
shouldShowFeedbackBar,
|
||||
maybeShowFeedbackBar,
|
||||
hideFeedbackBar,
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue