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

Consolidate accounts onboarding: Create new Google Ads account via the combo card #2651

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5b64b6b
Create new ads account.
ankitrox Oct 25, 2024
fdccdfb
Fix: lint css.
ankitrox Oct 25, 2024
ab8984e
Merge branch 'update/2596-connect-ads-account' into update/2603-creat…
ankitrox Oct 28, 2024
d4e0142
Add css.
ankitrox Oct 28, 2024
1584e33
Do not show card if account is in unclaimed status.
ankitrox Oct 28, 2024
a00d42c
Merge branch 'update/2596-connect-ads-account' into update/2603-creat…
ankitrox Oct 28, 2024
54fdfc8
Add E2E tests.
ankitrox Oct 28, 2024
3b25965
Fix: E2E issues.
ankitrox Oct 29, 2024
86a174e
Resolve conflicts in E2E.
ankitrox Oct 29, 2024
e1fca96
Resolve conflicts.
ankitrox Oct 29, 2024
073b04f
CR feedback.
ankitrox Oct 29, 2024
863a71c
Resolve conflicts.
ankitrox Oct 29, 2024
e9a071b
Merge branch 'update/2596-connect-ads-account' into update/2603-creat…
ankitrox Oct 29, 2024
3e2dcbe
Show correct text when creating an account.
asvinb Oct 30, 2024
db10842
Revert change.
asvinb Oct 30, 2024
3e4249c
Prevent complete re rendering of the card.
asvinb Oct 30, 2024
0c3f1c7
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Oct 30, 2024
f31dcc4
Fix error.
asvinb Oct 30, 2024
46aef1c
Fetch existing accounts again.
asvinb Oct 30, 2024
b93f3aa
Display updating text only when clicking the claim button.
asvinb Oct 30, 2024
d3dae92
Save WIP.
asvinb Oct 31, 2024
9f335dd
Merge branch 'feature/2509-consolidate-google-account-cards' into upd…
asvinb Oct 31, 2024
3c19aa9
Save WIP.
asvinb Oct 31, 2024
90db787
UX improvements.
asvinb Nov 4, 2024
797ea87
Review comments.
asvinb Nov 4, 2024
74ff220
Use single quotes.
asvinb Nov 4, 2024
e6222de
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 4, 2024
2d9c2cf
Use correct class name.
asvinb Nov 4, 2024
5638687
Improve 'Connect Google account' E2E tests
joemcgill Nov 4, 2024
6bb4318
Update title and indicator label.
asvinb Nov 5, 2024
d46d6ca
Merge branch 'update/2603-create-ads-account' of github.com:woocommer…
asvinb Nov 5, 2024
50e36fd
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 5, 2024
75c7827
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 6, 2024
fea64c6
Address CR feedback.
asvinb Nov 6, 2024
92fb813
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 6, 2024
01f1097
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
joemcgill Nov 6, 2024
5e81fba
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 7, 2024
fc6214d
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 7, 2024
b89142d
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 7, 2024
4fd8997
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 8, 2024
24a9c4f
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 8, 2024
bccac35
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 8, 2024
35580cb
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 8, 2024
3044904
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
asvinb Nov 8, 2024
d82c8d8
Address CR feedback.
asvinb Nov 8, 2024
4be14db
Fix ConnectAds props
joemcgill Nov 11, 2024
ab319c7
Fix E2E tests
joemcgill Nov 11, 2024
a05eb38
Merge branch 'update/2582-claim-ads-account' into update/2603-create-…
joemcgill Nov 11, 2024
d074504
Limit Ads claim updates to 3 retries
joemcgill Nov 11, 2024
51718c2
Inline docs updates
joemcgill Nov 12, 2024
3492fa5
Docblock fix
joemcgill Nov 12, 2024
54448e3
Update JSDoc.
asvinb Nov 13, 2024
55cbeb9
Merge branch 'feature/2509-consolidate-google-account-cards' into upd…
joemcgill Nov 13, 2024
f2aa1c9
E2E: Remove flaky mocks from auto account creation test
joemcgill Nov 13, 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,72 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import AppModal from '.~/components/app-modal';
import AppButton from '.~/components/app-button';
import WarningIcon from '.~/components/warning-icon';
import './confirm-create-modal.scss';

const ConfirmCreateModal = ( {
asvinb marked this conversation as resolved.
Show resolved Hide resolved
onContinue = () => {},
asvinb marked this conversation as resolved.
Show resolved Hide resolved
onRequestClose = () => {},
} ) => {
const handleCreateAccountClick = () => {
onContinue();
};

return (
<AppModal
className="gla-ads-warning-modal"
title={ __(
'Create Google Ads Account',
'google-listings-and-ads'
) }
buttons={ [
<AppButton
key="confirm"
isSecondary
eventName="gla_ads_account_warning_modal_confirm_button_click"
onClick={ handleCreateAccountClick }
asvinb marked this conversation as resolved.
Show resolved Hide resolved
>
{ __(
'Yes, I want a new account',
'google-listings-and-ads'
) }
</AppButton>,
<AppButton key="cancel" isPrimary onClick={ onRequestClose }>
{ __( 'Cancel', 'google-listings-and-ads' ) }
</AppButton>,
] }
onRequestClose={ onRequestClose }
>
<p className="gla-ads-warning-modal__warning-text">
<WarningIcon />
<span>
{ __(
'Are you sure you want to create a new Google Ads account?',
'google-listings-and-ads'
) }
</span>
</p>
<p>
{ __(
'You already have another Ads account associated with this Google account.',
'google-listings-and-ads'
) }
</p>
<p>
{ __(
'If you create a new Google Ads account, you will need to accept an invite to the account before it can be used.',
'google-listings-and-ads'
) }
</p>
</AppModal>
);
};

export default ConfirmCreateModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gla-ads-warning-modal {

.gla-ads-warning-modal__warning-text {
display: flex;
align-items: center;
gap: calc(var(--main-gap) / 3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { noop } from 'lodash';

/**
* Internal dependencies
Expand All @@ -14,14 +15,14 @@ import DisconnectAccount from '.~/components/google-ads-account-card/disconnect-
*
* @return {JSX.Element} Footer component.
*/
const ConnectAdsFooter = ( { isConnected } ) => {
const ConnectAdsFooter = ( { isConnected, onCreateNew = noop } ) => {
asvinb marked this conversation as resolved.
Show resolved Hide resolved
// If the account is connected, show the disconnect button.
if ( isConnected ) {
return <DisconnectAccount />;
}

return (
<AppButton isTertiary>
<AppButton onClick={ onCreateNew } isTertiary>
{ __(
'Or, create a new Google Ads account',
'google-listings-and-ads'
Expand Down
100 changes: 71 additions & 29 deletions js/src/components/google-combo-account-card/connect-ads/connect-ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import AccountCard from '.~/components/account-card';
import ConnectAccountCard from '../connect-account-card';
import ConnectAdsFooter from './connect-ads-footer';
import ConnectAdsBody from './connect-ads-body';
import ConfirmCreateModal from './confirm-create-modal';
import useApiFetchCallback from '.~/hooks/useApiFetchCallback';
import useCreateAccountActions from './useCreateAccountActions';
import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices';
import useExistingGoogleAdsAccounts from '.~/hooks/useExistingGoogleAdsAccounts';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import useGoogleAdsAccountReady from '.~/hooks/useGoogleAdsAccountReady';
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';
import LoadingLabel from '.~/components/loading-label/loading-label';
asvinb marked this conversation as resolved.
Show resolved Hide resolved

/**
* ConnectAds component renders an account card to connect to an existing Google Ads account.
Expand All @@ -31,13 +35,11 @@ const ConnectAds = () => {

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

const isConnected =
googleAdsAccount?.status === 'connected' ||
( googleAdsAccount?.status === 'incomplete' &&
googleAdsAccount?.step === 'link_merchant' );
const isConnected = useGoogleAdsAccountReady();

const [ value, setValue ] = useState();
const [ isLoading, setLoading ] = useState( false );
Expand All @@ -50,13 +52,25 @@ const ConnectAds = () => {
const { refetchGoogleAdsAccount } = useGoogleAdsAccount();
const { createNotice } = useDispatchCoreNotices();
const { fetchGoogleAdsAccountStatus } = useAppDispatch();
const {
creatingNewAccount,
showCreateNewModal,
onContinue,
onCreateNew,
onRequestClose,
} = useCreateAccountActions();

useEffect( () => {
if ( isConnected ) {
setValue( googleAdsAccount.id );
}
}, [ googleAdsAccount, isConnected ] );

// If the account is in unclaimed state, we don't want to show the card.
if ( hasGoogleAdsConnection && ! isConnected ) {
return null;
}

const handleConnectClick = async () => {
if ( ! value ) {
return;
Expand All @@ -66,7 +80,7 @@ const ConnectAds = () => {
try {
await fetchConnectAdsAccount();
await fetchGoogleAdsAccountStatus();
await refetchGoogleAdsAccount();
refetchGoogleAdsAccount();
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
setLoading( false );
asvinb marked this conversation as resolved.
Show resolved Hide resolved
} catch ( error ) {
setLoading( false );
Expand All @@ -80,6 +94,21 @@ const ConnectAds = () => {
}
};

if ( creatingNewAccount ) {
asvinb marked this conversation as resolved.
Show resolved Hide resolved
return (
<AccountCard
description={
<LoadingLabel
text={ __(
'Creating new ads account',
'google-listings-and-ads'
) }
/>
}
/>
);
}

// If the accounts are still being fetched, we don't want to show the card.
if (
! hasFinishedResolutionForExistingAdsAccount ||
Expand All @@ -90,27 +119,40 @@ const ConnectAds = () => {
}

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
isConnected={ isConnected }
handleConnectClick={ handleConnectClick }
isLoading={ isLoading }
setValue={ setValue }
value={ value }
<>
<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
isConnected={ isConnected }
handleConnectClick={ handleConnectClick }
isLoading={ isLoading }
setValue={ setValue }
value={ value }
/>
}
footer={
<ConnectAdsFooter
onCreateNew={ onCreateNew }
isConnected={ isConnected }
/>
}
/>
{ showCreateNewModal && (
<ConfirmCreateModal
onContinue={ onContinue }
onRequestClose={ onRequestClose }
/>
}
footer={ <ConnectAdsFooter isConnected={ isConnected } /> }
/>
) }
</>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* External dependencies
*/
import { useState } from '@wordpress/element';

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

const useCreateAccountActions = () => {
const [ creatingNewAccount, setCreatingNewAccount ] = useState( false );
const [ showCreateNewModal, setShowCreateNewModal ] = useState( false );
asvinb marked this conversation as resolved.
Show resolved Hide resolved
const [ upsertAdsAccount ] = useUpsertAdsAccount();

const onCreateNew = () => {
setShowCreateNewModal( true );
};

const onRequestClose = () => {
setShowCreateNewModal( false );
};

const onContinue = async () => {
setShowCreateNewModal( false );
setCreatingNewAccount( true );
await upsertAdsAccount();
setCreatingNewAccount( false );
};

return {
creatingNewAccount,
onContinue,
onCreateNew,
onRequestClose,
showCreateNewModal,
setShowCreateNewModal,
};
};

export default useCreateAccountActions;
Loading
Loading