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

R2: Updated Enhanced Conversion flow #2361

Open
wants to merge 14 commits into
base: feature/2239-enhanced-conversions-panel
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* External dependencies
*/
import { noop } from 'lodash';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/

import AppButton from '.~/components/app-button';

const ConfirmButton = ( { onConfirm = noop } ) => {
return (
<AppButton isPrimary onClick={ onConfirm }>
{ __( 'Confirm', 'google-listings-and-ads' ) }
</AppButton>
);
};

export default ConfirmButton;
60 changes: 60 additions & 0 deletions js/src/components/enhanced-conversion-tracking-settings/cta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* External dependencies
*/
import { noop } from 'lodash';
import { useEffect, useCallback } from '@wordpress/element';

/**
* Internal dependencies
*/
import { useAppDispatch } from '.~/data';
import { ENHANCED_ADS_CONVERSION_STATUS } from '.~/constants';
import AppButton from '.~/components/app-button';
import EnableButton from './enable-button';
import ConfirmButton from './confirm-button';
import useAutoCheckEnhancedConversionTOS from '.~/hooks/useAutoCheckEnhancedConversionTOS';

const CTA = ( { onConfirm = noop } ) => {
const { updateEnhancedAdsConversionStatus } = useAppDispatch();
const {
acceptedCustomerDataTerms,
hasFinishedResolution,
isPolling,
setIsPolling,
} = useAutoCheckEnhancedConversionTOS();

const handleConfirm = useCallback( () => {
updateEnhancedAdsConversionStatus(
ENHANCED_ADS_CONVERSION_STATUS.ENABLED
);

onConfirm();
}, [ onConfirm, updateEnhancedAdsConversionStatus ] );

useEffect( () => {
// As soon as the terms are accepted, do not show the spinner
if ( acceptedCustomerDataTerms && isPolling ) {
setIsPolling( false );
}
}, [ acceptedCustomerDataTerms, setIsPolling, isPolling, handleConfirm ] );

const handleOnEnable = () => {
setIsPolling( true );
};

if ( ! hasFinishedResolution ) {
return null;
}

if ( isPolling ) {
return <AppButton isSecondary disabled loading />;
}

if ( ! acceptedCustomerDataTerms ) {
return <EnableButton onEnable={ handleOnEnable } />;
}

return <ConfirmButton onConfirm={ handleConfirm } />;
};

export default CTA;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { noop } from 'lodash';
import { __ } from '@wordpress/i18n';
import { external as externalIcon } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -26,9 +27,16 @@ const EnableButton = ( { onEnable = noop } ) => {
};

return (
<AppButton isPrimary onClick={ handleOnEnableEnhancedConversions }>
{ __( 'Enable Enhanced Conversions', 'google-listings-and-ads' ) }
</AppButton>
<AppButton
icon={ externalIcon }
Copy link
Collaborator

Choose a reason for hiding this comment

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

✨ perfect icon choice

iconPosition="right"
isPrimary
onClick={ handleOnEnableEnhancedConversions }
text={ __(
'Enable Enhanced Conversions',
'google-listings-and-ads'
) }
/>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import CTA from '.~/product-feed/submission-success-guide/enhanced-conversions/cta';
import CTA from './cta';

const Enable = () => {
return (
Expand Down
20 changes: 16 additions & 4 deletions js/src/hooks/useAutoCheckEnhancedConversionTOS.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { useCallback } from '@wordpress/element';
import { useCallback, useState, useEffect } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -12,12 +12,15 @@ import useWindowFocusCallbackIntervalEffect from '.~/hooks/useWindowFocusCallbac
import useAcceptedCustomerDataTerms from '.~/hooks/useAcceptedCustomerDataTerms';
import useAllowEnhancedConversions from '.~/hooks/useAllowEnhancedConversions';

const useAutoCheckEnhancedConversionTOS = () => {
const { acceptedCustomerDataTerms } = useAcceptedCustomerDataTerms();
const useAutoCheckEnhancedConversionTOS = ( shouldPoll = false ) => {
const [ isPolling, setIsPolling ] = useState( false );
const { acceptedCustomerDataTerms, hasFinishedResolution } =
useAcceptedCustomerDataTerms();
const { allowEnhancedConversions } = useAllowEnhancedConversions();
const { fetchAcceptedCustomerDataTerms } = useAppDispatch();

const polling =
isPolling &&
! acceptedCustomerDataTerms &&
allowEnhancedConversions === ENHANCED_ADS_CONVERSION_STATUS.PENDING;

Expand All @@ -29,9 +32,18 @@ const useAutoCheckEnhancedConversionTOS = () => {
fetchAcceptedCustomerDataTerms();
}, [ fetchAcceptedCustomerDataTerms, polling ] );

useEffect( () => {
setIsPolling( shouldPoll );
}, [ shouldPoll ] );

useWindowFocusCallbackIntervalEffect( checkStatus, 30 );

return polling;
return {
isPolling,
setIsPolling,
acceptedCustomerDataTerms,
hasFinishedResolution,
};
};

export default useAutoCheckEnhancedConversionTOS;
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,19 @@
* External dependencies
*/
import { noop } from 'lodash';
import { __ } from '@wordpress/i18n';
import { useCallback, Fragment } from '@wordpress/element';
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
*/
import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices';
import CTA from './cta';
import CTA from '.~/components/enhanced-conversion-tracking-settings/cta';

const Actions = ( { onModalClose = noop } ) => {
const { createNotice } = useDispatchCoreNotices();

const handleOnConfirm = useCallback( () => {
createNotice(
'info',
__( 'Status successfully set', 'google-listings-and-ads' )
);

onModalClose();
}, [ createNotice, onModalClose ] );

return (
<Fragment>
<div className="gla-submission-success-guide__space_holder" />

<CTA onConfirm={ handleOnConfirm } />
<CTA onConfirm={ onModalClose } />
</Fragment>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ jest.mock( '.~/hooks/useAllowEnhancedConversions', () => ( {
default: jest.fn().mockName( 'useAllowEnhancedConversions' ),
} ) );

jest.mock( '.~/hooks/useDispatchCoreNotices', () => ( {
__esModule: true,
default: jest
.fn()
.mockName( 'useDispatchCoreNotices' )
.mockImplementation( () => {
return {
createNotice: jest.fn(),
};
} ),
} ) );

jest.mock( '.~/data/actions', () => ( {
...jest.requireActual( '.~/data/actions' ),
updateEnhancedAdsConversionStatus: jest
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading