Skip to content

Commit

Permalink
chore(accounts): customers,agents,admins
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Apr 10, 2019
1 parent 98a43b6 commit 6e6647d
Show file tree
Hide file tree
Showing 34 changed files with 891 additions and 205 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"moment-duration-format": "2.2.2",
"moment-timezone": "0.5.23",
"mongoose": "5.4.5",
"mongoose-autopopulate": "0.9.1",
"nconf": "0.10.0",
"netmask": "1.0.6",
"node-cache": "4.2.0",
Expand Down
9 changes: 8 additions & 1 deletion src/client/actions/departments.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@
*/

import { createAction } from 'redux-actions'
import { CREATE_DEPARTMENT, DELETE_DEPARTMENT, FETCH_DEPARTMENTS, UPDATE_DEPARTMENT } from 'actions/types'
import {
CREATE_DEPARTMENT,
DELETE_DEPARTMENT,
FETCH_DEPARTMENTS,
UNLOAD_DEPARTMENTS,
UPDATE_DEPARTMENT
} from 'actions/types'

export const fetchDepartments = createAction(FETCH_DEPARTMENTS.ACTION, payload => payload, () => ({ thunk: true }))
export const createDepartment = createAction(CREATE_DEPARTMENT.ACTION)
export const updateDepartment = createAction(UPDATE_DEPARTMENT.ACTION)
export const deleteDepartment = createAction(DELETE_DEPARTMENT.ACTION)
export const unloadDepartments = createAction(UNLOAD_DEPARTMENTS.ACTION, payload => payload, () => ({ thunk: true }))
1 change: 1 addition & 0 deletions src/client/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const FETCH_DEPARTMENTS = defineAction('FETCH_DEPARTMENTS', [PENDING, SUC
export const CREATE_DEPARTMENT = defineAction('CREATE_DEPARTMENT', [PENDING, SUCCESS, ERROR])
export const UPDATE_DEPARTMENT = defineAction('UPDATE_DEPARTMENT', [SUCCESS, PENDING, ERROR])
export const DELETE_DEPARTMENT = defineAction('DELETE_DEPARTMENT', [SUCCESS, PENDING, ERROR])
export const UNLOAD_DEPARTMENTS = defineAction('UNLOAD_DEPARTMENTS', [SUCCESS])

// Settings
export const FETCH_SETTINGS = defineAction('FETCH_SETTINGS', [SUCCESS, ERROR])
Expand Down
8 changes: 5 additions & 3 deletions src/client/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ api.accounts.create = payload => {
api.accounts.getWithPage = payload => {
const limit = payload && payload.limit ? payload.limit : 25
const page = payload && payload.page ? payload.page : 0
const type = payload && payload.type ? payload.type : 'customers'
let search = payload && payload.search ? payload.search : ''
if (search) search = `&search=${search}`
return axios.get(`/api/v1/users?limit=${limit}&page=${page}${search}`).then(res => {

return axios.get(`/api/v2/accounts?type=${type}&limit=${limit}&page=${page}${search}`).then(res => {
return res.data
})
}
api.accounts.updateUser = payload => {
return axios.put(`/api/v1/users/${payload.aUsername}`, payload).then(res => {
return axios.put(`/api/v2/accounts/${payload.username}`, payload).then(res => {
return res.data
})
}
Expand All @@ -155,7 +157,7 @@ api.accounts.enableAccount = ({ username }) => {

api.groups = {}
api.groups.get = () => {
return axios.get('/api/v1/groups').then(res => {
return axios.get('/api/v2/groups').then(res => {
return res.data
})
}
Expand Down
7 changes: 3 additions & 4 deletions src/client/components/MultiSelect/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MultiSelect extends React.Component {
$select.append(`<option value='${i.value}'>${i.text}</option>`)
})

$select.attr('disabled', false)
$select.multiSelect('refresh')

if (this.props.initialSelected) {
Expand All @@ -59,10 +60,8 @@ class MultiSelect extends React.Component {
}
}

if (prevProps.disabled !== this.props.disabled) {
$select.attr('disabled', this.props.disabled)
$select.multiSelect('refresh')
}
$select.attr('disabled', this.props.disabled)
$select.multiSelect('refresh')
}

getSelected () {
Expand Down
39 changes: 31 additions & 8 deletions src/client/components/Nav/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@ import SubmenuItem from 'components/Nav/SubmenuItem'

import { updateNavChange } from '../../../actions/nav'

// import Permissions from '../../../../permissions/index.js'

import Helpers from 'lib/helpers'

class Sidebar extends React.Component {
constructor (props) {
super(props)

// window.react.updateSidebar = (data) => {
// this.props.updateNavChange(data);
// };
}

componentDidMount () {
Expand Down Expand Up @@ -155,7 +149,36 @@ class Sidebar extends React.Component {
href='/accounts'
class='navAccounts'
active={activeItem === 'accounts'}
/>
subMenuTarget='accounts'
hasSubmenu={sessionUser && Helpers.canUser('agent:*', true)}
>
{sessionUser && Helpers.canUser('agent:*', true) && (
<Submenu id='accounts'>
<SubmenuItem
href={'/accounts/customers'}
text={'Customers'}
icon={'account_box'}
active={activeSubItem === 'accounts-customers'}
/>
{sessionUser && Helpers.canUser('agent:*', true) && (
<SubmenuItem
href={'/accounts/agents'}
text={'Agents'}
icon={'account_circle'}
active={activeSubItem === 'accounts-agents'}
/>
)}
{sessionUser && Helpers.canUser('admin:*') && (
<SubmenuItem
href={'/accounts/admins'}
text={'Admins'}
icon={'how_to_reg'}
active={activeSubItem === 'accounts-admins'}
/>
)}
</Submenu>
)}
</SidebarItem>
)}
{sessionUser && Helpers.canUser('groups:view') && (
<SidebarItem
Expand Down Expand Up @@ -250,7 +273,7 @@ class Sidebar extends React.Component {
/>
<SubmenuItem
text='Permissions'
icon='lock'
icon='security'
href='/settings/permissions'
active={activeSubItem === 'settings-permissions'}
/>
Expand Down
52 changes: 42 additions & 10 deletions src/client/containers/Accounts/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AccountsContainer extends React.Component {
}

getUsersWithPage (page) {
this.props.fetchAccounts({ page, limit: 25 }).then(({ response }) => {
this.props.fetchAccounts({ page, limit: 25, type: this.props.view }).then(({ response }) => {
if (response.count < 25) this.hasMore = false
})
}
Expand Down Expand Up @@ -124,6 +124,7 @@ class AccountsContainer extends React.Component {
)
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'}>
Expand Down Expand Up @@ -167,15 +168,39 @@ class AccountsContainer extends React.Component {
</div>
</li>
<li>
<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('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>
}
/>
Expand All @@ -186,7 +211,7 @@ class AccountsContainer extends React.Component {
return (
<div>
<PageTitle
title={'Accounts'}
title={this.props.title}
rightComponent={
<div className={'uk-grid uk-grid-collapse'}>
<div className={'uk-width-3-4 pr-10'}>
Expand Down Expand Up @@ -252,6 +277,8 @@ class AccountsContainer extends React.Component {
}

AccountsContainer.propTypes = {
title: PropTypes.string.isRequired,
view: PropTypes.string.isRequired,
fetchAccounts: PropTypes.func.isRequired,
deleteAccount: PropTypes.func.isRequired,
enableAccount: PropTypes.func.isRequired,
Expand All @@ -262,6 +289,11 @@ AccountsContainer.propTypes = {
accountsState: PropTypes.object.isRequired
}

AccountsContainer.defaultProps = {
title: 'Accounts',
view: 'customers'
}

const mapStateToProps = state => ({
shared: state.shared,
accountsState: state.accountsState,
Expand Down
Loading

0 comments on commit 6e6647d

Please sign in to comment.