Skip to content

Commit

Permalink
Hide connect GA4 CTA and show a text if no access.
Browse files Browse the repository at this point in the history
  • Loading branch information
hussain-t committed Dec 1, 2022
1 parent f5160c8 commit a091984
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion assets/js/components/settings/SettingsActiveModule/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ import Badge from '../../Badge';
import { trackEvent } from '../../../util';
import useViewContext from '../../../hooks/useViewContext';
import { CORE_FORMS } from '../../../googlesitekit/datastore/forms/constants';
import { FORM_SETUP } from '../../../modules/analytics/datastore/constants';
import {
FORM_SETUP,
MODULES_ANALYTICS,
} from '../../../modules/analytics/datastore/constants';
import { CORE_USER } from '../../../googlesitekit/datastore/user/constants';
const { useSelect, useDispatch } = Data;

export default function Header( { slug } ) {
Expand All @@ -77,6 +81,22 @@ export default function Header( { slug } ) {
select( CORE_MODULES ).isModuleConnected( 'analytics-4' )
);

const loggedInUserID = useSelect( ( select ) =>
select( CORE_USER ).getID()
);
const hasAnalyticsAccess = useSelect( ( select ) => {
if ( ! ( slug === 'analytics' && module?.connected ) ) {
return false;
}

const moduleOwnerID = select( MODULES_ANALYTICS ).getOwnerID();

if ( moduleOwnerID === loggedInUserID ) {
return true;
}
return select( CORE_MODULES ).hasModuleAccess( 'analytics' );
} );

const { setValues } = useDispatch( CORE_FORMS );

const openHeader = useCallback( () => {
Expand Down Expand Up @@ -237,6 +257,7 @@ export default function Header( { slug } ) {

{ connected &&
slug === 'analytics' &&
hasAnalyticsAccess &&
! isGA4Connected && (
<Fragment>
<Button
Expand All @@ -251,6 +272,19 @@ export default function Header( { slug } ) {
</Fragment>
) }

{ connected &&
slug === 'analytics' &&
! hasAnalyticsAccess &&
! isGA4Connected && (
<p className="googlesitekit-settings-module__status">
{ __(
'Google Analytics 4 is not connected',
'google-site-kit'
) }
<span className="googlesitekit-settings-module__status-icon googlesitekit-settings-module__status-icon--not-connected" />
</p>
) }

{ ! connected && (
<Fragment>
<Button
Expand Down

0 comments on commit a091984

Please sign in to comment.