From 037f004d0cbf50861de2a8afadef13a969704508 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 26 Oct 2016 12:46:17 -0300 Subject: [PATCH] Ivan - Add custom response field [skip ci] --- client/src/actions/session-actions.js | 7 +++-- client/src/app-components/ticket-viewer.js | 26 +++++++++++++++++++ client/src/app-components/ticket-viewer.scss | 6 +++++ .../panel/tickets/admin-panel-view-ticket.js | 13 +++++----- client/src/data/languages/en.js | 1 + client/src/reducers/admin-data-reducer.js | 15 ++++++++++- 6 files changed, 59 insertions(+), 9 deletions(-) diff --git a/client/src/actions/session-actions.js b/client/src/actions/session-actions.js index 08c95be8..2d1b7995 100644 --- a/client/src/actions/session-actions.js +++ b/client/src/actions/session-actions.js @@ -1,9 +1,8 @@ import API from 'lib-app/api-call'; +import AdminDataActions from 'actions/admin-data-actions'; import sessionStore from 'lib-app/session-store'; import store from 'app/store'; -import ConfigActions from 'actions/config-actions'; - export default { login(loginData) { return { @@ -13,6 +12,10 @@ export default { data: loginData }).then((result) => { store.dispatch(this.getUserData(result.data.userId, result.data.token, result.data.staff)); + + if(result.data.staff) { + store.dispatch(AdminDataActions.retrieveCustomResponses()); + } return result; }) diff --git a/client/src/app-components/ticket-viewer.js b/client/src/app-components/ticket-viewer.js index d45dd4b4..c324386a 100644 --- a/client/src/app-components/ticket-viewer.js +++ b/client/src/app-components/ticket-viewer.js @@ -20,6 +20,7 @@ class TicketViewer extends React.Component { ticket: React.PropTypes.object, onChange: React.PropTypes.func, editable: React.PropTypes.bool, + customResponses: React.PropTypes.array, assignmentAllowed: React.PropTypes.bool }; @@ -58,6 +59,7 @@ class TicketViewer extends React.Component {
{i18n('RESPOND')}
+ {this.renderCustomResponses()}
@@ -186,6 +188,30 @@ class TicketViewer extends React.Component { ); } + renderCustomResponses() { + let customResponsesNode = null; + + if (this.props.customResponses && this.props.editable) { + let customResponses = this.props.customResponses.map((customResponse) => { + return { + content: customResponse.name + }; + }); + + customResponses.unshift({ + content: i18n('SELECT_CUSTOM_RESPONSE') + }); + + customResponsesNode = ( +
+ +
+ ); + } + + return customResponsesNode; + } + onDepartmentDropdownChanged(event) { AreYouSure.openModal(null, this.changeDepartment.bind(this, event.index)); } diff --git a/client/src/app-components/ticket-viewer.scss b/client/src/app-components/ticket-viewer.scss index c4ec3865..0b885aa2 100644 --- a/client/src/app-components/ticket-viewer.scss +++ b/client/src/app-components/ticket-viewer.scss @@ -72,5 +72,11 @@ padding: 20px; text-align: left; } + + &-custom { + background-color: $very-light-grey; + padding: 20px 0 0 20px; + text-align: left; + } } } \ No newline at end of file diff --git a/client/src/app/admin/panel/tickets/admin-panel-view-ticket.js b/client/src/app/admin/panel/tickets/admin-panel-view-ticket.js index 141938f9..f9f34b20 100644 --- a/client/src/app/admin/panel/tickets/admin-panel-view-ticket.js +++ b/client/src/app/admin/panel/tickets/admin-panel-view-ticket.js @@ -1,5 +1,6 @@ import React from 'react'; import _ from 'lodash'; +import {connect} from 'react-redux'; import API from 'lib-app/api-call'; import i18n from 'lib-app/i18n'; @@ -62,16 +63,12 @@ class AdminPanelViewTicket extends React.Component { ticket: this.state.ticket, onChange: this.retrieveTicket.bind(this), assignmentAllowed: true, + customResponses: this.props.customResponses, editable: _.get(this.state.ticket, 'owner.id') === SessionStore.getUserData().id }; } retrieveTicket() { - this.setState({ - loading: true, - ticket: {} - }); - API.call({ path: '/ticket/get', date: { @@ -95,4 +92,8 @@ class AdminPanelViewTicket extends React.Component { } } -export default AdminPanelViewTicket; \ No newline at end of file +export default connect((store) => { + return { + customResponses: store.adminData.customResponses + }; +})(AdminPanelViewTicket); diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index aa7b778f..25e74b18 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -71,6 +71,7 @@ export default { 'ASSIGN_TO_ME': 'Assign to me', 'UN_ASSIGN': 'Unassign', 'VIEW_TICKET': 'View Ticket', + 'SELECT_CUSTOM_RESPONSE': 'Select a custom response...', //VIEW DESCRIPTIONS 'CREATE_TICKET_DESCRIPTION': 'This is a form for creating tickets. Fill the form and send us your issues/doubts/suggestions. Our support system will answer it as soon as possible.', diff --git a/client/src/reducers/admin-data-reducer.js b/client/src/reducers/admin-data-reducer.js index 60c59d20..2aeb295b 100644 --- a/client/src/reducers/admin-data-reducer.js +++ b/client/src/reducers/admin-data-reducer.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import Reducer from 'reducers/reducer'; +import sessionStore from 'lib-app/session-store'; class AdminDataReducer extends Reducer { @@ -13,16 +14,28 @@ class AdminDataReducer extends Reducer { getTypeHandlers() { return { - 'CUSTOM_RESPONSES_FULFILLED': this.onCustomResponses + 'CUSTOM_RESPONSES_FULFILLED': this.onCustomResponses, + 'SESSION_CHECKED': this.onSessionChecked }; } onCustomResponses(state, payload) { + sessionStore.setItem('customResponses', JSON.stringify(payload.data)); + return _.extend({}, state, { customResponses: payload.data, customResponsesLoaded: true }); } + + onSessionChecked(state) { + const customResponses = sessionStore.getItem('customResponses'); + + return _.extend({}, state, { + customResponses: JSON.parse(customResponses), + customResponsesLoaded: true + }); + } } export default AdminDataReducer.getInstance(); \ No newline at end of file