-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2618 from woocommerce/feature/2567-kickoff-mc-ads…
…-account-creation Kickoff MC and Ads account creation
- Loading branch information
Showing
22 changed files
with
669 additions
and
71 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
js/src/components/google-combo-account-card/account-details.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
js/src/components/google-combo-account-card/connect-google-combo-account-card.scss
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
js/src/components/google-combo-account-card/connected-google-combo-account-card.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
6 changes: 6 additions & 0 deletions
6
js/src/components/google-combo-account-card/connected-google-combo-account-card.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
65 changes: 65 additions & 0 deletions
65
js/src/components/google-combo-account-card/getAccountCreationTexts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.