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

Bug/5183 adsense api account status #5195

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 7 additions & 9 deletions assets/js/modules/adsense/components/setup/v2/SetupAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ export default function SetupAccount( { account, finishSetup } ) {
select( MODULES_ADSENSE ).getClientID()
);

const clients = useSelect( ( select ) =>
select( MODULES_ADSENSE ).getClients( accountID )
);

const site = useSelect( ( select ) =>
select( MODULES_ADSENSE ).getCurrentSite( accountID )
);
Expand All @@ -77,6 +73,8 @@ export default function SetupAccount( { account, finishSetup } ) {
useEffect( () => {
if ( afcClient?._id && clientID !== afcClient._id ) {
setClientID( afcClient._id );
} else if ( afcClient === null && !! clientID ) {
setClientID( '' );
}
}, [ afcClient, clientID, setClientID ] );

Expand All @@ -87,8 +85,8 @@ export default function SetupAccount( { account, finishSetup } ) {
}, [ setSiteStatus, site ] );

useEffect( () => {
// Do nothing if clients aren't loaded because we can't determine afcClientID yet.
if ( clients === undefined || site === undefined ) {
// Do nothing if site isn't loaded yet.
if ( site === undefined ) {
return;
}

Expand All @@ -103,10 +101,10 @@ export default function SetupAccount( { account, finishSetup } ) {
} else {
setAccountStatus( ACCOUNT_STATUS_READY );
}
}, [ accountState, afcClient, clientID, clients, setAccountStatus, site ] );
}, [ accountState, afcClient, clientID, setAccountStatus, site ] );

// Show the progress bar if clients or site aren't loaded yet.
if ( clients === undefined || site === undefined ) {
// Show the progress bar if site isn't loaded yet.
if ( site === undefined ) {
return <ProgressBar />;
}

Expand Down
16 changes: 14 additions & 2 deletions assets/js/modules/adsense/components/setup/v2/SetupMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,23 @@ export default function SetupMain( { finishSetup } ) {

// Update current account ID setting on-the-fly.
useEffect( () => {
if ( ! Array.isArray( accounts ) ) {
return;
}

let newAccountID;

if (
accounts?.length === 1 &&
accounts.length === 1 &&
( ! accountID || accounts[ 0 ]._id !== accountID )
) {
setAccountID( accounts[ 0 ]._id );
newAccountID = accounts[ 0 ]._id;
} else if ( accounts.length === 0 && !! accountID ) {
newAccountID = '';
}

if ( newAccountID !== undefined ) {
setAccountID( newAccountID );
// Set flag to await background submission.
setIsAwaitingBackgroundSubmit( true );
}
Expand Down