mattermost-mobile/app/utils/teams.js
Elias Nahum 9db040bcf7
Retry fetching teams if no teams are found (#2288)
* Retry fetching teams if no teams are found

* Remove flow
2018-10-27 00:50:19 -03:00

16 lines
480 B
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// @flow
export function selectFirstAvailableTeam(teams, primaryTeam) {
let defaultTeam;
if (primaryTeam) {
defaultTeam = teams.find((t) => t.name === primaryTeam.toLowerCase());
}
if (!defaultTeam) {
defaultTeam = Object.values(teams).sort((a, b) => a.display_name.localeCompare(b.display_name))[0];
}
return defaultTeam;
}