Skip to content

Commit

Permalink
If audiences is setting up return early from mount.
Browse files Browse the repository at this point in the history
  • Loading branch information
hussain-t committed Oct 22, 2024
1 parent 2979c8b commit b71a167
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import { useDispatch } from 'googlesitekit-data';
import { useDispatch, useSelect } from 'googlesitekit-data';
import AudienceTileLoading from '../AudienceTilesWidget/AudienceTile/AudienceTileLoading';
import { MODULES_ANALYTICS_4 } from '../../../../datastore/constants';
import AudienceSegmentationErrorWidget from '../AudienceSegmentationErrorWidget';
import { isInsufficientPermissionsError } from '../../../../../../util/errors';

export default function SecondaryUserSetupWidget( { Widget } ) {
const [ setupError, setSetupError ] = useState( null );
const isSettingUpAudiences = useSelect( ( select ) =>
select( MODULES_ANALYTICS_4 ).isSettingUpAudiences()
);
const { enableSecondaryUserAudienceGroup } =
useDispatch( MODULES_ANALYTICS_4 );

Expand All @@ -50,6 +53,10 @@ export default function SecondaryUserSetupWidget( { Widget } ) {
};

useMount( () => {
if ( isSettingUpAudiences ) {
return;
}

( async () => {
const { error } = await enableSecondaryUserAudienceGroup();
if ( error ) {
Expand Down

0 comments on commit b71a167

Please sign in to comment.