Skip to content

Commit 001e7c6

Browse files
committed
refactor(components): avatar additional props
1 parent 66b737b commit 001e7c6

File tree

4 files changed

+56
-39
lines changed

4 files changed

+56
-39
lines changed

src/client/components/Avatar/Avatar.jsx

+41-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import React, { Fragment } from 'react'
1515
import PropTypes from 'prop-types'
1616
import { connect } from 'react-redux'
1717
import { some } from 'lodash'
18+
import clsx from 'clsx'
1819

1920
import axios from 'axios'
2021

@@ -119,13 +120,37 @@ class Avatar extends React.Component {
119120
}
120121

121122
render () {
122-
const { image, showOnlineBubble, userId, size, showBorder, enableImageUpload } = this.props
123+
const {
124+
style,
125+
image,
126+
showOnlineBubble,
127+
overrideBubbleSize,
128+
showLargerBubble,
129+
size,
130+
showBorder,
131+
borderColor,
132+
enableImageUpload
133+
} = this.props
134+
135+
let wrapperStyle = { borderRadius: '50%' }
136+
if (showBorder) {
137+
wrapperStyle.borderWidth = 4
138+
wrapperStyle.borderStyle = 'solid'
139+
wrapperStyle.borderColor = 'rgba(0,0,0,0.1)'
140+
}
141+
if (borderColor) wrapperStyle.borderColor = borderColor
142+
143+
if (style) wrapperStyle = { ...wrapperStyle, ...style }
144+
145+
let bubbleSize = size < 50 ? Math.round(size / 2) : 17
146+
if (overrideBubbleSize) bubbleSize = overrideBubbleSize
147+
if (showLargerBubble) bubbleSize = 25
123148

124149
return (
125150
<Fragment>
126151
<div
127152
className='relative uk-clearfix uk-float-left uk-display-inline-block'
128-
style={{ border: showBorder ? '4px solid rgba(0,0,0,0.1)' : '', borderRadius: '50%' }}
153+
style={wrapperStyle}
129154
onMouseOver={() => this.onMouseOver()}
130155
onMouseOut={() => this.onMouseOut()}
131156
>
@@ -175,7 +200,13 @@ class Avatar extends React.Component {
175200
src={`/uploads/users/${image || 'defaultProfile.jpg'}`}
176201
alt=''
177202
/>
178-
{showOnlineBubble && <span ref={this.onlineBubbleRef} className='user-offline uk-border-circle' />}
203+
{showOnlineBubble && (
204+
<span
205+
ref={this.onlineBubbleRef}
206+
className={clsx(showLargerBubble && 'user-status-large', 'user-offline', 'uk-border-circle')}
207+
style={{ height: bubbleSize, width: bubbleSize }}
208+
/>
209+
)}
179210
</div>
180211
</Fragment>
181212
)
@@ -190,14 +221,19 @@ Avatar.propTypes = {
190221
size: PropTypes.number.isRequired,
191222
showOnlineBubble: PropTypes.bool,
192223
showBorder: PropTypes.bool,
193-
enableImageUpload: PropTypes.bool
224+
borderColor: PropTypes.string,
225+
enableImageUpload: PropTypes.bool,
226+
style: PropTypes.object,
227+
overrideBubbleSize: PropTypes.number,
228+
showLargerBubble: PropTypes.bool
194229
}
195230

196231
Avatar.defaultProps = {
197232
size: 50,
198233
showOnlineBubble: true,
199234
showBorder: false,
200-
enableImageUpload: false
235+
enableImageUpload: false,
236+
showLargerBubble: false
201237
}
202238

203239
const mapStateToProps = state => ({

src/client/containers/Accounts/index.jsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { makeObservable, observable } from 'mobx'
2121
import { showModal } from 'actions/common'
2222
import { fetchAccounts, deleteAccount, enableAccount, unloadAccounts } from 'actions/accounts'
2323

24+
import Avatar from 'components/Avatar/Avatar'
2425
import TruCard from 'components/TruCard'
2526
import PageTitle from 'components/PageTitle'
2627
import Grid from 'components/Grid'
@@ -144,10 +145,14 @@ class AccountsContainer extends React.Component {
144145
header={
145146
<div>
146147
<div className='account-image relative uk-display-inline-block'>
147-
<img src={`/uploads/users/${userImage}`} alt='ProfilePic' className={'tru-card-head-avatar'} />
148-
<span
149-
data-user-status-id={user.get('_id')}
150-
className='user-status-large user-offline uk-border-circle'
148+
<Avatar
149+
size={82}
150+
userId={user.get('_id')}
151+
image={userImage}
152+
style={{ marginTop: 10 }}
153+
showBorder={true}
154+
borderColor={'#ffffff'}
155+
showLargerBubble={true}
151156
/>
152157
</div>
153158
<h3 className='tru-card-head-text uk-text-center'>

src/client/containers/Groups/index.jsx

+3-15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { connect } from 'react-redux'
1919
import { fetchGroups, deleteGroup } from 'actions/groups'
2020
import { showModal } from 'actions/common'
2121

22+
import Avatar from 'components/Avatar/Avatar'
2223
import PageTitle from 'components/PageTitle'
2324
import PageContent from 'components/PageContent'
2425
import Button from 'components/Button'
@@ -89,17 +90,7 @@ class GroupsContainer extends React.Component {
8990
data-uk-tooltip={'{pos: "bottom"}'}
9091
title={user.get('fullname')}
9192
>
92-
<img
93-
style={{ width: 25, height: 25, marginRight: 5 }}
94-
className={'round'}
95-
src={`/uploads/users/${profilePic}`}
96-
alt={user.get('fullname')}
97-
/>
98-
<span
99-
data-user-status-id={user.get('_id')}
100-
className='user-offline uk-border-circle'
101-
style={{ width: 13, height: 13 }}
102-
/>
93+
<Avatar size={25} style={{ marginRight: 5 }} image={profilePic} userId={user.get('_id')} />
10394
</div>
10495
)
10596
})}
@@ -171,7 +162,4 @@ const mapStateToProps = state => ({
171162
groups: state.groupsState.groups
172163
})
173164

174-
export default connect(
175-
mapStateToProps,
176-
{ fetchGroups, deleteGroup, showModal }
177-
)(GroupsContainer)
165+
export default connect(mapStateToProps, { fetchGroups, deleteGroup, showModal })(GroupsContainer)

src/client/containers/Teams/index.jsx

+3-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import PageTitle from 'components/PageTitle'
2323
import PageContent from 'components/PageContent'
2424

2525
import helpers from 'lib/helpers'
26+
import Avatar from 'components/Avatar/Avatar'
2627
import Button from 'components/Button'
2728
import UIKit from 'uikit'
2829
import Table from 'components/Table'
@@ -107,17 +108,7 @@ class TeamsContainer extends React.Component {
107108
data-uk-tooltip={'{pos: "bottom"}'}
108109
title={user.get('fullname')}
109110
>
110-
<img
111-
style={{ width: 25, height: 25, marginRight: 5 }}
112-
className={'round'}
113-
src={`/uploads/users/${profilePic}`}
114-
alt={user.get('fullname')}
115-
/>
116-
<span
117-
data-user-status-id={user.get('_id')}
118-
className='user-offline uk-border-circle'
119-
style={{ width: 13, height: 13 }}
120-
/>
111+
<Avatar image={profilePic} userId={user.get('_id')} size={25} style={{ marginRight: 5 }} />
121112
</div>
122113
)
123114
})}
@@ -197,7 +188,4 @@ const mapStateToProps = state => ({
197188
teamsState: state.teamsState
198189
})
199190

200-
export default connect(
201-
mapStateToProps,
202-
{ fetchTeams, unloadTeams, deleteTeam, showModal }
203-
)(TeamsContainer)
191+
export default connect(mapStateToProps, { fetchTeams, unloadTeams, deleteTeam, showModal })(TeamsContainer)

0 commit comments

Comments
 (0)