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
This commit is contained in:
Halla Moore 2017-01-10 17:26:06 -08:00
parent 71c00776ff
commit bd842ee73a

View file

@ -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,
};
}