diff --git a/client/src/app-components/ticket-info.scss b/client/src/app-components/ticket-info.scss index 4ee52a3f..f719f36b 100644 --- a/client/src/app-components/ticket-info.scss +++ b/client/src/app-components/ticket-info.scss @@ -3,6 +3,7 @@ .ticket-info { width: 300px; font-weight: normal; + text-align: left; &__title { color: $primary-black; @@ -86,4 +87,4 @@ } } } -} \ No newline at end of file +} diff --git a/client/src/app/main/dashboard/dashboard-create-ticket/dashboard-create-ticket-page.js b/client/src/app/main/dashboard/dashboard-create-ticket/dashboard-create-ticket-page.js index 54378546..57e50d6c 100644 --- a/client/src/app/main/dashboard/dashboard-create-ticket/dashboard-create-ticket-page.js +++ b/client/src/app/main/dashboard/dashboard-create-ticket/dashboard-create-ticket-page.js @@ -34,7 +34,6 @@ class DashboardCreateTicketPage extends React.Component { onCreateTicketSuccess() { if((this.props.location.pathname !== '/create-ticket')) { - this.props.dispatch(SessionActions.getUserData()); setTimeout(() => {history.push('/dashboard')}, 2000); } else { setTimeout(() => {history.push('/check-ticket/' + result.data.ticketNumber + '/' + email)}, 1000); diff --git a/client/src/app/main/dashboard/dashboard-list-tickets/dashboard-list-tickets-page.js b/client/src/app/main/dashboard/dashboard-list-tickets/dashboard-list-tickets-page.js index 1623df49..352dbe40 100644 --- a/client/src/app/main/dashboard/dashboard-list-tickets/dashboard-list-tickets-page.js +++ b/client/src/app/main/dashboard/dashboard-list-tickets/dashboard-list-tickets-page.js @@ -1,6 +1,8 @@ import React from 'react'; import {connect} from 'react-redux'; +import SessionActions from 'actions/session-actions'; + import i18n from 'lib-app/i18n'; import Header from 'core-components/header'; @@ -15,6 +17,10 @@ class DashboardListTicketsPage extends React.Component { tickets: [] }; + componentDidMount() { + this.retrieveUserData(); + } + render() { return (
@@ -23,6 +29,10 @@ class DashboardListTicketsPage extends React.Component {
); } + + retrieveUserData() { + this.props.dispatch(SessionActions.getUserData()); + } } diff --git a/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.js b/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.js index 4f30814d..1af40be3 100644 --- a/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.js +++ b/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.js @@ -1,59 +1,82 @@ import React from 'react'; import _ from 'lodash'; -import {connect} from 'react-redux'; + +import store from 'app/store'; +import SessionActions from 'actions/session-actions'; import i18n from 'lib-app/i18n'; import API from 'lib-app/api-call'; -import SessionActions from 'actions/session-actions'; import TicketViewer from 'app-components/ticket-viewer'; +import Loading from 'core-components/loading'; +import Message from 'core-components/message'; class DashboardTicketPage extends React.Component { - static propTypes = { - tickets: React.PropTypes.array + state = { + error: null, + ticket: null, }; componentDidMount() { - let ticket = this.getTicketData(); - - if(ticket.unread) { - API.call({ - path: '/ticket/seen', - data: { - ticketNumber: ticket.ticketNumber - } - }).then(() => { - this.retrieveUserData(); - }); - } + this.retrieveTicketData(); } render() { - let ticketView = i18n('NO_PERMISSION'); - - if(!_.isEmpty(this.getTicketData())) { - ticketView = ; - } + const {ticket, error} = this.state; return (
- {ticketView} + {(ticket || error) ? this.renderContent() : }
); } - getTicketData() { - return _.find(this.props.tickets, {ticketNumber: this.props.params.ticketNumber}) || {}; + renderContent() { + const {ticket, error} = this.state; + + if(error) { + return ( + + {i18n(error)} + + ); + } else { + return ( + + ); + } + + } + + retrieveTicketData() { + API.call({ + path: '/ticket/get', + data: { + ticketNumber: this.props.params.ticketNumber, + } + }) + .then(result => { + const ticket = result.data + this.setState({ticket, error: null}) + + if(ticket.unread) { + API.call({ + path: '/ticket/seen', + data: { + ticketNumber: ticket.ticketNumber + } + }).then(() => { + this.retrieveUserData(); + }); + } + }) + .catch(result => this.setState({error: result.message})); } retrieveUserData() { - this.props.dispatch(SessionActions.getUserData()); + store.dispatch(SessionActions.getUserData()); } } -export default connect((store) => { - return { - tickets: store.session.userTickets - }; -})(DashboardTicketPage); +export default DashboardTicketPage; diff --git a/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.scss b/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.scss index 4caad9b2..3a16b2c2 100644 --- a/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.scss +++ b/client/src/app/main/dashboard/dashboard-ticket/dashboard-ticket-page.scss @@ -1,3 +1,7 @@ .dashboard-ticket-page { padding: 0 10px; -} \ No newline at end of file + + &__loading { + min-height: 300px; + } +} diff --git a/server/controllers/user/get.php b/server/controllers/user/get.php index f871a870..a7f8126f 100755 --- a/server/controllers/user/get.php +++ b/server/controllers/user/get.php @@ -18,7 +18,7 @@ DataValidator::with('CustomValidations', true); * @apiUse INVALID_CREDENTIALS * * @apiSuccess {Object} data Information about an user - * @apiSuccess {String} data.name Name of the user + * @apiSuccess {String} data.name Name of the user * @apiSuccess {String} data.email Email of the user * @apiSuccess {Boolean} data.verified Indicates if the user is verified * @apiSuccess {Object} data Information about an user @@ -48,7 +48,7 @@ class GetUserController extends Controller { $ticketList = $user->sharedTicketList; foreach($ticketList as $ticket) { - $parsedTicketList[] = $ticket->toArray(); + $parsedTicketList[] = $ticket->toArray(true); } Response::respondSuccess([ @@ -58,4 +58,4 @@ class GetUserController extends Controller { 'tickets' => $parsedTicketList ]); } -} \ No newline at end of file +} diff --git a/server/models/Ticket.php b/server/models/Ticket.php index 282bd54e..10f5c0d2 100755 --- a/server/models/Ticket.php +++ b/server/models/Ticket.php @@ -106,11 +106,11 @@ class Ticket extends DataStore { return $ticketNumber; } - public function toArray() { + public function toArray($minimized = false) { return [ 'ticketNumber' => $this->ticketNumber, 'title' => $this->title, - 'content' => $this->content, + 'content' => $minimized ? strip_tags($this->content) : $this->content, 'department' => [ 'id' => $this->department->id, 'name' => $this->department->name @@ -124,7 +124,7 @@ class Ticket extends DataStore { 'priority' => $this->priority, 'author' => $this->authorToArray(), 'owner' => $this->ownerToArray(), - 'events' => $this->eventsToArray() + 'events' => $minimized ? [] : $this->eventsToArray() ]; }