From a6862909946e8bcf4544401cf0238fd40e104e99 Mon Sep 17 00:00:00 2001 From: Eason Su Date: Fri, 22 Nov 2024 17:52:58 +0800 Subject: [PATCH] Reset the account ID state in `ConnectExistingAccount` after account is disconnected to avoid connecting to an invalid ID. --- .../connect-ads/connect-existing-account.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/src/components/google-combo-account-card/connect-ads/connect-existing-account.js b/js/src/components/google-combo-account-card/connect-ads/connect-existing-account.js index 41907de11c..cf1932c8d0 100644 --- a/js/src/components/google-combo-account-card/connect-ads/connect-existing-account.js +++ b/js/src/components/google-combo-account-card/connect-ads/connect-existing-account.js @@ -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 `` use of this component. + */ + setValue( undefined ); + }; + const getIndicator = () => { if ( ! hasFinishedResolution ) { return ; @@ -124,6 +135,7 @@ const ConnectExistingAccount = ( { onCreateClick } ) => { disabled={ isLoading } isConnected={ hasGoogleAdsConnection } onCreateNewClick={ onCreateClick } + onDisconnected={ handleDisconnected } /> } />