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 27 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
Show all changes
27 commits
Select commit Hold shift + click to select a range
1535369
Initial structure.
ankitrox Sep 18, 2024
0d7965c
Use hooks to determine existing accounts.
ankitrox Sep 19, 2024
9e9b662
Fix lint.
ankitrox Sep 19, 2024
c5023b6
Fix: CreateAccounts component.
ankitrox Sep 20, 2024
d41d825
Remove redundant props.
ankitrox Sep 20, 2024
41e6d04
Remove redundant code.
ankitrox Sep 23, 2024
6917337
Introduce hook.
ankitrox Sep 23, 2024
d1b4c77
Fix: Flicker in component due to resolution state.
ankitrox Sep 23, 2024
b997713
Update account creation checks.
ankitrox Sep 24, 2024
d293f15
Update name for resolved checks property.
ankitrox Sep 25, 2024
9ef6c13
E2E tests.
ankitrox Sep 25, 2024
767a906
Move hook to hooks directory.
ankitrox Sep 25, 2024
2de300a
Add JS tests for useCreateAccounts hook.
ankitrox Sep 25, 2024
8239b47
Add indicator style.
ankitrox Sep 25, 2024
2e16bf4
Fix css lint error.
ankitrox Sep 25, 2024
32b47d5
Refactor hook to handle either of the account creation.
ankitrox Sep 27, 2024
f55fd1d
CR feedback - round 2.
ankitrox Sep 30, 2024
95fe0cb
Add CR feedback changes.
ankitrox Oct 1, 2024
1a24f0d
Remove unwanted props.
ankitrox Oct 3, 2024
2325d7a
Use refs to remove no-deps eslint rule.
ankitrox Oct 3, 2024
a0dcb9a
Fix: e2e tests.
ankitrox Oct 3, 2024
ea3a30f
Fix: hook tests.
ankitrox Oct 3, 2024
58738f8
Lint fix.
ankitrox Oct 3, 2024
a2b5f19
Remove unnecessary act in tests.
ankitrox Oct 3, 2024
c4f0d2b
Move hooks to relevant component.
ankitrox Oct 3, 2024
0d5130f
Fix js linting.
ankitrox Oct 3, 2024
896c681
Load correct scss file in appropriate component.
asvinb Oct 3, 2024
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,16 @@
/**
* Display account info.
*
* @param {Object} props Props.
* @param {Object} props.account Account object.
* @param {string} props.text Text to display.
*/
const AccountInfo = ( { account, text } ) => {
if ( ! account?.id ) {
return null;
}

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

export default AccountInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import useGoogleAccount from '.~/hooks/useGoogleAccount';
import useGoogleMCAccount from '.~/hooks/useGoogleMCAccount';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import AccountInfo from './account-info';

/**
* Renders the description for the account creation card.
*
* @param {Object} props Props.
* @param {Object} props.accountsCreated Whether accounts have been created.
* @param {boolean} props.isCreatingBothAccounts Whether both, MC and Ads accounts are being created.
* @param {boolean} props.isCreatingMCAccount Whether Merchant Center account is being created.
* @param {boolean} props.isCreatingAdsAccount Whether Google Ads account is being created.
*/
const AccountCreationDescription = ( {
accountsCreated,
isCreatingBothAccounts,
isCreatingMCAccount,
isCreatingAdsAccount,
} ) => {
const { google } = useGoogleAccount();
const {
googleMCAccount,
hasFinishedResolution: hasFinishedResolutionForCurrentMCAccount,
} = useGoogleMCAccount();

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

const isLoadingData =
accountsCreated &&
( ! hasFinishedResolutionForCurrentMCAccount ||
! hasFinishedResolutionForCurrentAdsAccount );

const getDescription = () => {
if (
isLoadingData ||
isCreatingBothAccounts ||
isCreatingMCAccount ||
isCreatingAdsAccount
) {
if ( isCreatingBothAccounts ) {
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>
</>
);
}
}

return (
<>
<p>{ google?.email }</p>
<AccountInfo
account={ googleMCAccount }
text={ sprintf(
// Translators: %s is the Merchant Center ID
__(
'Merchant Center ID: %s',
'google-listings-and-ads'
),
googleMCAccount.id
) }
/>
<AccountInfo
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">
{ getDescription() }
</div>
);
};

export default AccountCreationDescription;
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 Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

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

/**
* 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 {
isCreatingAccounts,
isCreatingBothAccounts,
isCreatingAdsAccount,
isCreatingMCAccount,
accountCreationChecksResolved,
accountsCreated,
} = useAutoCreateAdsMCAccounts();

if ( ! accountCreationChecksResolved ) {
return <AccountCard description={ <AppSpinner /> } />;
}

const getHelper = () => {
if ( isCreatingBothAccounts ) {
return (
<p>
asvinb marked this conversation as resolved.
Show resolved Hide resolved
{ __(
'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
isCreatingBothAccounts={ isCreatingBothAccounts }
isCreatingAdsAccount={ isCreatingAdsAccount }
isCreatingMCAccount={ isCreatingMCAccount }
accountsCreated={ accountsCreated }
/>
}
helper={ getHelper() }
indicator={ getIndicator() }
/>
);
};

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

.gla-account-card__icon {
align-self: flex-start;
}

.gla-account-card__description p {
margin: 0;
}
}
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