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: Merge the store address setting in Step 3 into Step 1 and remove Step 3 along with the phone verification #2653

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
6817cc6
Rename hook to useStoreAddressSynced.
asvinb Oct 25, 2024
26ec20d
Merge branch 'feature/2509-consolidate-google-account-cards' into upd…
asvinb Oct 28, 2024
bd6c4fe
Add E2E tests.
asvinb Oct 28, 2024
8dc6740
Fix condition.
asvinb Oct 28, 2024
55b95fb
Adjust hook to return early if there's no MC connected account.
asvinb Oct 29, 2024
e0b7df9
Use correct paramters.
asvinb Oct 29, 2024
850944e
Adjust JSDocs.
asvinb Oct 29, 2024
4ca1f95
Add compact styles for store address account card.
asvinb Oct 29, 2024
5b81e15
No need to refetch.
asvinb Oct 29, 2024
123925d
Remove store requirements step.
asvinb Oct 29, 2024
b3a9ff9
Remove unused component.
asvinb Oct 29, 2024
ac7918c
Fix JS tests.
asvinb Oct 29, 2024
fe7d565
Fix E2E tests.
asvinb Oct 30, 2024
41f5513
Merge branch 'feature/2509-consolidate-google-account-cards' into upd…
asvinb Oct 31, 2024
babf4d6
Update store address card usage
joemcgill Oct 31, 2024
1f18092
Remove unused components
joemcgill Oct 31, 2024
bfcc39b
Remove phone account card format
joemcgill Oct 31, 2024
d2b2a38
Remvove unused useCountryCallingCodeOptions
joemcgill Oct 31, 2024
a49f43f
Streamline StoreAddressCard states and display
joemcgill Nov 1, 2024
1e0ed3b
Fix linting errors.
asvinb Nov 1, 2024
f76a955
Resolve store address before showing the card
joemcgill Nov 1, 2024
a9f5530
Improve updateGoogleMCContactInformation resolution
joemcgill Nov 1, 2024
a98a698
Merge pull request #2661 from woocommerce/update/2602-sync-mc-address…
joemcgill Nov 1, 2024
7e87761
Check MC address setup when getting setup status and remove phone ver…
joemcgill Nov 1, 2024
852dfde
Fix MerchantCenterServiceTests tests
joemcgill Nov 1, 2024
ec43e8f
Always show the address card when MC is connected
joemcgill Nov 6, 2024
4905228
Revert refresh button to previous behavior
joemcgill Nov 6, 2024
c024b95
Sync MC at the completion of step 1
joemcgill Nov 6, 2024
5098fe8
Reinstate EditStoreAddress flow in settings
joemcgill Nov 6, 2024
c1d0c25
Remove showValidation prop
joemcgill Nov 6, 2024
49c26f0
Update button text in docs/tests
joemcgill Nov 6, 2024
afdb054
Move condition.
asvinb Nov 6, 2024
d772944
Update address card copy
joemcgill Nov 6, 2024
921cd2c
Merge branch 'feature/2509-consolidate-google-account-cards' into upd…
joemcgill Nov 6, 2024
30ac53a
Add loading state to the Continue button
joemcgill Nov 7, 2024
53bab84
Update E2E tests
joemcgill Nov 7, 2024
f9ea219
Merge branch 'feature/2509-consolidate-google-account-cards' into upd…
joemcgill Nov 13, 2024
8b141d1
Update E2E tests
joemcgill Nov 13, 2024
428738c
Remove phone verification actions
joemcgill Nov 13, 2024
5c129a4
Remove useGoogleMCPhoneNumber and related selector and deps
joemcgill Nov 13, 2024
d4c0daa
Tweak address card description color
joemcgill Nov 13, 2024
059fd99
Correct inline docs
joemcgill Nov 13, 2024
49f8f82
Update ContactInformationPreview and export as default
joemcgill Nov 13, 2024
1372d3e
Remove redundant div wrapper for addressContent
joemcgill Nov 13, 2024
e49ca66
Simplify StoreAddressCard description
joemcgill Nov 13, 2024
299fad7
Use isAddressFilled from useStoreAddress hook
joemcgill Nov 13, 2024
6ad177b
Add blank line
joemcgill Nov 13, 2024
c0d25ec
Update fires tags
joemcgill Nov 14, 2024
eeb596b
Rename and simplify useStoreAddressSynced hook
joemcgill Nov 14, 2024
a1360bf
Fix handleSubmitCallback error handling
joemcgill Nov 14, 2024
e55f65e
Update E2E test docs
joemcgill Nov 14, 2024
ddbb900
Improve E2E tests
joemcgill Nov 14, 2024
866e7b6
Remove phone number validation from MerchantTrait and ContactInformat…
joemcgill Nov 14, 2024
7d49d69
Update the package-lock.json file to reflect the revmoval of the `lib…
eason9487 Nov 14, 2024
6fff925
Fix typo in JSdoc
joemcgill Nov 14, 2024
c77748c
Remove unused property
joemcgill Nov 14, 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
15 changes: 12 additions & 3 deletions js/src/components/contact-information/store-address-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { useRef, createInterpolateElement } from '@wordpress/element';
import { useRef, createInterpolateElement, useState } from '@wordpress/element';
import { CardDivider } from '@wordpress/components';
import { Spinner } from '@woocommerce/components';
import { update as updateIcon } from '@wordpress/icons';
Expand All @@ -11,6 +11,7 @@ import { getPath, getQuery } from '@woocommerce/navigation';
/**
* Internal dependencies
*/
import { useAppDispatch } from '.~/data';
import useStoreAddress from '.~/hooks/useStoreAddress';
import Section from '.~/wcdl/section';
import Subsection from '.~/wcdl/subsection';
Expand All @@ -20,6 +21,7 @@ import ValidationErrors from '.~/components/validation-errors';
import ContactInformationPreviewCard from './contact-information-preview-card';
import TrackableLink from '.~/components/trackable-link';
import mapStoreAddressErrors from './mapStoreAddressErrors';
import LoadingLabel from '.~/components/loading-label';
import { recordGlaEvent } from '.~/utils/tracks';
import './store-address-card.scss';

Expand Down Expand Up @@ -55,6 +57,8 @@ import './store-address-card.scss';
*/
const StoreAddressCard = ( { showValidation = false } ) => {
const { loaded, data, refetch } = useStoreAddress();
const [ isSaving, setSaving ] = useState( false );
const { updateGoogleMCContactInformation } = useAppDispatch();
const path = getPath();
const { subpath } = getQuery();

Expand All @@ -66,7 +70,10 @@ const StoreAddressCard = ( { showValidation = false } ) => {
}

const handleRefreshClick = () => {
refetch();
setSaving( true );
updateGoogleMCContactInformation()
.then( refetch )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this refetch is unnecessary, because updateGoogleMCContactInformation() returns the new data and updates the data store.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.catch( () => setSaving( false ) );

refetchedCallbackRef.current = ( storeAddress ) => {
const eventProps = {
Expand All @@ -80,7 +87,9 @@ const StoreAddressCard = ( { showValidation = false } ) => {
};
};

const refreshButton = (
const refreshButton = isSaving ? (
<LoadingLabel />
) : (
<AppButton
isSecondary
icon={ updateIcon }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AccountDetails from './account-details';
import Indicator from './indicator';
import getAccountCreationTexts from './getAccountCreationTexts';
import SpinnerCard from '.~/components/spinner-card';
import SyncStoreAddress from './sync-store-address';
import useAutoCreateAdsMCAccounts from '.~/hooks/useAutoCreateAdsMCAccounts';
import './connected-google-combo-account-card.scss';

Expand All @@ -22,14 +23,20 @@ const ConnectedGoogleComboAccountCard = () => {
}

return (
<AccountCard
appearance={ APPEARANCE.GOOGLE }
alignIcon="top"
className="gla-google-combo-account-card--connected"
description={ text || <AccountDetails /> }
helper={ subText }
indicator={ <Indicator showSpinner={ Boolean( creatingWhich ) } /> }
/>
<div className="gla-google-combo-account-cards">
<AccountCard
appearance={ APPEARANCE.GOOGLE }
alignIcon="top"
className="gla-google-combo-account-card--connected"
description={ text || <AccountDetails /> }
helper={ subText }
indicator={
<Indicator showSpinner={ Boolean( creatingWhich ) } />
}
/>

<SyncStoreAddress />
</div>
);
};

Expand Down
21 changes: 21 additions & 0 deletions js/src/components/google-combo-account-card/sync-store-address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Internal dependencies
*/
import StoreAddressCard from '.~/components/contact-information/store-address-card';
import useStoreAddressSynced from '.~/hooks/useStoreAddressSynced';

/*
* Renders StoreAddressCard to sync the store address if we have a connected MC account and the address needs to be synced.
* If there's no connected account or the store address has been synced, it will return null.
*/
const SyncStoreAddress = () => {
const storeAddressSynced = useStoreAddressSynced();

if ( storeAddressSynced === null || storeAddressSynced ) {
return null;
}

return <StoreAddressCard />;
};

export default SyncStoreAddress;
45 changes: 45 additions & 0 deletions js/src/hooks/useStoreAddressSynced.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* External dependencies
*/
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import useGoogleMCAccount from '.~/hooks/useGoogleMCAccount';
import { STORE_KEY } from '.~/data/constants';

/**
* Checks if the store address is synchronized with the Merchant Center (GMC) account address.
*
* @return {boolean|null} Returns `true` if the store address matches the GMC account address, otherwise, returns `false`. If the MC account is not connected or if the state is not yet determined, returns `null`.
*/
export default function useStoreAddressSynced() {
const { isReady } = useGoogleMCAccount();

return useSelect(
( select ) => {
if ( ! isReady ) {
return null;
}

const { getGoogleMCContactInformation } = select( STORE_KEY );
const contact = getGoogleMCContactInformation();

if ( ! contact ) {
return null;
}

const {
is_mc_address_different: isMCAddressDifferent,
wc_address_errors: missingRequiredFields,
} = contact;

return (
! Boolean( isMCAddressDifferent ) &&
! missingRequiredFields.length
);
},
[ isReady ]
);
}
5 changes: 4 additions & 1 deletion js/src/setup-mc/setup-stepper/setup-accounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Faqs from './faqs';
import './index.scss';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
import useGoogleAdsAccountReady from '.~/hooks/useGoogleAdsAccountReady';
import useStoreAddressSynced from '.~/hooks/useStoreAddressSynced';

/**
* Renders the disclaimer of Comparison Shopping Service (CSS).
Expand Down Expand Up @@ -89,6 +90,7 @@ const SetupAccounts = ( props ) => {
isReady: isGoogleMCReady,
} = useGoogleMCAccount();
const { hasFinishedResolution } = useGoogleAdsAccount();
const storeAddressSynced = useStoreAddressSynced();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook cannot be used here until after the MC account is connected. Otherwise it will send an API request to /gla/mc/contact-information which will result in a 401 error.

image

Either we need to incorporate useGoogleMCAccount() into the useStoreAddressSynced() hook so that it returns false early if there is no MC account, or rely on a useState() value that gets updated after the verification is made.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joemcgill . Completely missed that 🤦 . I've updated the useStoreAddressSynced hook. Let me know what you think.

const isGoogleAdsReady = useGoogleAdsAccountReady();

/**
Expand All @@ -115,7 +117,8 @@ const SetupAccounts = ( props ) => {
const isContinueButtonDisabled = ! (
hasFinishedResolution &&
isGoogleAdsReady &&
isGoogleMCReady
isGoogleMCReady &&
storeAddressSynced
);

return (
Expand Down
32 changes: 31 additions & 1 deletion tests/e2e/specs/setup-mc/step-1-accounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ test.describe( 'Set up accounts', () => {
test.beforeAll( async () => {
await setUpAccountsPage.mockAdsAccountConnected();
await setUpAccountsPage.mockMCNotConnected();
await setUpAccountsPage.mockContactInformation( {
wcAddressErrors: [],
isMCAddressDifferent: false,
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
} );

await setUpAccountsPage.goto();
} );
Expand All @@ -306,6 +310,10 @@ test.describe( 'Set up accounts', () => {
test.beforeAll( async () => {
await setUpAccountsPage.mockAdsAccountDisconnected();
await setUpAccountsPage.mockMCConnected();
await setUpAccountsPage.mockContactInformation( {
wcAddressErrors: [],
isMCAddressDifferent: false,
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
} );

await setUpAccountsPage.goto();
} );
Expand All @@ -317,11 +325,33 @@ test.describe( 'Set up accounts', () => {
} );
} );

test.describe( 'When all accounts are connected', async () => {
test.describe( 'When the store address needs to be synced and accounts are connected', async () => {
test.beforeAll( async () => {
await setUpAccountsPage.mockAdsAccountConnected();
await setUpAccountsPage.mockMCConnected();
await setUpAccountsPage.mockContactInformation( {
wcAddressErrors: [],
isMCAddressDifferent: true,
} );

await setUpAccountsPage.goto();
} );

test( 'should see "Continue" button disabled when the store address needs to be synced', async () => {
const continueButton =
await setUpAccountsPage.getContinueButton();
await expect( continueButton ).toBeDisabled();
} );
} );

test.describe( 'When all accounts are connected and store address is synced', async () => {
eason9487 marked this conversation as resolved.
Show resolved Hide resolved
test.beforeAll( async () => {
await setUpAccountsPage.mockAdsAccountConnected();
await setUpAccountsPage.mockMCConnected();
await setUpAccountsPage.mockContactInformation( {
wcAddressErrors: [],
isMCAddressDifferent: false,
} );

await setUpAccountsPage.goto();
} );
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/utils/pages/setup-mc/step-1-set-up-accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,25 @@ export default class SetUpAccountsPage extends MockRequests {
getTermsCheckbox() {
return this.page.getByLabel( /I accept the terms and conditions/ );
}

/**
* Get store address card.
*
* @return {import('@playwright/test').Locator} Get store address card.
*/
getStoreAddressCard() {
return this.page.locator( '.gla-store-address-card' );
}

/**
* Get store address refresh to sync button.
*
* @return {import('@playwright/test').Locator} Get store address refresh to sync button.
joemcgill marked this conversation as resolved.
Show resolved Hide resolved
*/
getStoreAddressRefreshToSyncButton() {
return this.getStoreAddressCard().getByRole( 'button', {
name: 'Refresh to sync',
exact: true,
} );
}
}