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

Onboarding: Connect to existing Ads account in Google Accounts Card #2640

Merged
Show file tree
Hide file tree
Changes from 41 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 Oct 4, 2024
f73c4b2
Conflict resolution
ankitrox Oct 4, 2024
96e3ef2
Add rendering condition.
ankitrox Oct 4, 2024
7e73f98
Separate components for body and footer.
ankitrox Oct 4, 2024
ba5ca7b
Connected label styling
ankitrox Oct 4, 2024
df93a29
Pass isVisible prop to card component.
ankitrox Oct 4, 2024
6fce3e6
Use ref for keeping connected account selected.
ankitrox Oct 4, 2024
4173593
Add E2E tests.
ankitrox Oct 4, 2024
2466f7e
Fix lint css.
ankitrox Oct 4, 2024
a4d0eb4
Fix: E2E tests.
ankitrox Oct 8, 2024
f4fb5c2
Resolve conflicts and merge base branch.
ankitrox Oct 8, 2024
4ef6d25
Add styling for select.
ankitrox Oct 8, 2024
32864c3
CR feedback.
ankitrox Oct 14, 2024
2e6bcfe
Resolve conflicts and merge base branch.
ankitrox Oct 15, 2024
2b7c811
Update tests.
ankitrox Oct 15, 2024
aa6a670
Resolve conflicts and merge base branch.
ankitrox Oct 18, 2024
fbb199f
CR feedback.
ankitrox Oct 18, 2024
c20fbea
Fix: E2E tests.
ankitrox Oct 18, 2024
7c9c848
CR feedback.
ankitrox Oct 18, 2024
57023bc
Resolve conflicts and merge base branch.
ankitrox Oct 22, 2024
9617a63
CR feedback round 2.
ankitrox Oct 22, 2024
9475fa2
Fix: lint js.
ankitrox Oct 22, 2024
8a562d1
Rename ConnectCTA to ConnectButton.
asvinb Oct 22, 2024
693efd2
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox Oct 22, 2024
63c4fba
Add nonInteractive prop to app-select.
asvinb Oct 22, 2024
a83c242
Merge branch 'update/2596-connect-ads-account' of github.com:woocomme…
asvinb Oct 22, 2024
73350ef
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox Oct 22, 2024
d58278e
Fix: E2E.
ankitrox Oct 22, 2024
5c3c5c3
Resolve conflicts and merge base branch.
ankitrox Oct 23, 2024
47a0c3d
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox Oct 23, 2024
713afc0
Remove redundant prop.
ankitrox Oct 23, 2024
5dd622e
Fix: E2E failing test.
ankitrox Oct 24, 2024
87c0686
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox Oct 24, 2024
1299ad1
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox Oct 24, 2024
efe843a
Resolve conflicts and merge base branch.
ankitrox Oct 24, 2024
da1a10e
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox Oct 25, 2024
690067d
Fix: styling the tertiary link.
ankitrox Oct 25, 2024
fe1b2ec
Fix: lint css error.
ankitrox Oct 25, 2024
6f85011
Resolve conflicts and merge base branch.
ankitrox Oct 25, 2024
60a101a
Merge branch 'feature/2567-kickoff-mc-ads-account-creation' into upda…
ankitrox Oct 28, 2024
098b886
Fix: failing E2E test
ankitrox Oct 28, 2024
0046434
Fix: E2E tests.
ankitrox Oct 29, 2024
b449092
Merge branch 'feature/2509-consolidate-google-account-cards' into upd…
ankitrox Oct 29, 2024
31c35a8
CR feedback.
ankitrox Oct 29, 2024
f12e5e3
Update condition for isConnected google ads account.
ankitrox Oct 29, 2024
5632913
Use useGoogleAdsAccountReady hook.
ankitrox Oct 29, 2024
2724b0f
Revert the css change.
ankitrox Oct 29, 2024
e5edd82
Update AccountCard component
joemcgill Oct 30, 2024
4901758
Update ConnectAds to use new AccountCard
joemcgill Oct 30, 2024
0b23082
Update docblocks to AccountCard
joemcgill Oct 30, 2024
c7e0e70
Delete ConnectAccountCard
joemcgill Oct 30, 2024
4c9bb4b
Delete ConnectAccountCard (realy)
joemcgill Oct 30, 2024
79a66ff
Use ConnectButton component.
asvinb Oct 31, 2024
b77f799
Merge pull request #2658 from woocommerce/update/2596-connect-ads-ref…
asvinb Oct 31, 2024
e3bbd83
Add render conditions in the connected combo card.
asvinb Oct 31, 2024
84811bd
Update E2E tests.
asvinb Oct 31, 2024
4cba145
Make label non interactive.
asvinb Oct 31, 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
9 changes: 7 additions & 2 deletions js/src/components/app-select-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import './index.scss';
* @param {Function} [props.onChange=noop] Callback function triggered when the selected value changes. Receives the new value as an argument.
* @param {string} [props.value] The currently selected value. This component should be used as a controlled component. A special case is that after mounting, when `autoSelectFirstOption` is true and `value` is undefined, it tries to call back `onChange` once to select the first option so that the `value` can be consistent with the `<select>` element's own value.
* @param {boolean} [props.autoSelectFirstOption=false] If true, automatically triggers the onChange callback with the first option as value when no value is provided. If only one option is available, the select control is also changed to non-interactive.
* @param {boolean} [props.nonInteractive=false] If true, the select control is changed to non-interactive.
* @param {*} [props.rest] Additional props passed to the `SelectControl` component.
*/
const AppSelectControl = ( props ) => {
Expand All @@ -29,6 +30,7 @@ const AppSelectControl = ( props ) => {
onChange = noop,
value,
autoSelectFirstOption = false,
nonInteractive = false,
...rest
} = props;
const shouldAutoSelectOnceRef = useRef( autoSelectFirstOption === true );
Expand All @@ -52,12 +54,15 @@ const AppSelectControl = ( props ) => {
};

const hasSingleValueStyle = autoSelectFirstOption && options?.length === 1;
if ( hasSingleValueStyle ) {
if ( hasSingleValueStyle || nonInteractive ) {
selectProps = {
...selectProps,
suffix: ' ',
tabIndex: '-1',
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
style: {
pointerEvents: 'none',
},
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
readOnly: true,
tabIndex: -1,
};
}

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

/**
* Internal dependencies
*/
import AppButton from '.~/components/app-button';
import useEventPropertiesFilter from '.~/hooks/useEventPropertiesFilter';
import { FILTER_ONBOARDING } from '.~/utils/tracks';

/**
* Clicking on the button to connect an existing Google Ads account.
*
* @event gla_ads_account_connect_button_click
* @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.
*/

/**
* Connect CTA component.
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {Object} props Props.
* @param {Function} props.handleConnectClick Callback to handle the connect click.
* @param {string} props.value Connected account ID.
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
* @fires gla_ads_account_connect_button_click when "Connect" button is clicked.
* @return {JSX.Element} Connect CTA component.
*/
const ConnectButton = ( { handleConnectClick, value } ) => {
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
const getEventProps = useEventPropertiesFilter( FILTER_ONBOARDING );

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 ConnectButton;
19 changes: 5 additions & 14 deletions js/src/components/google-ads-account-card/connect-ads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import { CardDivider } from '@wordpress/components';
import AccountCard, { APPEARANCE } from '.~/components/account-card';
import AppButton from '.~/components/app-button';
import AppDocumentationLink from '.~/components/app-documentation-link';
import ConnectButton from './connect-button';
import ContentButtonLayout from '.~/components/content-button-layout';
import LoadingLabel from '.~/components/loading-label';
import Section from '.~/wcdl/section';
import Subsection from '.~/wcdl/subsection';
import useApiFetchCallback from '.~/hooks/useApiFetchCallback';
import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import useEventPropertiesFilter from '.~/hooks/useEventPropertiesFilter';
import AdsAccountSelectControl from '.~/components/ads-account-select-control';
import { useAppDispatch } from '.~/data';
import { FILTER_ONBOARDING } from '.~/utils/tracks';
import './index.scss';

/**
Expand Down Expand Up @@ -49,7 +48,6 @@ const ConnectAds = ( props ) => {
data: { id: value },
} );
const { refetchGoogleAdsAccount } = useGoogleAdsAccount();
const getEventProps = useEventPropertiesFilter( FILTER_ONBOARDING );
const { createNotice } = useDispatchCoreNotices();
const { fetchGoogleAdsAccountStatus } = useAppDispatch();

Expand Down Expand Up @@ -131,17 +129,10 @@ const ConnectAds = ( props ) => {
) }
/>
) : (
<AppButton
isSecondary
disabled={ ! value }
eventName="gla_ads_account_connect_button_click"
eventProps={ getEventProps( {
id: Number( value ),
} ) }
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
onClick={ handleConnectClick }
>
{ __( 'Connect', 'google-listings-and-ads' ) }
</AppButton>
<ConnectButton
handleConnectClick={ handleConnectClick }
value={ value }
/>
) }
</ContentButtonLayout>
</Section.Card.Body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AccountDetails = () => {
<>
<p>{ google.email }</p>
<p>
{ googleMCAccount.id > 0 &&
{ googleMCAccount?.id > 0 &&
sprintf(
// Translators: %s is the Merchant Center ID
__(
Expand All @@ -34,7 +34,7 @@ const AccountDetails = () => {
) }
</p>
<p>
{ googleAdsAccount.id > 0 &&
{ googleAdsAccount?.id > 0 &&
sprintf(
// Translators: %s is the Google Ads ID
__( 'Google Ads ID: %s', 'google-listings-and-ads' ),
Expand Down
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.
* @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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.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;

.app-button,
.components-button.is-tertiary:hover:not(:disabled,[aria-disabled="true"]) {
background: none;
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
padding-left: 0;
}
}

.gla-connected-icon-label {
flex-basis: content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import AdsAccountSelectControl from '.~/components/ads-account-select-control';
import ContentButtonLayout from '.~/components/content-button-layout';
import ConnectButton from '.~/components/google-ads-account-card/connect-ads/connect-button';
import LoadingLabel from '.~/components/loading-label/loading-label';
import ConnectedIconLabel from '.~/components/connected-icon-label';

/**
* ConnectAdsBody component.
*
* @param {Object} props Props.
* @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.
* @return {JSX.Element} Body component.
*/
const ConnectAdsBody = ( {
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
value={ value }
onChange={ setValue }
autoSelectFirstOption={ true }
asvinb marked this conversation as resolved.
Show resolved Hide resolved
nonInteractive={ isConnected }
/>
{ isLoading ? (
<LoadingLabel
text={ __( 'Connecting…', 'google-listings-and-ads' ) }
/>
) : (
<>
{ isConnected ? (
<ConnectedIconLabel />
) : (
<ConnectButton
handleConnectClick={ handleConnectClick }
value={ value }
/>
) }
</>
) }
</ContentButtonLayout>
);
};

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

/**
* Internal dependencies
*/
import AppButton from '.~/components/app-button';
import DisconnectAccount from '.~/components/google-ads-account-card/disconnect-account';

/**
* Footer component.
*
* @return {JSX.Element} Footer component.
*/
const ConnectAdsFooter = ( { isConnected } ) => {
// If the account is connected, show the disconnect button.
if ( isConnected ) {
return <DisconnectAccount />;
}

return (
<AppButton isTertiary>
{ __(
'Or, create a new Google Ads account',
'google-listings-and-ads'
) }
</AppButton>
);
};

export default ConnectAdsFooter;
Loading