summaryrefslogtreecommitdiffstats
path: root/web/react/components/member_list_item.jsx
blob: 357fd49a8784ac9f29585a4235502d95a7400725 (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
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.

var ChannelStore = require('../stores/channel_store.jsx');
var UserStore = require('../stores/user_store.jsx');

module.exports = React.createClass({
    displayName: 'MemberListItem',
    handleInvite: function(e) {
        e.preventDefault();
        this.props.handleInvite(this.props.member.id);
    },
    handleRemove: function(e) {
        e.preventDefault();
        this.props.handleRemove(this.props.member.id);
    },
    handleMakeAdmin: function(e) {
        e.preventDefault();
        this.props.handleMakeAdmin(this.props.member.id);
    },
    render: function() {

        var member = this.props.member;
        var isAdmin = this.props.isAdmin;
        var isMemberAdmin = member.roles.indexOf("admin") > -1;

        var invite;
        if (member.invited && this.props.handleInvite) {
            invite = <span className="member-role">Added</span>;
        } else if (this.props.handleInvite) {
            invite = <a onClick={this.handleInvite} className="btn btn-sm btn-primary member-invite"><i className="glyphicon glyphicon-envelope"/>  Add</a>;
        } else if (isAdmin && !isMemberAdmin && (member.id != UserStore.getCurrentId())) {
            var self = this;
            invite = (
                        <div className="dropdown member-drop">
                            <a href="#" className="dropdown-toggle theme" type="button" id="channel_header_dropdown" data-toggle="dropdown" aria-expanded="true">
                                <span className="text-capitalize">{member.roles || 'Member'}  </span>
                                <span className="caret"></span>
                            </a>
                            <ul className="dropdown-menu member-menu" role="menu" aria-labelledby="channel_header_dropdown">
                                { this.props.handleMakeAdmin ?
                                <li role="presentation"><a href="" role="menuitem" onClick={self.handleMakeAdmin}>Make Admin</a></li>
                                : null }
                                { this.props.handleRemove ?
                                <li role="presentation"><a href="" role="menuitem" onClick={self.handleRemove}>Remove Member</a></li>
                                : null }
                            </ul>
                        </div>
                    );
        } else {
            invite = <div className="member-role text-capitalize" style={{marginRight: 15}}>{member.roles || 'Member'}</div>;
        }

        return (
            <div className="row member-div">
                <img className="post-profile-img pull-left" src={"/api/v1/users/" + member.id + "/image"} height="36" width="36" />
                <span className="member-name">{member.username}</span>
                <span className="member-email">{member.email}</span>
                { invite }
            </div>
        );
    }
});