Skip to content

Commit

Permalink
Reset the account ID state in ConnectExistingAccount after account …
Browse files Browse the repository at this point in the history
…is disconnected to avoid connecting to an invalid ID.
  • Loading branch information
eason9487 committed Nov 22, 2024
1 parent eff6271 commit a686290
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ const ConnectExistingAccount = ( { onCreateClick } ) => {
}
};

const handleDisconnected = () => {
/*
* Prevent the `value` from staying on the unclaimed and disconnected account ID.
* Please note that the reset works because the `AdsAccountSelectControl` happens to
* switch between two different `AppSelectControls` so that `autoSelectFirstOption`
* can be triggered again. Otherwise, it would need to specify `key={ Boolean(value) }`
* in the `<AdsAccountSelectControl>` use of this component.
*/
setValue( undefined );
};

const getIndicator = () => {
if ( ! hasFinishedResolution ) {
return <LoadingLabel />;
Expand Down Expand Up @@ -124,6 +135,7 @@ const ConnectExistingAccount = ( { onCreateClick } ) => {
disabled={ isLoading }
isConnected={ hasGoogleAdsConnection }
onCreateNewClick={ onCreateClick }
onDisconnected={ handleDisconnected }
/>
}
/>
Expand Down

0 comments on commit a686290

Please sign in to comment.