This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
user_list_row.jsx
132 lines (122 loc) · 4.45 KB
/
user_list_row.jsx
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-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
import {Client4} from 'mattermost-redux/client';
import * as Utils from 'utils/utils.jsx';
import ProfilePicture from 'components/profile_picture';
import UserProfile from 'components/user_profile';
import FormattedMarkdownMessage from 'components/formatted_markdown_message.jsx';
export default class UserListRow extends React.PureComponent {
static propTypes = {
user: PropTypes.object.isRequired,
status: PropTypes.string,
extraInfo: PropTypes.arrayOf(PropTypes.object),
actions: PropTypes.arrayOf(PropTypes.func),
actionProps: PropTypes.object,
actionUserProps: PropTypes.object,
index: PropTypes.number,
totalUsers: PropTypes.number,
userCount: PropTypes.number,
};
static defaultProps = {
extraInfo: [],
actions: [],
actionProps: {},
actionUserProps: {},
};
render() {
let buttons = null;
if (this.props.actions) {
buttons = this.props.actions.map((Action, index) => {
return (
<Action
key={index.toString()}
user={this.props.user}
index={this.props.index}
totalUsers={this.props.totalUsers}
{...this.props.actionProps}
{...this.props.actionUserProps}
/>
);
});
}
// QUICK HACK, NEEDS A PROP FOR TOGGLING STATUS
let email = this.props.user.email;
let emailStyle = 'more-modal__description';
let status;
if (this.props.extraInfo && this.props.extraInfo.length > 0) {
email = (
<FormattedMarkdownMessage
id='admin.user_item.emailTitle'
defaultMessage='**Email:** {email}'
values={{
email: this.props.user.email,
}}
/>
);
emailStyle = '';
} else if (this.props.user.status) {
status = this.props.user.status;
} else {
status = this.props.status;
}
if (this.props.user.is_bot) {
status = null;
email = null;
}
let userCountID = null;
let userCountEmail = null;
if (this.props.userCount >= 0) {
userCountID = Utils.createSafeId('userListRowName' + this.props.userCount);
userCountEmail = Utils.createSafeId('userListRowEmail' + this.props.userCount);
}
return (
<div
key={this.props.user.id}
className='more-modal__row'
>
<ProfilePicture
src={Client4.getProfilePictureUrl(this.props.user.id, this.props.user.last_picture_update)}
status={status}
size='md'
userId={this.props.user.id}
hasMention={true}
/>
<div
className='more-modal__details'
data-testid='userListItemDetails'
>
<div
id={userCountID}
className='more-modal__name'
>
<UserProfile
userId={this.props.user.id}
hasMention={true}
displayUsername={true}
/>
{' '}
{this.props.user.first_name || this.props.user.last_name || this.props.user.nickname ?
'-' : null}
{' '}
{Utils.displayFullAndNicknameForUser(this.props.user)}
</div>
<div
id={userCountEmail}
className={emailStyle}
>
{email}
</div>
{this.props.extraInfo}
</div>
<div
data-testid='userListItemActions'
className='more-modal__actions'
>
{buttons}
</div>
</div>
);
}
}