Skip to content

Commit

Permalink
fix(accounts): account list returning null after updating admin
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Jun 23, 2019
1 parent 6cc9c60 commit da79f1d
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 92 deletions.
184 changes: 93 additions & 91 deletions src/client/containers/Accounts/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,105 +110,107 @@ class AccountsContainer extends React.Component {
}

render () {
const items = this.props.accountsState.accounts.map(user => {
const userImage = user.get('image') || 'defaultProfile.jpg'
let actionMenu = [<DropdownItem key={0} text={'Edit'} onClick={e => this.onEditAccountClicked(e, user)} />]
if (user.get('deleted'))
actionMenu.push(<DropdownItem key={2} text={'Enable'} onClick={e => this.onEnableAccountClicked(e, user)} />)
else
actionMenu.push(
<DropdownItem
key={1}
text={'Delete'}
extraClass={'uk-text-danger'}
onClick={e => this.onDeleteAccountClicked(e, user)}
/>
)
const isAdmin = user.getIn(['role', 'isAdmin']) || false
const isAgent = user.getIn(['role', 'isAgent']) || false
const customer = !isAdmin && !isAgent
const isDeleted = user.get('deleted') || false
return (
<GridItem key={user.get('_id')} width={'1-5'} xLargeWidth={'1-6'} extraClass={'mb-25'}>
<TruCard
loaderActive={user.get('loading')}
menu={actionMenu}
extraHeadClass={
(isAdmin ? 'tru-card-head-admin' : '') +
(!isAdmin && isAgent ? 'tru-card-head-agent' : '') +
(isDeleted ? ' tru-card-head-deleted' : '')
}
header={
<div>
<div className='account-image relative uk-display-inline-block'>
<img src={`/uploads/users/${userImage}`} alt='ProfilePic' className={'tru-card-head-avatar'} />
<span
data-user-status-id={user.get('_id')}
className='user-status-large user-offline uk-border-circle'
/>
</div>
<h3 className='tru-card-head-text uk-text-center'>
{user.get('fullname')}
<span className='uk-text-truncate'>{user.get('title')}</span>
</h3>
</div>
}
content={
<ul className='tru-list'>
<li>
<div className='tru-list-content'>
<span className='tru-list-heading'>Role</span>
<span className='uk-text-small uk-text-muted'>{user.getIn(['role', 'name'])}</span>
const items =
this.props.accountsState.accounts &&
this.props.accountsState.accounts.map(user => {
const userImage = user.get('image') || 'defaultProfile.jpg'
let actionMenu = [<DropdownItem key={0} text={'Edit'} onClick={e => this.onEditAccountClicked(e, user)} />]
if (user.get('deleted'))
actionMenu.push(<DropdownItem key={2} text={'Enable'} onClick={e => this.onEnableAccountClicked(e, user)} />)
else
actionMenu.push(
<DropdownItem
key={1}
text={'Delete'}
extraClass={'uk-text-danger'}
onClick={e => this.onDeleteAccountClicked(e, user)}
/>
)
const isAdmin = user.getIn(['role', 'isAdmin']) || false
const isAgent = user.getIn(['role', 'isAgent']) || false
const customer = !isAdmin && !isAgent
const isDeleted = user.get('deleted') || false
return (
<GridItem key={user.get('_id')} width={'1-5'} xLargeWidth={'1-6'} extraClass={'mb-25'}>
<TruCard
loaderActive={user.get('loading')}
menu={actionMenu}
extraHeadClass={
(isAdmin ? 'tru-card-head-admin' : '') +
(!isAdmin && isAgent ? 'tru-card-head-agent' : '') +
(isDeleted ? ' tru-card-head-deleted' : '')
}
header={
<div>
<div className='account-image relative uk-display-inline-block'>
<img src={`/uploads/users/${userImage}`} alt='ProfilePic' className={'tru-card-head-avatar'} />
<span
data-user-status-id={user.get('_id')}
className='user-status-large user-offline uk-border-circle'
/>
</div>
</li>
<li>
<div className='tru-list-content'>
<span className='tru-list-heading'>Email</span>
<span className='uk-text-small uk-text-muted'>
<a href={`mailto:${user.get('email')}`}>{user.get('email')}</a>
</span>
</div>
</li>
<li>
{customer && user.get('groups') && (
<div className='tru-list-content'>
<span className='tru-list-heading'>Groups</span>
<span className='uk-text-small uk-text-muted uk-text-truncate'>
{user.get('groups').map(group => {
return group.get('name') + (user.get('groups').toArray().length > 1 ? ', ' : '')
})}
</span>
</div>
)}
{!customer && user.get('teams') && (
<h3 className='tru-card-head-text uk-text-center'>
{user.get('fullname')}
<span className='uk-text-truncate'>{user.get('title')}</span>
</h3>
</div>
}
content={
<ul className='tru-list'>
<li>
<div className='tru-list-content'>
<span className='tru-list-heading'>Teams</span>
<span className='uk-text-small uk-text-muted uk-text-truncate'>
{user.get('teams').map(team => {
return team.get('name') + (user.get('teams').toArray().length > 1 ? ', ' : '')
})}
</span>
<span className='tru-list-heading'>Role</span>
<span className='uk-text-small uk-text-muted'>{user.getIn(['role', 'name'])}</span>
</div>
)}
</li>
{!customer && user.get('departments') && (
</li>
<li>
<div className='tru-list-content'>
<span className='tru-list-heading'>Departments</span>
<span className='uk-text-small uk-text-muted uk-text-truncate'>
{user.get('departments').map(department => {
return department.get('name') + (user.get('departments').toArray().length > 1 ? ', ' : '')
})}
<span className='tru-list-heading'>Email</span>
<span className='uk-text-small uk-text-muted'>
<a href={`mailto:${user.get('email')}`}>{user.get('email')}</a>
</span>
</div>
</li>
)}
</ul>
}
/>
</GridItem>
)
})
<li>
{customer && user.get('groups') && (
<div className='tru-list-content'>
<span className='tru-list-heading'>Groups</span>
<span className='uk-text-small uk-text-muted uk-text-truncate'>
{user.get('groups').map(group => {
return group.get('name') + (user.get('groups').toArray().length > 1 ? ', ' : '')
})}
</span>
</div>
)}
{!customer && user.get('teams') && (
<div className='tru-list-content'>
<span className='tru-list-heading'>Teams</span>
<span className='uk-text-small uk-text-muted uk-text-truncate'>
{user.get('teams').map(team => {
return team.get('name') + (user.get('teams').toArray().length > 1 ? ', ' : '')
})}
</span>
</div>
)}
</li>
{!customer && user.get('departments') && (
<li>
<div className='tru-list-content'>
<span className='tru-list-heading'>Departments</span>
<span className='uk-text-small uk-text-muted uk-text-truncate'>
{user.get('departments').map(department => {
return department.get('name') + (user.get('departments').toArray().length > 1 ? ', ' : '')
})}
</span>
</div>
</li>
)}
</ul>
}
/>
</GridItem>
)
})

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/client/reducers/accountsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const reducer = handleActions(

let accounts = null
if ((state.type === 'agents' || state.type === 'admins') && !customer)
state.accounts.set(accountIndex, fromJS(resUser))
accounts = state.accounts.set(accountIndex, fromJS(resUser))
else if ((state.type === 'agents' || state.type === 'admins') && customer)
accounts = state.accounts.remove(accountIndex)
else if (state.type === 'customers' && !customer) accounts = state.accounts.remove(accountIndex)
Expand Down

0 comments on commit da79f1d

Please sign in to comment.