From 9ec82932fa511b633c11e9d5f8dacd2ab92270e9 Mon Sep 17 00:00:00 2001 From: Chris Brame Date: Sun, 22 Dec 2019 21:16:02 -0500 Subject: [PATCH] feat(tickets): allow agents to submit tickets on behalf of user #252 --- .../containers/Modals/CreateTicketModal.jsx | 79 ++++++++++++++++--- .../containers/Settings/Tickets/index.jsx | 24 ++++++ src/helpers/viewdata/index.js | 11 +++ src/settings/settingsUtil.js | 1 + 4 files changed, 103 insertions(+), 12 deletions(-) diff --git a/src/client/containers/Modals/CreateTicketModal.jsx b/src/client/containers/Modals/CreateTicketModal.jsx index 966b93ad0..178b0aa22 100644 --- a/src/client/containers/Modals/CreateTicketModal.jsx +++ b/src/client/containers/Modals/CreateTicketModal.jsx @@ -22,6 +22,7 @@ import axios from 'axios' import Log from '../../logger' import { createTicket } from 'actions/tickets' import { fetchGroups } from 'actions/groups' +import { fetchAccounts } from 'actions/accounts' import $ from 'jquery' import helpers from 'lib/helpers' @@ -38,6 +39,8 @@ import EasyMDE from 'components/EasyMDE' @observer class CreateTicketModal extends React.Component { @observable priorities = [] + @observable allAccounts = this.props.accounts || [] + @observable groupAccounts = [] @observable selectedPriority = '' issueText = '' @@ -47,6 +50,7 @@ class CreateTicketModal extends React.Component { componentDidMount () { this.props.fetchGroups() + this.props.fetchAccounts({ type: 'all' }) helpers.UI.inputs() helpers.formvalidator() this.defaultTicketTypeWatcher = when( @@ -100,6 +104,10 @@ class CreateTicketModal extends React.Component { let data = {} if (this.issueText.length < 1) return + const allowAgentUserTickets = + this.props.viewdata.ticketSettings.allowAgentUserTickets && + (this.props.shared.sessionUser.role.isAdmin || this.props.shared.sessionUser.role.isAgent) + const minIssueLength = this.props.viewdata.ticketSettings.minIssue let $mdeError const $issueTextbox = $(this.issueMde.element) @@ -121,6 +129,8 @@ class CreateTicketModal extends React.Component { if (!$form.isValid(null, null, false)) return true + if (allowAgentUserTickets) data.owner = this.ownerSelect.value + data.subject = e.target.subject.value data.group = this.groupSelect.value data.type = this.typeSelect.value @@ -132,8 +142,30 @@ class CreateTicketModal extends React.Component { this.props.createTicket(data) } + onGroupSelectChange (e) { + // this.groupAccounts = this.props.groups + // .filter(grp => grp.get('_id') === e.target.value) + // .first() + // .get('members') + // .map(a => { + // return { text: a.get('fullname'), value: a.get('_id') } + // }) + // .toArray() + } + render () { - const { viewdata } = this.props + const { shared, viewdata } = this.props + + const allowAgentUserTickets = + viewdata.ticketSettings.allowAgentUserTickets && + (shared.sessionUser.role.isAdmin || shared.sessionUser.role.isAgent) + + const mappedAccounts = this.props.accounts + .map(a => { + return { text: a.get('fullname'), value: a.get('_id') } + }) + .toArray() + const mappedGroups = this.props.groups .map(grp => { return { text: grp.get('name'), value: grp.get('_id') } @@ -163,14 +195,31 @@ class CreateTicketModal extends React.Component { />
- - (this.groupSelect = i)} - /> + + {allowAgentUserTickets && ( + + + (this.ownerSelect = i)} + /> + + )} + + + this.onGroupSelectChange(e)} + width={'100%'} + ref={i => (this.groupSelect = i)} + /> + +
@@ -253,6 +302,7 @@ class CreateTicketModal extends React.Component {
Please try to be as specific as possible. Please include any details you think may be relevant, such as + {/* eslint-disable-next-line react/no-unescaped-entities */} troubleshooting steps you've taken. @@ -267,18 +317,23 @@ class CreateTicketModal extends React.Component { } CreateTicketModal.propTypes = { + shared: PropTypes.object.isRequired, viewdata: PropTypes.object.isRequired, + accounts: PropTypes.object.isRequired, groups: PropTypes.object.isRequired, createTicket: PropTypes.func.isRequired, - fetchGroups: PropTypes.func.isRequired + fetchGroups: PropTypes.func.isRequired, + fetchAccounts: PropTypes.func.isRequired } const mapStateToProps = state => ({ + shared: state.shared, viewdata: state.common, - groups: state.groupsState.groups + groups: state.groupsState.groups, + accounts: state.accountsState.accounts }) export default connect( mapStateToProps, - { createTicket, fetchGroups } + { createTicket, fetchGroups, fetchAccounts } )(CreateTicketModal) diff --git a/src/client/containers/Settings/Tickets/index.jsx b/src/client/containers/Settings/Tickets/index.jsx index 873d4befc..89fbf4e72 100644 --- a/src/client/containers/Settings/Tickets/index.jsx +++ b/src/client/containers/Settings/Tickets/index.jsx @@ -107,6 +107,15 @@ class TicketsSettings extends React.Component { }) } + onAllowAgentUserTicketsChange (e) { + this.props.updateSetting({ + name: 'allowAgentUserTickets:enable', + value: e.target.checked, + stateName: 'allowAgentUserTickets', + noSnackbar: true + }) + } + onShowOverdueChange (e) { this.props.updateSetting({ name: 'showOverdueTickets:enable', @@ -238,6 +247,21 @@ class TicketsSettings extends React.Component { /> } /> + Allow the creation of tickets by agents on behalf of users.} + tooltip={'Setting takes affect after refresh.'} + component={ + { + this.onAllowAgentUserTicketsChange(e) + }} + /> + } + />