Skip to content

Commit

Permalink
Add useEffect to avoid multiple CES prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemd24 committed May 31, 2022
1 parent 6ae6c67 commit 74949bc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions js/src/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { Button } from '@wordpress/components';
import { useState, useCallback } from '@wordpress/element';
import { useState, useCallback, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Link } from '@woocommerce/components';
import { getNewPath, getQuery, getHistory } from '@woocommerce/navigation';
Expand All @@ -26,12 +26,18 @@ import EditFreeCampaign from '.~/edit-free-campaign';
import EditPaidAdsCampaign from '.~/pages/edit-paid-ads-campaign';
import CreatePaidAdsCampaign from '.~/pages/create-paid-ads-campaign';
import { CTA_CREATE_ANOTHER_CAMPAIGN, CTA_CONFIRM } from './constants';
import useUrlQuery from '.~/hooks/useUrlQuery';

/**
* @fires gla_modal_closed when CES modal is closed.
*/
const Dashboard = () => {
const [ isCESPromptOpen, setCESPromptOpen ] = useState( false );
const query = useUrlQuery();

useEffect( () => {
setCESPromptOpen( false );
}, [ query.subpath ] );

const handleCampaignCreationSuccessGuideClose = useCallback(
( e, specifiedAction ) => {
Expand All @@ -56,7 +62,6 @@ const Dashboard = () => {
[ setCESPromptOpen ]
);

const query = getQuery();
switch ( query.subpath ) {
case subpaths.editFreeListings:
return <EditFreeCampaign />;
Expand Down

0 comments on commit 74949bc

Please sign in to comment.