Skip to content

Commit

Permalink
Address CR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
asvinb committed Nov 6, 2024
1 parent 75c7827 commit fea64c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import ConnectAdsFooter from './connect-ads-footer';
import ConfirmCreateModal from './confirm-create-modal';
import LoadingLabel from '.~/components/loading-label';
import useApiFetchCallback from '.~/hooks/useApiFetchCallback';
import useUpsertAdsAccount from '.~/hooks/useUpsertAdsAccount';
import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices';
import useExistingGoogleAdsAccounts from '.~/hooks/useExistingGoogleAdsAccounts';
import useGoogleAdsAccount from '.~/hooks/useGoogleAdsAccount';
Expand All @@ -26,10 +25,12 @@ import ConnectButton from '.~/components/google-ads-account-card/connect-ads/con
* ConnectAds component renders an account card to connect to an existing Google Ads account.
*
* @param {Object} props Component props.
* @param {boolean} props.finalizeAdsAccountCreation Whether the user is in the process of finalizing the Ads account creation, i.e after the user has claimed the account and the step is conversion_action.
* @param {boolean} props.isConnecting Whether the user is in the process of finalizing the Ads account creation, i.e after the user has claimed the account and the step is conversion_action.
* @param {boolean} props.isCreating Whether the user is in the process of creating a new Ads account.
* @param {Function} props.onCreate A callback to fire when creating a new account.
* @return {JSX.Element} {@link AccountCard} filled with content.
*/
const ConnectAds = ( { finalizeAdsAccountCreation } ) => {
const ConnectAds = ( { isConnecting, isCreating, onCreate } ) => {
const [ value, setValue ] = useState();
const [ isLoading, setLoading ] = useState( false );
const { createNotice } = useDispatchCoreNotices();
Expand All @@ -38,14 +39,16 @@ const ConnectAds = ( { finalizeAdsAccountCreation } ) => {
const [ showCreateNewModal, setShowCreateNewModal ] = useState( false );
const { existingAccounts: accounts, hasFinishedResolution } =
useExistingGoogleAdsAccounts();
const { googleAdsAccount, refetchGoogleAdsAccount } = useGoogleAdsAccount();
const {
googleAdsAccount,
refetchGoogleAdsAccount,
hasFinishedResolution: hasResolvedGoogleAdsAccount,
} = useGoogleAdsAccount();
const [ connectGoogleAdsAccount ] = useApiFetchCallback( {
path: '/wc/gla/ads/accounts',
method: 'POST',
data: { id: value },
} );
const [ upsertAdsAccount, { loading: creatingNewAccount } ] =
useUpsertAdsAccount();

const onCreateNew = () => {
setShowCreateNewModal( true );
Expand All @@ -57,7 +60,7 @@ const ConnectAds = ( { finalizeAdsAccountCreation } ) => {

const handleOnContinue = async () => {
setShowCreateNewModal( false );
await upsertAdsAccount();
await onCreate();
};

useEffect( () => {
Expand Down Expand Up @@ -94,7 +97,7 @@ const ConnectAds = ( { finalizeAdsAccountCreation } ) => {
}

const getIndicator = () => {
if ( ! hasFinishedResolution ) {
if ( ! hasFinishedResolution || ! hasResolvedGoogleAdsAccount ) {
return <LoadingLabel />;
}

Expand All @@ -116,15 +119,14 @@ const ConnectAds = ( { finalizeAdsAccountCreation } ) => {
};

// Show a loading state if the Ads account is being updated or if a new Ads account is being created.
// If finalizeAdsAccountCreation is true, the processing is done in `ConnectedGoogleComboAccountCard`.
if ( creatingNewAccount || finalizeAdsAccountCreation ) {
if ( isConnecting || isCreating ) {
let title = __(
'Creating a new Google Ads account',
'google-listings-and-ads'
);
let indicatorLabel = __( 'Creating…', 'google-listings-and-ads' );

if ( finalizeAdsAccountCreation ) {
if ( isConnecting ) {
title = __(
'Connecting your Google Ads account',
'google-listings-and-ads'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ConnectedGoogleComboAccountCard = () => {
const { invalidateResolution } = useAppDispatch();
const { googleAdsAccount } = useGoogleAdsAccount();
const { hasAccess, step } = useGoogleAdsAccountStatus();
const [ upsertAdsAccount ] = useUpsertAdsAccount();
const [ upsertAdsAccount, { action } ] = useUpsertAdsAccount();

const finalizeAdsAccountCreation =
hasAccess === true && step === 'conversion_action';
Expand Down Expand Up @@ -116,7 +116,9 @@ const ConnectedGoogleComboAccountCard = () => {

{ showConnectAds && (
<ConnectAds
finalizeAdsAccountCreation={ finalizeAdsAccountCreation }
isConnecting={ action === 'update' }
isCreating={ action === 'create' }
onCreate={ upsertAdsAccount }
/>
) }
</div>
Expand Down

0 comments on commit fea64c6

Please sign in to comment.