// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import $ from 'jquery';
import UserStore from 'stores/user_store.jsx';
import {Popover, Overlay} from 'react-bootstrap';
import * as Utils from 'utils/utils.jsx';
import Constants from 'utils/constants.jsx';
import Client from 'utils/web_client.jsx';
import {FormattedMessage} from 'react-intl';
import {browserHistory} from 'react-router';
import React from 'react';
export default class PopoverListMembers extends React.Component {
constructor(props) {
super(props);
this.handleShowDirectChannel = this.handleShowDirectChannel.bind(this);
this.closePopover = this.closePopover.bind(this);
}
componentDidUpdate() {
$('.member-list__popover .popover-content').perfectScrollbar();
}
componentWillMount() {
this.setState({showPopover: false});
}
handleShowDirectChannel(teammate, e) {
e.preventDefault();
Utils.openDirectChannelToUser(
teammate,
(channel, channelAlreadyExisted) => {
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
if (channelAlreadyExisted) {
this.closePopover();
}
},
() => {
this.closePopover();
}
);
}
closePopover() {
this.setState({showPopover: false});
}
render() {
const popoverHtml = [];
const members = this.props.members;
const teamMembers = UserStore.getProfilesUsernameMap();
const currentUserId = UserStore.getCurrentId();
if (members && teamMembers) {
members.sort((a, b) => {
const aName = Utils.displayUsername(a.id);
const bName = Utils.displayUsername(b.id);
return aName.localeCompare(bName);
});
members.forEach((m, i) => {
let button = '';
if (currentUserId !== m.id && this.props.channel.type !== 'D') {
button = (
this.handleShowDirectChannel(m, e)}
>