-
Notifications
You must be signed in to change notification settings - Fork 13
/
Members.jsx
161 lines (153 loc) · 5.72 KB
/
Members.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
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
import React from 'react';
import { Link } from 'react-router-dom';
import { Avatar, Stack, IconButton, Divider, Badge } from '@mui/material'
import {
List as SourceIcon, Loyalty as CollectionIcon, AccountBalance as OrgIcon,
AdminPanelSettings as AdminIcon, PersonOff as UserDisabledIcon,
PrivacyTip as UnverifiedIcon,
VerifiedUser as VerifiedIcon,
SafetyCheck as VerificationPendingIcon,
} from '@mui/icons-material';
import { map, chunk, isEmpty } from 'lodash';
import { GREEN, ORANGE } from '../../common/constants'
import { getUserInitials } from '../../common/utils';
import HtmlToolTipRaw from '../common/HtmlToolTipRaw';
const Identity = ({member, size}) => {
const width = size || '50px';
return (
<React.Fragment>
{
member.logo_url ?
<Link to={member.url}>
<Avatar alt={member.name} src={member.logo_url} style={{width: width, height: width}} />
</Link> :
<IconButton touch='true' href={`/#${member.url}`} className='no-anchor-styles' style={{border: `1px solid gray`, width: width, height: width}}>
{getUserInitials(member)}
</IconButton>
}
</React.Fragment>
)
}
const IdentityBadge = ({member, size}) => {
const isAdmin = member.is_superuser || member.is_staff;
let icon = null;
if(isAdmin)
icon = <AdminIcon color='success' />;
else if (member.status === 'deactivated')
icon = <UserDisabledIcon color='error' style={{width: '20px'}} />;
else if (member.status === 'unverified')
icon = <UnverifiedIcon color='warning' style={{width: '20px'}} />;
else if (member.status === 'verified')
icon = <VerifiedIcon color='success' style={{width: '20px'}} />;
else if (member.status === 'verification_pending')
icon = <VerificationPendingIcon color='warning' style={{width: '20px'}} />;
return (
<React.Fragment>
{
icon ?
<Badge
overlap="circular"
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
badgeContent={icon}
>
<Identity member={member} size={size} />
</Badge> :
<Identity member={member} size={size} />
}
</React.Fragment>
)
}
const Info = ({ member }) => {
return (
<div className='col-xs-12 no-side-padding' style={{fontSize: '14px'}}>
<div className='col-xs-12 flex-vertical-center' style={{padding: '8px 0'}}>
<span style={{marginRight: '10px', display: 'inline-block'}}>
<IdentityBadge member={member} />
</span>
<Link to={member.url} className='no-anchor-styles'>
<div style={{fontWeight: 'bold', fontSize: '16px'}}>
{member.name}
</div>
<div style={{color: 'rgba(0, 0, 0, 0.7)', fontSize: '16px'}}>
{member.username}
</div>
</Link>
</div>
<Divider style={{width: '100%'}} />
<div className='col-xs-12' style={{padding: '8px 0'}}>
{
member.sources > 0 &&
<div className='col-xs-12 no-side-padding flex-vertical-center' style={{fontSize: '14px'}}>
<Link to={`${member.url}sources`} className='no-anchor-styles flex-vertical-center'>
<React.Fragment>
<SourceIcon style={{marginRight: '5px', width: '18px', color: GREEN}} />
<span>{`Owner of ${member.sources} public sources`}</span>
</React.Fragment>
</Link>
</div>
}
{
member.collections > 0 &&
<div className='col-xs-12 no-side-padding flex-vertical-center' style={{fontSize: '14px'}}>
<Link to={`${member.url}collections`} className='no-anchor-styles flex-vertical-center'>
<React.Fragment>
<CollectionIcon style={{marginRight: '5px', width: '18px', color: GREEN}} />
<span>{`Owner of ${member.collections} public collections`}</span>
</React.Fragment>
</Link>
</div>
}
{
member.organizations > 0 &&
<div className='col-xs-12 no-side-padding flex-vertical-center' style={{fontSize: '14px'}}>
<Link to={`${member.url}organizations`} className='no-anchor-styles flex-vertical-center'>
<React.Fragment>
<OrgIcon style={{marginRight: '5px', width: '18px', color: ORANGE}} />
<span>{`Member of ${member.organizations} organizations`}</span>
</React.Fragment>
</Link>
</div>
}
</div>
</div>
)
}
const Members = ({ members, org }) => {
const hasMore = members.length > 15
const chunks = chunk(members.slice(0, 15), 5)
return (
<div className='col-xs-12' style={{padding: 0, paddingLeft: '20px'}}>
<h3 style={{margin: '10px 0px', display: 'flex', alignItems: 'center'}}>
<Link style={{color: 'inherit'}} to={`/orgs/${org.id}/members`}>Members</Link>
</h3>
{
isEmpty(members) ?
<div className='col-xs-12'>
No members
</div> :
<React.Fragment>
{
map(chunks, (group, index) => (
<Stack direction="row" spacing={1} key={index} style={{padding: '5px 0'}}>
{
map(group, member => (
<HtmlToolTipRaw placement='top' title={<Info member={member} />} key={member.username} arrow>
<span>
<IdentityBadge member={member} />
</span>
</HtmlToolTipRaw>
))
}
</Stack>
))
}
{
hasMore &&
<Link style={{marginLeft: '5px', fontSize: '16px'}} to={`${org.url}members`}>View All</Link>
}
</React.Fragment>
}
</div>
)
}
export default Members;