Skip to content

Commit

Permalink
Reset the property ID when selecting a different account.
Browse files Browse the repository at this point in the history
  • Loading branch information
tofumatt committed Apr 16, 2023
1 parent 3ecfabd commit 5203129
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion assets/js/modules/analytics/components/common/AccountSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import { Select, Option } from '../../../../material-components';
import { MODULES_ANALYTICS, ACCOUNT_CREATE } from '../../datastore/constants';
import { trackEvent } from '../../../../util';
import useViewContext from '../../../../hooks/useViewContext';
import {
MODULES_ANALYTICS_4,
PROPERTY_CREATE,
} from '../../../analytics-4/datastore/constants';
const { useSelect, useDispatch } = Data;

export default function AccountSelect( { hasModuleAccess } ) {
Expand All @@ -46,20 +50,25 @@ export default function AccountSelect( { hasModuleAccess } ) {
select( MODULES_ANALYTICS ).hasFinishedResolution( 'getAccounts' )
);

const { setPropertyID } = useDispatch( MODULES_ANALYTICS_4 );

const { selectAccount } = useDispatch( MODULES_ANALYTICS );
const onChange = useCallback(
( index, item ) => {
const newAccountID = item.dataset.value;
if ( accountID !== newAccountID ) {
selectAccount( newAccountID );

// Reset the property ID.
setPropertyID( PROPERTY_CREATE );
const action =
newAccountID === ACCOUNT_CREATE
? 'change_account_new'
: 'change_account';
trackEvent( `${ viewContext }_analytics`, action );
}
},
[ accountID, selectAccount, viewContext ]
[ accountID, selectAccount, setPropertyID, viewContext ]
);

if ( ! hasResolvedAccounts ) {
Expand Down

0 comments on commit 5203129

Please sign in to comment.