From 4e0669c4ae0840248f7ce140dd146af8dd472018 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Fri, 20 Jan 2017 22:01:18 -0300 Subject: [PATCH] Ivan - WIP [skip ci] --- client/src/app/Routes.js | 2 +- client/src/app/main/main-view-ticket.js | 104 ++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 client/src/app/main/main-view-ticket.js diff --git a/client/src/app/Routes.js b/client/src/app/Routes.js index c6b0b52b..6349f569 100644 --- a/client/src/app/Routes.js +++ b/client/src/app/Routes.js @@ -67,7 +67,7 @@ export default ( - + diff --git a/client/src/app/main/main-view-ticket.js b/client/src/app/main/main-view-ticket.js new file mode 100644 index 00000000..3d093cc9 --- /dev/null +++ b/client/src/app/main/main-view-ticket.js @@ -0,0 +1,104 @@ +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'; +import SessionStore from 'lib-app/session-store'; + +import TicketViewer from 'app-components/ticket-viewer'; +import Loading from 'core-components/loading'; +import Header from 'core-components/header'; + +class MainViewTicket extends React.Component { + + state = { + loading: true, + ticket: {} + }; + + componentDidMount() { + this.retrieveTicket(); + } + + render() { + return ( +
+
+ {(this.state.loading) ? this.renderLoading() : this.renderView()} +
+ ); + } + + renderLoading() { + return ( +
+ +
+ ) + }; + + renderView() { + return (_.isEmpty(this.state.ticket)) ? this.renderNoPermissionError() : this.renderTicketView(); + } + + renderNoPermissionError() { + return ( +
+ {i18n('NO_PERMISSION')} +
+ ); + } + + renderTicketView() { + return ( +
+ +
+ ); + } + + getTicketViewProps() { + return { + ticket: this.state.ticket, + onChange: this.retrieveTicket.bind(this), + assignmentAllowed: true, + customResponses: this.props.customResponses, + editable: this.state.ticket.owner && this.state.ticket.owner.id == SessionStore.getSessionData().userId + }; + } + + retrieveTicket() { + API.call({ + path: '/ticket/get', + data: { + ticketNumber: this.props.params.ticketNumber + } + }).then(this.onRetrieveSuccess.bind(this)).catch(this.onRetrieveFail.bind(this)) + } + + onRetrieveSuccess(result) { + this.setState({ + loading: false, + ticket: result.data + }); + + if(result.data.unreadStaff) { + API.call({ + path: '/ticket/seen', + data: { + ticketNumber: this.props.params.ticketNumber + } + }); + } + } + + onRetrieveFail() { + this.setState({ + loading: false, + ticket: {} + }); + } +} + +export default MainViewTicket; \ No newline at end of file