summaryrefslogtreecommitdiffstats
path: root/webapp/components/member_list_team.jsx
blob: 9f18fba33e1f9ff94fbd5914159bc97f5dbbf731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import FilteredUserList from './filtered_user_list.jsx';
import TeamMembersDropdown from './team_members_dropdown.jsx';
import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import * as AsyncClient from 'utils/async_client.jsx';

import React from 'react';

export default class MemberListTeam extends React.Component {
    constructor(props) {
        super(props);

        this.getUsers = this.getUsers.bind(this);
        this.onChange = this.onChange.bind(this);
        this.onTeamChange = this.onTeamChange.bind(this);

        this.state = {
            users: this.getUsers(),
            teamMembers: TeamStore.getMembersForTeam()
        };
    }

    componentDidMount() {
        UserStore.addChangeListener(this.onChange);
        TeamStore.addChangeListener(this.onTeamChange);
        AsyncClient.getTeamMembers(TeamStore.getCurrentId());
    }

    componentWillUnmount() {
        UserStore.removeChangeListener(this.onChange);
        TeamStore.removeChangeListener(this.onTeamChange);
    }

    getUsers() {
        const profiles = UserStore.getProfiles();
        const users = [];

        for (const id of Object.keys(profiles)) {
            users.push(profiles[id]);
        }

        users.sort((a, b) => a.username.localeCompare(b.username));

        return users;
    }

    onChange() {
        this.setState({
            users: this.getUsers()
        });
    }

    onTeamChange() {
        this.setState({
            teamMembers: TeamStore.getMembersForTeam()
        });
    }

    render() {
        let teamMembersDropdown = null;
        if (this.props.isAdmin) {
            teamMembersDropdown = [TeamMembersDropdown];
        }

        return (
            <FilteredUserList
                style={this.props.style}
                users={this.state.users}
                teamMembers={this.state.teamMembers}
                actions={teamMembersDropdown}
            />
        );
    }
}

MemberListTeam.propTypes = {
    style: React.PropTypes.object,
    isAdmin: React.PropTypes.bool
};