Skip to content

Commit

Permalink
fix(tickets): third party
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Apr 14, 2021
1 parent a861b09 commit c954ba0
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/client/actions/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
UNLOAD_TICKETS,
TICKET_UPDATED,
DELETE_TICKET,
TICKET_EVENT
TICKET_EVENT,
TRANSFER_TO_THIRDPARTY
} from 'actions/types'

export const fetchTickets = createAction(FETCH_TICKETS.ACTION)
Expand Down Expand Up @@ -56,3 +57,4 @@ export const deletePriority = createAction(DELETE_PRIORITY.ACTION, ({ id, newPri
export const getTagsWithPage = createAction(GET_TAGS_WITH_PAGE.ACTION, ({ limit, page }) => ({ limit, page }))
export const tagsUpdateCurrentPage = createAction(TAGS_UPDATE_CURRENT_PAGE.ACTION, currentPage => ({ currentPage }))
export const createTag = createAction(CREATE_TAG.ACTION, ({ name, currentPage }) => ({ name, currentPage }))
export const transferToThirdParty = createAction(TRANSFER_TO_THIRDPARTY.ACTION, ({ uid }) => ({ uid }))
1 change: 1 addition & 0 deletions src/client/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const DELETE_PRIORITY = defineAction('DELETE_PRIORITY', [SUCCESS, ERROR])
export const GET_TAGS_WITH_PAGE = defineAction('GET_TAGS_WITH_PAGE', [SUCCESS, ERROR])
export const TAGS_UPDATE_CURRENT_PAGE = defineAction('TAGS_UPDATE_CURRENT_PAGE', [SUCCESS, ERROR])
export const CREATE_TAG = defineAction('CREATE_TAG', [SUCCESS, ERROR])
export const TRANSFER_TO_THIRDPARTY = defineAction('TRANSFER_TO_THIRDPARTY', [SUCCESS, ERROR])

// Accounts
export const FETCH_ACCOUNTS = defineAction('FETCH_ACCOUNTS', [PENDING, SUCCESS, ERROR])
Expand Down
6 changes: 6 additions & 0 deletions src/client/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ api.tickets.createTag = ({ name }) => {
})
}

api.tickets.transferToThirdParty = ({ uid }) => {
return axios.post(`/api/v2/tickets/transfer/${uid}`).then(res => {
return res.data
})
}

api.accounts = {}
api.accounts.create = payload => {
return axios.post('/api/v2/accounts', payload).then(res => {
Expand Down
35 changes: 29 additions & 6 deletions src/client/containers/Tickets/SingleTicketContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { observer } from 'mobx-react'
import sortBy from 'lodash/sortBy'
import union from 'lodash/union'

import { transferToThirdParty } from 'actions/tickets'
import { fetchGroups, unloadGroups } from 'actions/groups'
import { showModal } from 'actions/common'

Expand Down Expand Up @@ -202,6 +203,11 @@ class SingleTicketContainer extends React.Component {
})
}

transferToThirdParty (e) {
socket.ui.sendUpdateTicketStatus(this.ticket._id, 3)
this.props.transferToThirdParty({ uid: this.ticket.uid })
}

@computed
get notesTagged () {
this.ticket.notes.forEach(i => (i.isNote = true))
Expand Down Expand Up @@ -336,7 +342,10 @@ class SingleTicketContainer extends React.Component {
type.priorities.findIndex(p => p._id === this.ticket.priority._id) !== -1

if (!hasPriority) {
socket.ui.setTicketPriority(this.ticket._id, type.priorities.find(() => true))
socket.ui.setTicketPriority(
this.ticket._id,
type.priorities.find(() => true)
)
showPriorityConfirm()
}

Expand Down Expand Up @@ -493,6 +502,20 @@ class SingleTicketContainer extends React.Component {
{/* Right Side */}
<div className='page-message nopadding' style={{ marginLeft: 360 }}>
<div className='page-title-right noshadow'>
{this.props.common.hasThirdParty && (
<div className='page-top-comments uk-float-right'>
<a
role='button'
className='btn md-btn-primary no-ajaxy'
onClick={e => {
e.preventDefault()
this.transferToThirdParty(e)
}}
>
Transfer to ThirdParty
</a>
</div>
)}
<div className='page-top-comments uk-float-right'>
<a
role='button'
Expand Down Expand Up @@ -755,7 +778,8 @@ SingleTicketContainer.propTypes = {
groupsState: PropTypes.object.isRequired,
fetchGroups: PropTypes.func.isRequired,
unloadGroups: PropTypes.func.isRequired,
showModal: PropTypes.func.isRequired
showModal: PropTypes.func.isRequired,
transferToThirdParty: PropTypes.func
}

const mapStateToProps = state => ({
Expand All @@ -764,7 +788,6 @@ const mapStateToProps = state => ({
groupsState: state.groupsState
})

export default connect(
mapStateToProps,
{ fetchGroups, unloadGroups, showModal }
)(SingleTicketContainer)
export default connect(mapStateToProps, { fetchGroups, unloadGroups, showModal, transferToThirdParty })(
SingleTicketContainer
)
20 changes: 19 additions & 1 deletion src/client/sagas/tickets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
UNLOAD_TICKETS,
TICKET_UPDATED,
DELETE_TICKET,
TICKET_EVENT
TICKET_EVENT,
TRANSFER_TO_THIRDPARTY
} from 'actions/types'

import helpers from 'lib/helpers'
Expand Down Expand Up @@ -204,6 +205,22 @@ function * createTag ({ payload }) {
}
}

function * transferToThirdParty ({ payload }) {
try {
const response = yield call(api.tickets.transferToThirdParty, payload)
yield put({ type: TRANSFER_TO_THIRDPARTY.SUCCESS, response })
helpers.UI.showSnackbar(`Ticket Transferred Successfully`, false)
} catch (error) {
const errorText = error.response ? error.response.data.error : error
if (error.response && error.response.status !== (401 || 403)) {
Log.error(errorText, error)
helpers.UI.showSnackbar(`Error: ${errorText}`, true)
}

yield put({ type: TRANSFER_TO_THIRDPARTY.ERROR, error })
}
}

export default function * watcher () {
yield takeLatest(FETCH_TICKETS.ACTION, fetchTickets)
yield takeLatest(CREATE_TICKET.ACTION, createTicket)
Expand All @@ -218,4 +235,5 @@ export default function * watcher () {
yield takeLatest(DELETE_PRIORITY.ACTION, deletePriority)
yield takeLatest(GET_TAGS_WITH_PAGE.ACTION, getTagsWithPage)
yield takeLatest(CREATE_TAG.ACTION, createTag)
yield takeLatest(TRANSFER_TO_THIRDPARTY.ACTION, transferToThirdParty)
}
1 change: 1 addition & 0 deletions src/controllers/api/v2/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function (middleware, router, controllers) {
// Tickets
router.get('/api/v2/tickets', apiv2Auth, apiv2.tickets.get)
router.post('/api/v2/tickets', apiv2Auth, apiv2.tickets.create)
router.post('/api/v2/tickets/transfer/:uid', apiv2Auth, isAdmin, apiv2.tickets.transferToThirdParty)
router.get('/api/v2/tickets/:uid', apiv2Auth, apiv2.tickets.single)
router.put('/api/v2/tickets/batch', apiv2Auth, apiv2.tickets.batchUpdate)
router.put('/api/v2/tickets/:uid', apiv2Auth, apiv2.tickets.update)
Expand Down
33 changes: 33 additions & 0 deletions src/controllers/api/v2/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,37 @@ ticketsV2.permDelete = function (req, res) {
})
}

ticketsV2.transferToThirdParty = function (req, res) {
var uid = req.params.uid
if (!uid) return apiUtils.sendApiError(res, 400, 'Invalid Parameters')

Ticket.getTicketByUid(uid, function (err, ticket) {
if (err) return apiUtils.sendApiError(res, 400, err.message)
if (!ticket) return apiUtils.sendApiError(res, 404, 'Ticket not found')

var request = require('axios')
var nconf = require('nconf')
var thirdParty = nconf.get('thirdParty')
var url = thirdParty.url + '/api/v2/tickets'

var ticketObj = {
subject: ticket.subject,
description: ticket.issue,
email: ticket.owner.email,
status: 2,
priority: 2
}

request
.post(url, ticketObj, { auth: { username: thirdParty.apikey, password: '1' } })
.then(function (response) {
return apiUtils.sendApiSuccess(res)
})
.catch(function (err) {
console.log(err)
return apiUtils.sendApiError(res, err.response.status, err.response.data.message)
})
})
}

module.exports = ticketsV2
10 changes: 10 additions & 0 deletions src/helpers/viewdata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ viewController.getData = function (request, cb) {
return callback()
})
},
function (callback) {
var settingsUtil = require('../../settings/settingsUtil')
settingsUtil.getSettings(function (err, res) {
if (err) return callback(err)

viewdata.hasThirdParty = res.data.settings.hasThirdParty

return callback()
})
},
function (callback) {
viewController.getPluginsInfo(request, function (err, data) {
if (err) return callback(err)
Expand Down
2 changes: 2 additions & 0 deletions src/settings/settingsUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

var _ = require('lodash')
var async = require('async')
var nconf = require('nconf')
var jsStringEscape = require('js-string-escape')
var settingSchema = require('../models/setting')
var ticketTypeSchema = require('../models/tickettype')
Expand Down Expand Up @@ -51,6 +52,7 @@ util.getSettings = function (callback) {
}

s.emailBeta = parseSetting(settings, 'beta:email', false)
s.hasThirdParty = !nconf.get('thirdParty') ? false : nconf.get('thirdParty').enable

s.siteTitle = parseSetting(settings, 'gen:sitetitle', 'Trudesk')
s.siteUrl = parseSetting(settings, 'gen:siteurl', '')
Expand Down

0 comments on commit c954ba0

Please sign in to comment.