Skip to content

Commit

Permalink
Check for non connected state.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvinb committed Oct 7, 2024
1 parent 9475ec2 commit 3965234
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useGoogleMCAccount from '.~/hooks/useGoogleMCAccount';
import ConnectAccountCard from '../connect-account-card';
import ConnectMCBody from './connect-mc-body';
import ConnectMCFooter from './connect-mc-footer';
import SpinnerCard from '.~/components/spinner-card';

/**
* Clicking on the "Switch account" button to select a different Google Merchant Center account to connect.
Expand All @@ -25,7 +26,7 @@ import ConnectMCFooter from './connect-mc-footer';
*/

const ConnectMC = () => {
const { googleMCAccount } = useGoogleMCAccount();
const { googleMCAccount, hasFinishedResolution } = useGoogleMCAccount();
const [ value, setValue ] = useState();
const [ handleConnectMC, resultConnectMC ] = useConnectMCAccount( value );
const [ handleCreateAccount, resultCreateAccount ] = useCreateMCAccount();
Expand All @@ -34,11 +35,12 @@ const ConnectMC = () => {
// The `link_ads` step will be resolved when the Ads account is connected
// since these can be connected in any order.
const isConnected =
googleMCAccount?.id ||
googleMCAccount?.status === 'connected' ||
( googleMCAccount?.status === 'incomplete' &&
googleMCAccount?.step === 'link_ads' );

if ( resultConnectMC.response?.status === 409 ) {
if ( ! isConnected && resultConnectMC.response?.status === 409 ) {
return (
<SwitchUrlCard
id={ resultConnectMC.error.id }
Expand All @@ -51,8 +53,9 @@ const ConnectMC = () => {
}

if (
resultConnectMC.response?.status === 403 ||
resultCreateAccount.response?.status === 403
! isConnected &&
( resultConnectMC.response?.status === 403 ||
resultCreateAccount.response?.status === 403 )
) {
return (
<ReclaimUrlCard
Expand All @@ -72,8 +75,9 @@ const ConnectMC = () => {
}

if (
resultCreateAccount.loading ||
resultCreateAccount.response?.status === 503
! isConnected &&
( resultCreateAccount.loading ||
resultCreateAccount.response?.status === 503 )
) {
return (
<CreatingCard
Expand All @@ -83,6 +87,10 @@ const ConnectMC = () => {
);
}

if ( ! hasFinishedResolution ) {
return <SpinnerCard />;
}

return (
<ConnectAccountCard
title={ __(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { CardDivider } from '@wordpress/components';

/**
* Internal dependencies
Expand Down

0 comments on commit 3965234

Please sign in to comment.