summaryrefslogtreecommitdiffstats
path: root/web/react/components/team_members.jsx
blob: 0cd22437efeb17c2cea93b2791a7520ef89a0a49 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.

var UserStore = require('../stores/user_store.jsx');
var MemberListTeam = require('./member_list_team.jsx');
var utils = require('../utils/utils.jsx');

function getStateFromStores() {
    var users = UserStore.getProfiles();
    var memberList = [];
    for (var id in users) {
        if (users.hasOwnProperty(id)) {
            memberList.push(users[id]);
        }
    }

    memberList.sort(function sort(a, b) {
        if (a.username < b.username) {
            return -1;
        }

        if (a.username > b.username) {
            return 1;
        }

        return 0;
    });

    return {
        member_list: memberList
    };
}

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

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

        this.state = getStateFromStores();
    }

    componentDidMount() {
        UserStore.addChangeListener(this.onChange);

        var self = this;
        $(React.findDOMNode(this.refs.modal)).on('hidden.bs.modal', function show() {
            self.setState({render_members: false});
        });

        $(React.findDOMNode(this.refs.modal)).on('show.bs.modal', function hide() {
            self.setState({render_members: true});
        });
    }

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

    onChange() {
        var newState = getStateFromStores();
        if (!utils.areStatesEqual(newState, this.state)) {
            this.setState(newState);
        }
    }

    render() {
        var serverError = null;

        if (this.state.server_error) {
            serverError = <label className='has-error control-label'>{this.state.server_error}</label>;
        }

        var renderMembers = '';

        if (this.state.render_members) {
            renderMembers = <MemberListTeam users={this.state.member_list} />;
        }

        return (
            <div
                className='modal fade'
                ref='modal'
                id='team_members'
                tabIndex='-1'
                role='dialog'
                aria-hidden='true'
            >
                <div className='modal-dialog'>
                    <div className='modal-content'>
                        <div className='modal-header'>
                            <button
                                type='button'
                                className='close'
                                data-dismiss='modal'
                                aria-label='Close'
                            >
                                <span aria-hidden='true'>×</span>
                            </button>
                            <h4
                                className='modal-title'
                                id='myModalLabel'
                            >{this.props.teamDisplayName + ' Members'}</h4>
                        </div>
                        <div
                            ref='modalBody'
                            className='modal-body'
                        >
                            <div className='channel-settings'>
                                <div className='team-member-list'>
                                    {renderMembers}
                                </div>
                                {serverError}
                            </div>
                        </div>
                        <div className='modal-footer'>
                            <button
                                type='button'
                                className='btn btn-default'
                                data-dismiss='modal'
                            >Close</button>
                        </div>
                    </div>
               </div>
            </div>
        );
    }
}

TeamMembers.propTypes = {
    teamDisplayName: React.PropTypes.string
};