-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtile-user-list.jsx
More file actions
176 lines (151 loc) · 4.39 KB
/
tile-user-list.jsx
File metadata and controls
176 lines (151 loc) · 4.39 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { PureComponent } from 'react';
import classnames from 'classnames';
import _ from 'lodash';
import { confirmFirst } from '../utils';
import UserName from './user-name';
import { UserPicture } from './user-picture';
class UserTile extends PureComponent {
handleAcceptClick = () => {
const { user } = this.props;
user.acceptRequest(user.username);
};
handleRejectClick = () => {
const { user } = this.props;
user.rejectRequest(user.username);
};
handlePromoteClick = () => {
const { user } = this.props;
user.makeAdmin(user);
};
handleUnsubscribeClick = confirmFirst(() => {
const { user } = this.props;
user.remove(user.username);
});
handleDemoteClick = () => {
const { user } = this.props;
user.removeAdminRights(user);
};
handleRevokeClick = () => {
const { user } = this.props;
user.revokeSentRequest(user);
};
render() {
const { type, user } = this.props;
return (
<li key={user.id}>
<div className="avatar">
<UserPicture user={user} large={this.props.largePicture} />
</div>
<UserName user={user} />
{type == WITH_MUTUALS && user.isMutual ? (
<div className="user-ismutual">mutual</div>
) : (
false
)}
{type == WITH_REQUEST_HANDLES ? (
<div className="user-actions">
<a onClick={this.handleAcceptClick}>Accept</a>
<span> - </span>
<a onClick={this.handleRejectClick}>Reject</a>
</div>
) : (
false
)}
{type == WITH_REMOVE_AND_MAKE_ADMIN_HANDLES ? (
<div className="user-actions">
<a onClick={this.handlePromoteClick} title="Promote user to admin">
Promote
</a>
<span> - </span>
<a onClick={this.handleUnsubscribeClick} title="Unsubscribe user from the group">
Unsub
</a>
</div>
) : (
false
)}
{type == WITH_REMOVE_ADMIN_RIGHTS ? (
<div className="user-actions">
<a onClick={this.handleDemoteClick} title="Demote user from admin">
Demote
</a>
</div>
) : (
false
)}
{type == WITH_REVOKE_SENT_REQUEST ? (
<div className="user-actions">
<a onClick={this.handleRevokeClick} title="Revoke sent request">
Revoke
</a>
</div>
) : (
false
)}
</li>
);
}
}
const renderUsers = (type) => (user) => {
return <UserTile key={user.id} type={type} user={user} />;
};
export const PLAIN = 'PLAIN';
export const WITH_REQUEST_HANDLES = 'WITH_REQUEST_HANDLES';
export const WITH_REMOVE_AND_MAKE_ADMIN_HANDLES = 'WITH_REMOVE_AND_MAKE_ADMIN_HANDLES';
export const WITH_REMOVE_ADMIN_RIGHTS = 'WITH_REMOVE_ADMIN_RIGHTS';
export const WITH_REVOKE_SENT_REQUEST = 'WITH_REVOKE_SENT_REQUEST';
export const WITH_MUTUALS = 'WITH_MUTUALS';
function pickActions(type, props) {
switch (type) {
case WITH_REQUEST_HANDLES: {
return _.pick(props, ['acceptRequest', 'rejectRequest']);
}
case WITH_REMOVE_AND_MAKE_ADMIN_HANDLES: {
return _.pick(props, ['makeAdmin', 'remove']);
}
case WITH_REMOVE_ADMIN_RIGHTS: {
return { removeAdminRights: props.removeAdminRights };
}
case WITH_REVOKE_SENT_REQUEST: {
return { revokeSentRequest: props.revokeSentRequest };
}
}
return {};
}
export const tileUserListFactory = (config) => (props) => {
if (!props.users || props.users.length === 0) {
return false;
}
const usersData = props.users.map((user) => {
return {
..._.pick(user, [
'id',
'screenName',
'username',
'isMutual',
'profilePictureUrl',
'profilePictureLargeUrl',
'profilePictureMediumUrl',
'isGone',
]),
largePicture: config.size === 'large',
...pickActions(config.type, props),
};
});
const users = usersData.map(renderUsers(config.type));
const listClasses = classnames({
'tile-list': true,
'large-pics': config.size === 'large',
'with-actions': config.type !== PLAIN,
});
const header =
props.header && config.displayQuantity
? `${props.header} (${props.users.length})`
: props.header;
return (
<div>
<h3>{header}</h3>
<ul className={listClasses}>{users}</ul>
</div>
);
};