MM-27607 Fix filter undefined when searching profiles (#4657) (#4659)

(cherry picked from commit b001c50fdc)

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
Mattermost Build 2020-08-11 13:09:50 -04:00 committed by GitHub
parent 12dbcfe627
commit 72c9414993
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 10 deletions

View file

@ -276,7 +276,11 @@ export default class ChannelAddMembers extends PureComponent {
const options = {not_in_channel_id: currentChannelId, team_id: currentTeamId, group_constrained: currentChannelGroupConstrained};
this.setState({loading: true});
actions.searchProfiles(term.toLowerCase(), options).then(({data}) => {
actions.searchProfiles(term.toLowerCase(), options).then((results) => {
let data = [];
if (results.data) {
data = results.data;
}
this.setState({searchResults: data, loading: false});
});
};

View file

@ -307,7 +307,11 @@ export default class ChannelMembers extends PureComponent {
const options = {in_channel_id: currentChannelId};
this.setState({loading: true});
actions.searchProfiles(term.toLowerCase(), options).then(({data}) => {
actions.searchProfiles(term.toLowerCase(), options).then((results) => {
let data = [];
if (results.data) {
data = results.data;
}
this.setState({searchResults: data, loading: false});
});
};

View file

@ -279,20 +279,24 @@ export default class MoreDirectMessages extends PureComponent {
}
};
searchProfiles = (term) => {
searchProfiles = async (term) => {
const lowerCasedTerm = term.toLowerCase();
const {actions, currentTeamId, restrictDirectMessage} = this.props;
this.setState({loading: true});
let results;
if (restrictDirectMessage) {
actions.searchProfiles(lowerCasedTerm).then(({data}) => {
this.setState({searchResults: data, loading: false});
});
results = await actions.searchProfiles(lowerCasedTerm);
} else {
actions.searchProfiles(lowerCasedTerm, {team_id: currentTeamId}).then(({data}) => {
this.setState({searchResults: data, loading: false});
});
results = await actions.searchProfiles(lowerCasedTerm, {team_id: currentTeamId});
}
let data = [];
if (results.data) {
data = results.data;
}
this.setState({searchResults: data, loading: false});
};
startConversation = async (selectedId) => {

View file

@ -215,7 +215,11 @@ export default class SelectorScreen extends PureComponent {
const {actions} = this.props;
this.setState({loading: true});
actions.searchProfiles(term.toLowerCase()).then(({data}) => {
actions.searchProfiles(term.toLowerCase()).then((results) => {
let data = [];
if (results.data) {
data = results.data;
}
this.setState({searchResults: data, loading: false});
});
};