-
Notifications
You must be signed in to change notification settings - Fork 21
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
Onboarding: Connect to existing Ads account in Google Accounts Card #2640
Merged
asvinb
merged 57 commits into
feature/2509-consolidate-google-account-cards
from
update/2596-connect-ads-account
Oct 31, 2024
Merged
Changes from 13 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
63b182b
Onboarding: Connect to existing Ads account in Google Accounts Card
ankitrox f73c4b2
Conflict resolution
ankitrox 96e3ef2
Add rendering condition.
ankitrox 7e73f98
Separate components for body and footer.
ankitrox ba5ca7b
Connected label styling
ankitrox df93a29
Pass isVisible prop to card component.
ankitrox 6fce3e6
Use ref for keeping connected account selected.
ankitrox 4173593
Add E2E tests.
ankitrox 2466f7e
Fix lint css.
ankitrox a4d0eb4
Fix: E2E tests.
ankitrox f4fb5c2
Resolve conflicts and merge base branch.
ankitrox 4ef6d25
Add styling for select.
ankitrox 32864c3
CR feedback.
ankitrox 2e6bcfe
Resolve conflicts and merge base branch.
ankitrox 2b7c811
Update tests.
ankitrox aa6a670
Resolve conflicts and merge base branch.
ankitrox fbb199f
CR feedback.
ankitrox c20fbea
Fix: E2E tests.
ankitrox 7c9c848
CR feedback.
ankitrox 57023bc
Resolve conflicts and merge base branch.
ankitrox 9617a63
CR feedback round 2.
ankitrox 9475fa2
Fix: lint js.
ankitrox 8a562d1
Rename ConnectCTA to ConnectButton.
asvinb 693efd2
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox 63c4fba
Add nonInteractive prop to app-select.
asvinb a83c242
Merge branch 'update/2596-connect-ads-account' of github.com:woocomme…
asvinb 73350ef
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox d58278e
Fix: E2E.
ankitrox 5c3c5c3
Resolve conflicts and merge base branch.
ankitrox 47a0c3d
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox 713afc0
Remove redundant prop.
ankitrox 5dd622e
Fix: E2E failing test.
ankitrox 87c0686
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox 1299ad1
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox efe843a
Resolve conflicts and merge base branch.
ankitrox da1a10e
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox 690067d
Fix: styling the tertiary link.
ankitrox fe1b2ec
Fix: lint css error.
ankitrox 6f85011
Resolve conflicts and merge base branch.
ankitrox 60a101a
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox 098b886
Fix: failing E2E test
ankitrox 0046434
Fix: E2E tests.
ankitrox b449092
Merge branch 'feature/2509-consolidate-google-account-cards' into upd…
ankitrox 31c35a8
CR feedback.
ankitrox f12e5e3
Update condition for isConnected google ads account.
ankitrox 5632913
Use useGoogleAdsAccountReady hook.
ankitrox 2724b0f
Revert the css change.
ankitrox e5edd82
Update AccountCard component
joemcgill 4901758
Update ConnectAds to use new AccountCard
joemcgill 0b23082
Update docblocks to AccountCard
joemcgill c7e0e70
Delete ConnectAccountCard
joemcgill 4c9bb4b
Delete ConnectAccountCard (realy)
joemcgill 79a66ff
Use ConnectButton component.
asvinb b77f799
Merge pull request #2658 from woocommerce/update/2596-connect-ads-ref…
asvinb e3bbd83
Add render conditions in the connected combo card.
asvinb 84811bd
Update E2E tests.
asvinb 4cba145
Make label non interactive.
asvinb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
js/src/components/google-combo-account-card/connect-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,50 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classNames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Section from '.~/wcdl/section'; | ||
import AccountCard from '.~/components/account-card'; | ||
import './connect-account-card.scss'; | ||
|
||
/** | ||
* ConnectAccountCard component renders an account card with a title, helper text, body, and footer sections. | ||
* | ||
* @param {Object} props Props. | ||
* @param {string} props.title The title of the account card. | ||
* @param {string} props.helperText The helper text for the account card. | ||
* @param {JSX.Element} props.body The content for the body of the account card. | ||
* @param {JSX.Element} props.footer The content for the footer of the account card. | ||
* @param {string} props.className Additional class names for the account card. | ||
asvinb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @return {JSX.Element} ConnectAccountCard component. | ||
*/ | ||
const ConnectAccountCard = ( { | ||
title, | ||
helperText, | ||
body, | ||
footer, | ||
className = '', | ||
} ) => { | ||
return ( | ||
<AccountCard | ||
className={ classNames( | ||
'gla-google-combo-service-account-card', | ||
className | ||
) } | ||
title={ title } | ||
helper={ helperText } | ||
> | ||
<Section.Card.Body className="gla-google-combo-service-account-card__body"> | ||
{ body } | ||
</Section.Card.Body> | ||
<Section.Card.Footer className="gla-google-combo-service-account-card__footer"> | ||
{ footer } | ||
</Section.Card.Footer> | ||
</AccountCard> | ||
); | ||
}; | ||
|
||
export default ConnectAccountCard; |
27 changes: 27 additions & 0 deletions
27
js/src/components/google-combo-account-card/connect-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,27 @@ | ||
.gla-google-combo-service-account-card { | ||
padding: var(--large-gap); | ||
|
||
> div { | ||
display: flex; | ||
flex-direction: column; | ||
gap: calc(var(--main-gap) / 2); | ||
} | ||
|
||
.wcdl-section-card-body, | ||
.gla-google-combo-service-account-card__body { | ||
padding: 0; | ||
|
||
.app-select-control { | ||
flex-grow: 1; | ||
} | ||
} | ||
|
||
.gla-google-combo-service-account-card__footer { | ||
border: 0; | ||
padding: 0; | ||
} | ||
|
||
.gla-connected-icon-label { | ||
flex-basis: content; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
js/src/components/google-combo-account-card/connect-ads/connect-ads-body.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,69 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AdsAccountSelectControl from '.~/components/ads-account-select-control'; | ||
import ContentButtonLayout from '.~/components/content-button-layout'; | ||
import ConnectCTA from './connect-cta'; | ||
import LoadingLabel from '.~/components/loading-label/loading-label'; | ||
|
||
/** | ||
* Clicking on the button to connect an existing Google Ads account. | ||
* | ||
* @event gla_ads_account_connect_button_click | ||
asvinb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @property {number} id The account ID to be connected. | ||
* @property {string} [context] Indicates the place where the button is located. | ||
* @property {string} [step] Indicates the step in the onboarding process. | ||
*/ | ||
|
||
/** | ||
* ConnectAdsBody component. | ||
* | ||
* @param {Object} props Props. | ||
* @param {Array} props.accounts Accounts. | ||
* @param {Object} props.googleAdsAccount Google Ads account object. | ||
* @param {boolean} props.isConnected Whether the account is connected. | ||
* @param {Function} props.handleConnectClick Callback to handle the connect click. | ||
* @param {boolean} props.isLoading Whether the card is in a loading state. | ||
* @param {Function} props.setValue Callback to set the value. | ||
* @param {string} props.value Ads account ID. | ||
* @fires gla_ads_account_connect_button_click when "Connect" button is clicked. | ||
* @return {JSX.Element} Body component. | ||
*/ | ||
const ConnectAdsBody = ( { | ||
accounts, | ||
googleAdsAccount, | ||
isConnected, | ||
handleConnectClick, | ||
eason9487 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isLoading, | ||
setValue, | ||
eason9487 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value, | ||
} ) => { | ||
return ( | ||
<ContentButtonLayout> | ||
<AdsAccountSelectControl | ||
accounts={ accounts } | ||
value={ value } | ||
onChange={ setValue } | ||
/> | ||
{ isLoading ? ( | ||
<LoadingLabel | ||
text={ __( 'Connecting…', 'google-listings-and-ads' ) } | ||
/> | ||
) : ( | ||
<ConnectCTA | ||
isConnected={ isConnected } | ||
id={ googleAdsAccount.id } | ||
handleConnectClick={ handleConnectClick } | ||
value={ value } | ||
/> | ||
) } | ||
</ContentButtonLayout> | ||
); | ||
}; | ||
|
||
export default ConnectAdsBody; |
25 changes: 25 additions & 0 deletions
25
js/src/components/google-combo-account-card/connect-ads/connect-ads-footer.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,25 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AppButton from '.~/components/app-button'; | ||
|
||
/** | ||
* Footer component. | ||
* | ||
* @return {JSX.Element} Footer component. | ||
*/ | ||
const ConnectAdsFooter = () => ( | ||
<AppButton isTertiary> | ||
{ __( | ||
'Or, create a new Google Ads account', | ||
'google-listings-and-ads' | ||
) } | ||
</AppButton> | ||
); | ||
|
||
export default ConnectAdsFooter; |
123 changes: 123 additions & 0 deletions
123
js/src/components/google-combo-account-card/connect-ads/connect-ads.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,123 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useEffect, useRef, useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AccountCard from '.~/components/account-card'; | ||
import useApiFetchCallback from '.~/hooks/useApiFetchCallback'; | ||
import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices'; | ||
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount'; | ||
import { useAppDispatch } from '.~/data'; | ||
import useExistingGoogleAdsAccounts from '.~/hooks/useExistingGoogleAdsAccounts'; | ||
import ConnectAccountCard from '../connect-account-card'; | ||
import ConnectAdsFooter from './connect-ads-footer'; | ||
import ConnectAdsBody from './connect-ads-body'; | ||
|
||
/** | ||
* ConnectAds component renders an account card to connect to an existing Google Ads account. | ||
* | ||
* @fires gla_documentation_link_click with `{ context: 'setup-ads-connect-account', link_id: 'connect-sub-account', href: 'https://support.google.com/google-ads/answer/6139186' }` | ||
eason9487 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @return {JSX.Element} {@link AccountCard} filled with content. | ||
*/ | ||
const ConnectAds = () => { | ||
eason9487 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { | ||
existingAccounts: accounts, | ||
hasFinishedResolution: hasFinishedResolutionForExistingAdsAccount, | ||
} = useExistingGoogleAdsAccounts(); | ||
|
||
const { | ||
googleAdsAccount, | ||
hasFinishedResolution: hasFinishedResolutionForCurrentAccount, | ||
} = useGoogleAdsAccount(); | ||
|
||
const isConnected = | ||
googleAdsAccount?.status === 'connected' || | ||
( googleAdsAccount?.status === 'incomplete' && | ||
googleAdsAccount?.step === 'link_merchant' ); | ||
eason9487 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const [ value, setValue ] = useState(); | ||
const [ isLoading, setLoading ] = useState( false ); | ||
const [ fetchConnectAdsAccount ] = useApiFetchCallback( { | ||
eason9487 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
path: '/wc/gla/ads/accounts', | ||
method: 'POST', | ||
data: { id: value }, | ||
} ); | ||
const { refetchGoogleAdsAccount } = useGoogleAdsAccount(); | ||
const { createNotice } = useDispatchCoreNotices(); | ||
const { fetchGoogleAdsAccountStatus } = useAppDispatch(); | ||
const initialValueRef = useRef( null ); | ||
|
||
if ( googleAdsAccount?.id ) { | ||
initialValueRef.current = googleAdsAccount.id; | ||
asvinb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
useEffect( () => { | ||
if ( initialValueRef.current ) { | ||
setValue( initialValueRef.current ); | ||
} | ||
}, [ initialValueRef ] ); | ||
|
||
const handleConnectClick = async () => { | ||
if ( ! value ) { | ||
return; | ||
} | ||
|
||
setLoading( true ); | ||
try { | ||
await fetchConnectAdsAccount(); | ||
await fetchGoogleAdsAccountStatus(); | ||
await refetchGoogleAdsAccount(); | ||
setLoading( false ); | ||
} catch ( error ) { | ||
setLoading( false ); | ||
createNotice( | ||
'error', | ||
__( | ||
'Unable to connect your Google Ads account. Please try again later.', | ||
'google-listings-and-ads' | ||
) | ||
); | ||
} | ||
}; | ||
|
||
// If the accounts are still being fetched, we don't want to show the card. | ||
if ( | ||
! hasFinishedResolutionForExistingAdsAccount || | ||
! hasFinishedResolutionForCurrentAccount || | ||
accounts.length === 0 | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ConnectAccountCard | ||
className="gla-google-combo-service-account-card--ads" | ||
title={ __( | ||
'Connect to existing Google Ads account', | ||
'google-listings-and-ads' | ||
) } | ||
helperText={ __( | ||
'Required to set up conversion measurement for your store.', | ||
'google-listings-and-ads' | ||
) } | ||
body={ | ||
<ConnectAdsBody | ||
accounts={ accounts } | ||
googleAdsAccount={ googleAdsAccount } | ||
isConnected={ isConnected } | ||
handleConnectClick={ handleConnectClick } | ||
isLoading={ isLoading } | ||
setValue={ setValue } | ||
value={ value } | ||
/> | ||
} | ||
footer={ <ConnectAdsFooter /> } | ||
/> | ||
); | ||
}; | ||
|
||
export default ConnectAds; |
47 changes: 47 additions & 0 deletions
47
js/src/components/google-combo-account-card/connect-ads/connect-cta.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,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AppButton from '.~/components/app-button'; | ||
import ConnectedIconLabel from '.~/components/connected-icon-label'; | ||
import useEventPropertiesFilter from '.~/hooks/useEventPropertiesFilter'; | ||
import { FILTER_ONBOARDING } from '.~/utils/tracks'; | ||
|
||
/** | ||
* Connect CTA component. | ||
* | ||
* @param {Object} props Props. | ||
* @param {boolean} props.isConnected Whether the account is connected. | ||
* @param {number} props.id Account ID. | ||
* @param {Function} props.handleConnectClick Callback to handle the connect click. | ||
* @param {string} props.value Connected account ID. | ||
* | ||
* @return {JSX.Element} Connect CTA component. | ||
*/ | ||
const ConnectCTA = ( { isConnected, id, handleConnectClick, value } ) => { | ||
asvinb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const getEventProps = useEventPropertiesFilter( FILTER_ONBOARDING ); | ||
|
||
if ( isConnected && id === Number( value ) ) { | ||
asvinb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return <ConnectedIconLabel />; | ||
asvinb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return ( | ||
<AppButton | ||
isSecondary | ||
disabled={ ! value } | ||
eventName="gla_ads_account_connect_button_click" | ||
eventProps={ getEventProps( { | ||
id: Number( value ), | ||
} ) } | ||
onClick={ handleConnectClick } | ||
> | ||
{ __( 'Connect', 'google-listings-and-ads' ) } | ||
</AppButton> | ||
); | ||
}; | ||
|
||
export default ConnectCTA; |
5 changes: 5 additions & 0 deletions
5
js/src/components/google-combo-account-card/connect-ads/index.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,5 @@ | ||
/** | ||
asvinb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Internal dependencies | ||
*/ | ||
|
||
export { default } from './connect-ads'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, this will updated in https://github.com/woocommerce/google-listings-and-ads/pull/2639/files#diff-8c885f578f99827b77511ccb568a741365e07f9fd3eecea8bc62ac67253ac3a3R126