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/5180 adsense create account popup #5197

Merged
merged 4 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
4 changes: 2 additions & 2 deletions assets/js/modules/adsense/components/setup/v2/SetupAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ export default function SetupAccount( { account, finishSetup } ) {
}

if ( site === null ) {
return <SetupAccountCreateSite accountID={ accountID } />;
return <SetupAccountCreateSite />;
}

if (
accountState === API_STATE_NEEDS_ATTENTION ||
afcClient?.state === API_STATE_REQUIRES_REVIEW ||
afcClient?.state === API_STATE_GETTING_READY
) {
return <SetupAccountPendingTasks accountID={ accountID } />;
return <SetupAccountPendingTasks />;
}

return <SetupAccountSite site={ site } finishSetup={ finishSetup } />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
* limitations under the License.
*/

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* WordPress dependencies
*/
Expand All @@ -37,7 +32,8 @@ import { ErrorNotices } from '../../common';
import { trackEvent } from '../../../../../util';
import useViewContext from '../../../../../hooks/useViewContext';
const { useSelect } = Data;
export default function SetupAccountCreateSite( { accountID } ) {

export default function SetupAccountCreateSite() {
const viewContext = useViewContext();

const addSiteURL = useSelect( ( select ) =>
Expand All @@ -53,10 +49,6 @@ export default function SetupAccountCreateSite( { accountID } ) {
[ addSiteURL, viewContext ]
);

if ( ! accountID || addSiteURL === undefined ) {
return null;
}

return (
<Fragment>
<h3 className="googlesitekit-heading-4 googlesitekit-setup-module__title">
Expand All @@ -83,7 +75,3 @@ export default function SetupAccountCreateSite( { accountID } ) {
</Fragment>
);
}

SetupAccountCreateSite.propTypes = {
accountID: PropTypes.string.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
* limitations under the License.
*/

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* WordPress dependencies
*/
Expand All @@ -38,7 +33,8 @@ import { ErrorNotices } from '../../common';
import { trackEvent } from '../../../../../util';
import useViewContext from '../../../../../hooks/useViewContext';
const { useSelect } = Data;
export default function SetupAccountPendingTasks( { accountID } ) {

export default function SetupAccountPendingTasks() {
const viewContext = useViewContext();

const onButtonClick = useCallback( () => {
Expand All @@ -49,10 +45,6 @@ export default function SetupAccountPendingTasks( { accountID } ) {
select( MODULES_ADSENSE ).getServiceAccountURL()
);

if ( ! accountID || ! serviceAccountURL ) {
return null;
}

return (
<Fragment>
<h3 className="googlesitekit-heading-4 googlesitekit-setup-module__title">
Expand Down Expand Up @@ -81,7 +73,3 @@ export default function SetupAccountPendingTasks( { accountID } ) {
</Fragment>
);
}

SetupAccountPendingTasks.propTypes = {
accountID: PropTypes.string.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ const { useSelect } = Data;
export default function SetupCreateAccount() {
const viewContext = useViewContext();
const eventCategory = `${ viewContext }_adsense`;
const siteURL = useSelect( ( select ) =>
select( CORE_SITE ).getReferenceSiteURL()
);
const userEmail = useSelect( ( select ) => select( CORE_USER ).getEmail() );
const existingTag = useSelect( ( select ) =>
select( MODULES_ADSENSE ).getExistingTag()
Expand All @@ -69,10 +66,6 @@ export default function SetupCreateAccount() {
[ signUpURL, eventCategory ]
);

if ( ! siteURL || ! userEmail || undefined === existingTag ) {
return null;
}

return (
<Fragment>
<h3 className="googlesitekit-heading-4 googlesitekit-setup-module__title">
Expand Down
17 changes: 16 additions & 1 deletion assets/js/modules/adsense/components/setup/v2/SetupMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import SetupSelectAccount from './SetupSelectAccount';
import { trackEvent } from '../../../../../util';
import { AdBlockerWarning, ErrorNotices } from '../../common';
import { MODULES_ADSENSE } from '../../../datastore/constants';
import { CORE_USER } from '../../../../../googlesitekit/datastore/user/constants';
import { CORE_SITE } from '../../../../../googlesitekit/datastore/site/constants';
import {
ACCOUNT_STATUS_READY,
ACCOUNT_STATUS_NONE,
Expand Down Expand Up @@ -112,6 +114,13 @@ export default function SetupMain( { finishSetup } ) {
const hasResolvedAccounts = useSelect( ( select ) =>
select( MODULES_ADSENSE ).hasFinishedResolution( 'getAccounts' )
);
const userEmail = useSelect( ( select ) => select( CORE_USER ).getEmail() );
const referenceSiteURL = useSelect( ( select ) =>
select( CORE_SITE ).getReferenceSiteURL()
);
const existingTag = useSelect( ( select ) =>
select( MODULES_ADSENSE ).getExistingTag()
);

const account = accounts?.find( ( { _id } ) => _id === accountID );

Expand Down Expand Up @@ -257,7 +266,13 @@ export default function SetupMain( { finishSetup } ) {

let viewComponent;

if ( ! hasResolvedAccounts ) {
if (
! hasResolvedAccounts ||
accountID === undefined ||
userEmail === undefined ||
referenceSiteURL === undefined ||
existingTag === undefined
) {
viewComponent = <ProgressBar />;
} else if ( hasErrors ) {
viewComponent = <ErrorNotices />;
Expand Down
13 changes: 11 additions & 2 deletions assets/js/modules/adsense/components/setup/v2/SetupMain.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function createSetupAccountStory( variation, args = {} ) {
receiveGetSites,
receiveGetURLChannels,
receiveGetExistingTag,
setAccountID,
} = registry.dispatch( MODULES_ADSENSE );

provideSiteInfo( registry, {
Expand All @@ -92,8 +93,7 @@ function createSetupAccountStory( variation, args = {} ) {
receiveGetSites( sites, { accountID } );
receiveGetSettings( { ...defaultSettings, accountID } );
receiveGetAlerts( fixtures.alerts, { accountID } );

registry.dispatch( MODULES_ADSENSE ).setAccountID( accountID );
setAccountID( accountID );

const clientID = clients.find(
( { _accountID } ) => _accountID === accountID
Expand Down Expand Up @@ -225,6 +225,15 @@ SelectAccount.args = {
},
createTime: '2013-10-17T15:51:03.000Z',
},
{
_id: 'pub-2833782679114992',
name: 'accounts/pub-2833782679114992',
displayName: 'Test Account 2',
timeZone: {
id: 'Europe/Berlin',
},
createTime: '2013-10-18T15:51:03.000Z',
},
] );
},
};
Expand Down
4 changes: 4 additions & 0 deletions assets/js/modules/adsense/datastore/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const fetchGetClientsStore = createFetchStore( {
);
},
reducerCallback: ( state, clients, { accountID } ) => {
if ( ! Array.isArray( clients ) ) {
return state;
}

return {
...state,
clients: {
Expand Down
4 changes: 4 additions & 0 deletions assets/js/modules/adsense/datastore/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const fetchGetSitesStore = createFetchStore( {
);
},
reducerCallback: ( state, sites, { accountID } ) => {
if ( ! Array.isArray( sites ) ) {
return state;
}

return {
...state,
sites: {
Expand Down