From bd842ee73a87aa4d686ad2ce9ae6158c072e405c Mon Sep 17 00:00:00 2001 From: Halla Moore Date: Tue, 10 Jan 2017 17:26:06 -0800 Subject: [PATCH] fix(preference-accounts): Don't select accounts that no longer exist Summary: After updating an account's connection settings, there's a brief moment where the selected account isn't null, but doesn't actually exist in the AccountStore. This throws a bunch of undefined errors, so this diff makes sure we discard that selection. Fixes T7452 Test Plan: tested locally Reviewers: evan, juan Reviewed By: juan Maniphest Tasks: T7452 Differential Revision: https://phab.nylas.com/D3634 --- .../preferences/lib/tabs/preferences-accounts.jsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal_packages/preferences/lib/tabs/preferences-accounts.jsx b/internal_packages/preferences/lib/tabs/preferences-accounts.jsx index 07f65211d..9b933a570 100644 --- a/internal_packages/preferences/lib/tabs/preferences-accounts.jsx +++ b/internal_packages/preferences/lib/tabs/preferences-accounts.jsx @@ -26,9 +26,18 @@ class PreferencesAccounts extends React.Component { getStateFromStores({selected} = {}) { const accounts = AccountStore.accounts() + let selectedAccount; + if (selected) { + selectedAccount = _.findWhere(accounts, {id: selected.id}) + } + // If selected was null or no longer exists in the AccountStore, + // just use the first account. + if (!selectedAccount) { + selectedAccount = accounts[0]; + } return { accounts, - selected: selected ? _.findWhere(accounts, {id: selected.id}) : accounts[0], + selected: selectedAccount, }; }