Skip to content

Commit

Permalink
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
Browse files Browse the repository at this point in the history
…ads-account
  • Loading branch information
asvinb committed Nov 8, 2024
2 parents b89142d + 83374a1 commit 4fd8997
Showing 1 changed file with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/**
* External dependencies
*/
import { useEffect, useRef, useState } from '@wordpress/element';
import { useEffect } from '@wordpress/element';

/**
* Internal dependencies
*/
import { useAppDispatch } from '.~/data';
import { GOOGLE_ADS_ACCOUNT_STATUS } from '.~/constants';
import AccountCard, { APPEARANCE } from '../account-card';
import ConnectAds from './connect-ads';
import AccountDetails from './account-details';
Expand All @@ -31,12 +32,6 @@ import './connected-google-combo-account-card.scss';
* It will also kickoff Ads and Merchant Center account creation if the user does not have accounts.
*/
const ConnectedGoogleComboAccountCard = () => {
const [
showConversionMeasurementNotice,
setShowConversionMeasurementNotice,
] = useState( false );
const initConnected = useRef( null );

// We use a single instance of the hook to create a MC (Merchant Center) account,
// ensuring consistent results across both the main component (ConnectedGoogleComboAccountCard) and its child component (ConnectMC).
// This approach is especially useful when an MC account is automatically created, and the URL needs to be reclaimed.
Expand All @@ -58,22 +53,6 @@ const ConnectedGoogleComboAccountCard = () => {
const finalizeAdsAccountCreation =
hasAccess === true && step === 'conversion_action';

// Show the conversion measurement notice after the account is ready.
useEffect( () => {
if ( isConnected === null ) {
return;
}

if ( isConnected && initConnected.current === false ) {
setShowConversionMeasurementNotice( true );
}

// Store the initial isConnected state.
if ( initConnected.current === null ) {
initConnected.current = isConnected;
}
}, [ isConnected ] );

// Ideally updating the account should be done in ConnectMC component but the latter is not always rendered,
// (for e.g when the user is creating the first account).
useEffect( () => {
Expand Down Expand Up @@ -115,6 +94,9 @@ const ConnectedGoogleComboAccountCard = () => {
( Boolean( creatingWhich ) && ! shouldClaimGoogleAdsAccount ) ||
( ! showConnectAds && finalizeAdsAccountCreation );

const showConversionMeasurementNotice =
googleAdsAccount.status === GOOGLE_ADS_ACCOUNT_STATUS.CONNECTED ||
googleAdsAccount.step === 'link_merchant';
return (
<div>
<AccountCard
Expand Down

0 comments on commit 4fd8997

Please sign in to comment.