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

Kickoff MC and Ads account creation #2618

Open
wants to merge 20 commits into
base: feature/2509-consolidate-google-account-cards
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';

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

/**
* Renders the description for the account creation card.
*
* @param {Object} props Props.
* @param {boolean} props.isCreatingMCAccount Whether Merchant Center account is being created.
* @param {boolean} props.isCreatingAdsAccount Whether Google Ads account is being created.
* @param {boolean} props.isLoading Whether the data is loading.
* @param {Object} props.googleMCAccount Google Merchant Center account.
* @param {Object} props.googleAdsAccount Google Ads account.
*/
const AccountCreationDescription = ( {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ankitrox Let's document the props of this component.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ankitrox the name param0 sounds weird. Let's use props as we already have in the codebase.

isCreatingMCAccount,
isCreatingAdsAccount,
isLoading = false,
googleMCAccount = {},
googleAdsAccount = {},
} ) => {
const { google } = useGoogleAccount();

const getDescription = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ankitrox Let's return early when a condition is met:

Suggested change
const getDescription = () => {
const getDescription = () => {
if ( isCreatingAccounts ) {
if ( isCreatingMCAccount && isCreatingAdsAccount ) {
return (
<p>
{ __(
'You don’t have Merchant Center nor Google Ads accounts, so we’re creating them for you.',
'google-listings-and-ads'
) }
</p>
);
}
if ( isCreatingAdsAccount ) {
return (
<>
<p>
{ __(
'You don’t have Google Ads account, so we’re creating one for you.',
'google-listings-and-ads'
) }
</p>
<em>
{ __(
'Required to set up conversion measurement for your store.',
'google-listings-and-ads'
) }
</em>
</>
);
}
if ( isCreatingMCAccount ) {
return (
<>
<p>
{ __(
'You don’t have Merchant Center account, so we’re creating one for you.',
'google-listings-and-ads'
) }
</p>
<em>
{ __(
'Required to sync products so they show on Google.',
'google-listings-and-ads'
) }
</em>
</>
);
}
}
return (
<>
<p>{ google?.email }</p>
{ googleMCAccount?.id && (
<p>
{ sprintf(
// Translators: %s is the Merchant Center ID
__(
'Merchant Center ID: %s',
'google-listings-and-ads'
),
googleMCAccount.id
) }
</p>
) }
{ googleAdsAccount?.id && (
<p>
{ sprintf(
// Translators: %s is the Google Ads ID
__(
'Google Ads ID: %s',
'google-listings-and-ads'
),
googleAdsAccount.id
) }
</p>
) }
</>
);
};

if ( isCreatingMCAccount && isCreatingAdsAccount ) {
return (
<p>
{ __(
'You don’t have Merchant Center nor Google Ads accounts, so we’re creating them for you.',
'google-listings-and-ads'
) }
</p>
);
} else if ( isCreatingAdsAccount ) {
return (
<>
<p>
{ __(
'You don’t have Google Ads account, so we’re creating one for you.',
'google-listings-and-ads'
) }
</p>
<em>
{ __(
'Required to set up conversion measurement for your store.',
'google-listings-and-ads'
) }
</em>
</>
);
} else if ( isCreatingMCAccount ) {
return (
<>
<p>
{ __(
'You don’t have Merchant Center account, so we’re creating one for you.',
'google-listings-and-ads'
) }
</p>
<em>
{ __(
'Required to sync products so they show on Google.',
'google-listings-and-ads'
) }
</em>
</>
);
}

const DisplayAccountInfo = ( { account, text } ) => {
if ( account?.id === undefined || account.id === 0 ) {
return null;
}

return <p>{ text }</p>;
};

if ( isLoading ) {
return null;
}

return (
<>
<p>{ google?.email }</p>
<DisplayAccountInfo
account={ googleMCAccount }
text={ sprintf(
// Translators: %s is the Merchant Center ID
__(
'Merchant Center ID: %s',
'google-listings-and-ads'
),
googleMCAccount.id
) }
/>
<DisplayAccountInfo
account={ googleAdsAccount }
text={ sprintf(
// Translators: %s is the Google Ads ID
__( 'Google Ads ID: %s', 'google-listings-and-ads' ),
googleAdsAccount.id
) }
/>
</>
);
};

return (
<div className="gla-connected-google-combo-account-card__description">
asvinb marked this conversation as resolved.
Show resolved Hide resolved
{ getDescription() }
</div>
);
};

export default AccountCreationDescription;
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.gla-connect-google-combo-account-card {
.gla-google-combo-account-card--connected {

.gla-account-card__helper {
font-size: $gla-font-base;
.gla-account-card__icon {
align-self: flex-start;
}

.gla-account-card__description p {
margin: 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import AccountCard, { APPEARANCE } from '../account-card';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import useGoogleMCAccount from '.~/hooks/useGoogleMCAccount';
import AppSpinner from '../app-spinner';
import useAutoCreateAdsMCAccounts from '../../hooks/useAutoCreateAdsMCAccounts';
import LoadingLabel from '../loading-label/loading-label';
import AccountCreationDescription from './account-creation-description';

/**
* Clicking on the "connect to a different Google account" button.
*
* @event gla_google_account_connect_different_account_button_click
*/

/**
* Renders a Google account card UI with connected account information.
* It will also kickoff Ads and Merchant Center account creation if the user does not have accounts.
*
* @fires gla_google_account_connect_different_account_button_click
*/
const ConnectedGoogleComboAccountCard = () => {
const {
googleMCAccount,
hasFinishedResolution: hasFinishedResolutionForCurrentMCAccount,
} = useGoogleMCAccount();

const {
googleAdsAccount,
hasFinishedResolution: hasFinishedResolutionForCurrentAdsAccount,
} = useGoogleAdsAccount();

const {
isCreatingAccounts,
isCreatingBothAccounts,
isCreatingAdsAccount,
isCreatingMCAccount,
accountCreationChecksResolved,
accountsCreated,
} = useAutoCreateAdsMCAccounts();

if (
! accountsCreated &&
( ! hasFinishedResolutionForCurrentAdsAccount ||
asvinb marked this conversation as resolved.
Show resolved Hide resolved
! hasFinishedResolutionForCurrentMCAccount ||
! accountCreationChecksResolved )
) {
return <AccountCard description={ <AppSpinner /> } />;
}

const getHelper = () => {
if ( isCreatingBothAccounts ) {
return (
<p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ankitrox Same as my previous comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above.

{ __(
'Merchant Center is required to sync products so they show on Google. Google Ads is required to set up conversion measurement for your store.',
'google-listings-and-ads'
) }
</p>
);
}

return null;
};

const getIndicator = () => {
if ( isCreatingAccounts ) {
return (
<LoadingLabel
text={ __( 'Creating…', 'google-listings-and-ads' ) }
/>
);
}

return null;
};

return (
<AccountCard
appearance={ APPEARANCE.GOOGLE }
className="gla-google-combo-account-card--connected"
description={
<AccountCreationDescription
isLoading={
! hasFinishedResolutionForCurrentAdsAccount ||
! hasFinishedResolutionForCurrentMCAccount
}
isCreatingAdsAccount={ isCreatingAdsAccount }
isCreatingMCAccount={ isCreatingMCAccount }
googleMCAccount={ googleMCAccount }
googleAdsAccount={ googleAdsAccount }
/>
}
helper={ getHelper() }
indicator={ getIndicator() }
/>
);
};

export default ConnectedGoogleComboAccountCard;
4 changes: 2 additions & 2 deletions js/src/components/google-combo-account-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import useGoogleAccount from '.~/hooks/useGoogleAccount';
import AppSpinner from '.~/components/app-spinner';
import AccountCard from '.~/components/account-card';
import RequestFullAccessGoogleAccountCard from '../google-account-card/request-full-access-google-account-card';
import { ConnectedGoogleAccountCard } from '../google-account-card';
import ConnectGoogleComboAccountCard from './connect-google-combo-account-card';
import ConnectedGoogleComboAccountCard from './connected-google-combo-account-card';

export default function GoogleComboAccountCard( { disabled = false } ) {
const { google, scope, hasFinishedResolution } = useGoogleAccount();
Expand All @@ -18,7 +18,7 @@ export default function GoogleComboAccountCard( { disabled = false } ) {
const isConnected = google?.active === 'yes';

if ( isConnected && scope.glaRequired ) {
return <ConnectedGoogleAccountCard googleAccount={ google } />;
return <ConnectedGoogleComboAccountCard />;
}

if ( isConnected && ! scope.glaRequired ) {
Expand Down
Loading
Loading