Revert "Show feedback bar only once (#41787)" (#43178)

* Revert "Show feedback bar only once (#41787)"

This reverts commit defa590f32.

* Add changelog
This commit is contained in:
Fernando Marichal 2023-12-29 16:33:59 -03:00 committed by GitHub
parent c58b0cf936
commit cb9bd1ae76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 30 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Revert "Show feedback bar only once (#41787)" #43178

View File

@ -12,7 +12,6 @@ import {
createElement, createElement,
createInterpolateElement, createInterpolateElement,
Fragment, Fragment,
useState,
} from '@wordpress/element'; } from '@wordpress/element';
import { closeSmall } from '@wordpress/icons'; import { closeSmall } from '@wordpress/icons';
import { Pill } from '@woocommerce/components'; import { Pill } from '@woocommerce/components';
@ -31,10 +30,9 @@ export type FeedbackBarProps = {
}; };
export function FeedbackBar( { productType }: FeedbackBarProps ) { export function FeedbackBar( { productType }: FeedbackBarProps ) {
const { shouldShowFeedbackBar } = useFeedbackBar(); const { hideFeedbackBar, shouldShowFeedbackBar } = useFeedbackBar();
const { showCesModal, showProductMVPFeedbackModal } = const { showCesModal, showProductMVPFeedbackModal } =
useCustomerEffortScoreModal(); useCustomerEffortScoreModal();
const [ isFeedbackBarHidden, setIsFeedbackBarHidden ] = useState( false );
const getProductTracksProps = () => { const getProductTracksProps = () => {
const tracksProps = { const tracksProps = {
@ -177,7 +175,6 @@ export function FeedbackBar( { productType }: FeedbackBarProps ) {
type: 'snackbar', type: 'snackbar',
} }
); );
setIsFeedbackBarHidden( true );
}; };
const onTurnOffEditorClick = () => { const onTurnOffEditorClick = () => {
@ -185,7 +182,7 @@ export function FeedbackBar( { productType }: FeedbackBarProps ) {
...getProductTracksProps(), ...getProductTracksProps(),
} ); } );
setIsFeedbackBarHidden( true ); hideFeedbackBar();
showProductMVPFeedbackModal(); showProductMVPFeedbackModal();
}; };
@ -195,12 +192,12 @@ export function FeedbackBar( { productType }: FeedbackBarProps ) {
...getProductTracksProps(), ...getProductTracksProps(),
} ); } );
setIsFeedbackBarHidden( true ); hideFeedbackBar();
}; };
return ( return (
<> <>
{ shouldShowFeedbackBar && ! isFeedbackBarHidden && ( { shouldShowFeedbackBar && (
<div className="woocommerce-product-mvp-ces-footer"> <div className="woocommerce-product-mvp-ces-footer">
<Pill>Beta</Pill> <Pill>Beta</Pill>
<div className="woocommerce-product-mvp-ces-footer__message"> <div className="woocommerce-product-mvp-ces-footer__message">

View File

@ -1,8 +1,7 @@
/** /**
* External dependencies * External dependencies
*/ */
import { resolveSelect, useDispatch } from '@wordpress/data'; import { resolveSelect, useDispatch, useSelect } from '@wordpress/data';
import { useEffect, useState, useCallback } from '@wordpress/element';
import { OPTIONS_STORE_NAME } from '@woocommerce/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 = () => { export const useFeedbackBar = () => {
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME ); 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 = () => { const showFeedbackBar = () => {
updateOptions( { updateOptions( {
@ -41,32 +58,15 @@ export const useFeedbackBar = () => {
} }
}; };
const showFeedbackBarOnce = () => { const hideFeedbackBar = () => {
updateOptions( { updateOptions( {
[ PRODUCT_EDITOR_SHOW_FEEDBACK_BAR_OPTION_NAME ]: 'no', [ 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 { return {
shouldShowFeedbackBar, shouldShowFeedbackBar,
maybeShowFeedbackBar, maybeShowFeedbackBar,
hideFeedbackBar,
}; };
}; };