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

Add useEffect to avoid multiple CES prompts on the Dashboard Page #1543

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
41 changes: 41 additions & 0 deletions js/src/hooks/useCESNotice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { noop } from 'lodash';

/**
* Internal dependencies
*/
import useUnmountableNotice from '.~/hooks/useUnmountableNotice';

/**
* Hook to create a CES notice
*
* @param {string} label CES prompt label.
* @param {JSX.Element} icon Icon (React component) to be shown on the notice.
* @param {Function} [onClickCallBack] Function to call when Give feedback is clicked.
* @param {Function} [onNoticeDismissedCallback] Function to call when the notice is dismissed.
*
* @return {Function} a function that will create the CES notice.
*/
const useCESNotice = (
label,
icon,
onClickCallBack = noop,
onNoticeDismissedCallback = noop
) => {
return useUnmountableNotice( 'success', label, {
actions: [
{
label: __( 'Give feedback', 'woocommerce-admin' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be google-listings-and-ads rather than woocommerce-admin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ianlin, it is updated: f674ca7

For the bundle size, I also think it's related to importing '@woocommerce/customer-effort-score/build/customer-feedback-modal', but I don't have any clues at the moment

It is related to @wordpress/components, I think the issue is that @woocommerce/customer-effort-score/build/customer-feedback-modal uses a different version of @wordpress/components, and this increases the bundle size.

I am looking into possible solutions, maybe @ecgan have seen this issue before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking into possible solutions, maybe @ecgan have seen this issue before.

See my comment #1543 (comment) below.

onClick: onClickCallBack,
},
],
icon,
explicitDismiss: true,
onDismiss: onNoticeDismissedCallback,
} );
};

export default useCESNotice;