Skip to content

Commit

Permalink
Merge pull request #2618 from woocommerce/feature/2567-kickoff-mc-ads…
Browse files Browse the repository at this point in the history
…-account-creation

Kickoff MC and Ads account creation
  • Loading branch information
ankitrox authored Oct 28, 2024
2 parents 7d31e5c + 8ab1be0 commit 7ceffde
Show file tree
Hide file tree
Showing 22 changed files with 669 additions and 71 deletions.
48 changes: 48 additions & 0 deletions js/src/components/google-combo-account-card/account-details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';

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

/**
* Account details.
* @return {JSX.Element} JSX markup.
*/
const AccountDetails = () => {
const { google } = useGoogleAccount();
const { googleAdsAccount } = useGoogleAdsAccount();
const { googleMCAccount } = useGoogleMCAccount();

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

export default AccountDetails;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import AppButton from '.~/components/app-button';
import readMoreLink from '../google-account-card/read-more-link';
import useGoogleConnectFlow from '../google-account-card/use-google-connect-flow';
import AppDocumentationLink from '../app-documentation-link';
import './connect-google-combo-account-card.scss';

/**
* @param {Object} props React props
Expand All @@ -34,7 +33,6 @@ const ConnectGoogleComboAccountCard = ( { disabled } ) => {
return (
<AccountCard
appearance={ APPEARANCE.GOOGLE }
className="gla-connect-google-combo-account-card"
disabled={ disabled }
alignIcon="top"
description={
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Internal dependencies
*/
import AccountCard, { APPEARANCE } from '../account-card';
import AccountDetails from './account-details';
import Indicator from './indicator';
import getAccountCreationTexts from './getAccountCreationTexts';
import SpinnerCard from '.~/components/spinner-card';
import useAutoCreateAdsMCAccounts from '.~/hooks/useAutoCreateAdsMCAccounts';
import './connected-google-combo-account-card.scss';

/**
* 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.
*/
const ConnectedGoogleComboAccountCard = () => {
const { hasDetermined, creatingWhich } = useAutoCreateAdsMCAccounts();
const { text, subText } = getAccountCreationTexts( creatingWhich );

if ( ! hasDetermined ) {
return <SpinnerCard />;
}

return (
<AccountCard
appearance={ APPEARANCE.GOOGLE }
alignIcon="top"
className="gla-google-combo-account-card--connected"
description={ text || <AccountDetails /> }
helper={ subText }
indicator={ <Indicator showSpinner={ Boolean( creatingWhich ) } /> }
/>
);
};

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

.gla-account-card__description {
gap: 0;
}
}
3 changes: 3 additions & 0 deletions js/src/components/google-combo-account-card/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CREATING_BOTH_ACCOUNTS = 'both';
export const CREATING_ADS_ACCOUNT = 'ads';
export const CREATING_MC_ACCOUNT = 'mc';
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import {
CREATING_ADS_ACCOUNT,
CREATING_BOTH_ACCOUNTS,
CREATING_MC_ACCOUNT,
} from './constants';

/**
* Account creation in progress description.
* @param {string|null} creatingWhich Which account is being created.
* @return {Object} Text and subtext.
*/
const getAccountCreationTexts = ( creatingWhich ) => {
let text = null;
let subText = null;

switch ( creatingWhich ) {
case CREATING_BOTH_ACCOUNTS:
text = __(
'You don’t have Merchant Center nor Google Ads accounts, so we’re creating them for you.',
'google-listings-and-ads'
);
subText = __(
'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'
);
break;

case CREATING_ADS_ACCOUNT:
text = __(
'You don’t have Google Ads account, so we’re creating one for you.',
'google-listings-and-ads'
);
subText = __(
'Required to set up conversion measurement for your store.',
'google-listings-and-ads'
);
break;

case CREATING_MC_ACCOUNT:
text = __(
'You don’t have Merchant Center account, so we’re creating one for you.',
'google-listings-and-ads'
);
subText = __(
'Required to sync products so they show on Google.',
'google-listings-and-ads'
);
break;
}

return {
text,
subText,
};
};

export default getAccountCreationTexts;
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
40 changes: 40 additions & 0 deletions js/src/components/google-combo-account-card/indicator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import ConnectedIconLabel from '.~/components/connected-icon-label';
import LoadingLabel from '.~/components/loading-label/loading-label';
import useGoogleAdsAccountReady from '.~/hooks/useGoogleAdsAccountReady';
import useGoogleMCAccount from '.~/hooks/useGoogleMCAccount';

/**
* Account creation indicator.
* Displays a loading indicator when accounts are being created or a connected icon when accounts are connected.
* @param {Object} props Component props.
* @param {boolean} props.showSpinner Whether to display a spinner.
* @return {JSX.Element|null} Indicator component.
*/
const Indicator = ( { showSpinner } ) => {
const isGoogleAdsConnected = useGoogleAdsAccountReady();
const { isReady: isGoogleMCConnected } = useGoogleMCAccount();

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

if ( isGoogleAdsConnected && isGoogleMCConnected ) {
return <ConnectedIconLabel />;
}

return null;
};

export default Indicator;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ReclaimUrlCard from '../reclaim-url-card';
import AccountCard, { APPEARANCE } from '.~/components/account-card';
import CreateAccountButton from '../create-account-button';
import useConnectMCAccount from '../useConnectMCAccount';
import useCreateMCAccount from '../useCreateMCAccount';
import useCreateMCAccount from '.~/hooks/useCreateMCAccount';
import CreatingCard from '../creating-card';
import './index.scss';

Expand Down
2 changes: 1 addition & 1 deletion js/src/components/google-mc-account-card/create-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import CreateAccountCard from './create-account-card';
import CreatingCard from './creating-card';
import ReclaimUrlCard from './reclaim-url-card';
import useCreateMCAccount from './useCreateMCAccount';
import useCreateMCAccount from '.~/hooks/useCreateMCAccount';

/**
* Create Account flow.
Expand Down
6 changes: 6 additions & 0 deletions js/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export const GOOGLE_ADS_ACCOUNT_STATUS = {
INCOMPLETE: 'incomplete',
};

export const GOOGLE_MC_ACCOUNT_STATUS = {
CONNECTED: 'connected',
DISCONNECTED: 'disconnected',
INCOMPLETE: 'incomplete',
};

export const GOOGLE_ADS_BILLING_STATUS = {
UNKNOWN: 'unknown',
PENDING: 'pending',
Expand Down
Loading

0 comments on commit 7ceffde

Please sign in to comment.