Add create ticket option for staff members
This commit is contained in:
parent
0a5d444186
commit
cd2e1cd3df
|
@ -17,6 +17,7 @@ class TicketList extends React.Component {
|
|||
ticketPath: React.PropTypes.string,
|
||||
showDepartmentDropdown: React.PropTypes.bool,
|
||||
tickets: React.PropTypes.arrayOf(React.PropTypes.object),
|
||||
userId: React.PropTypes.number,
|
||||
type: React.PropTypes.oneOf([
|
||||
'primary',
|
||||
'secondary'
|
||||
|
@ -233,7 +234,15 @@ class TicketList extends React.Component {
|
|||
}
|
||||
|
||||
isTicketUnread(ticket) {
|
||||
return (this.props.type === 'primary' && ticket.unread) || (this.props.type === 'secondary' && ticket.unreadStaff);
|
||||
if(this.props.type === 'primary') {
|
||||
return ticket.unread;
|
||||
} else if(this.props.type === 'secondary') {
|
||||
if(ticket.author.id == this.props.userId && ticket.author.staff) {
|
||||
return ticket.unread;
|
||||
} else {
|
||||
return ticket.unreadStaff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ class TicketViewer extends React.Component {
|
|||
</div>
|
||||
<div className="ticket-viewer__info-row-header row">
|
||||
<div className="col-md-4">{i18n('PRIORITY')}</div>
|
||||
<div className="col-md-4">{i18n('OWNED')}</div>
|
||||
<div className="col-md-4">{i18n('OWNER')}</div>
|
||||
<div className="col-md-4">{i18n('STATUS')}</div>
|
||||
</div>
|
||||
<div className="ticket-viewer__info-row-values row">
|
||||
|
@ -107,9 +107,7 @@ class TicketViewer extends React.Component {
|
|||
<DropDown className="ticket-viewer__editable-dropdown" items={priorityList} selectedIndex={priorities[ticket.priority]} onChange={this.onPriorityDropdownChanged.bind(this)} />
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<Button type={(ticket.owner) ? 'primary' : 'secondary'} size="extra-small" onClick={this.onAssignClick.bind(this)}>
|
||||
{i18n(ticket.owner ? 'UN_ASSIGN' : 'ASSIGN_TO_ME')}
|
||||
</Button>
|
||||
{this.renderEditableOwnerNode()}
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<Button type={(ticket.closed) ? 'secondary' : 'primary'} size="extra-small" onClick={this.onCloseClick.bind(this)}>
|
||||
|
@ -161,6 +159,23 @@ class TicketViewer extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
renderEditableOwnerNode() {
|
||||
let ownerNode = null;
|
||||
let {ticket, userId} = this.props;
|
||||
|
||||
if (_.isEmpty(ticket.owner) || ticket.owner.id == userId) {
|
||||
ownerNode = (
|
||||
<Button type={(ticket.owner) ? 'primary' : 'secondary'} size="extra-small" onClick={this.onAssignClick.bind(this)}>
|
||||
{i18n(ticket.owner ? 'UN_ASSIGN' : 'ASSIGN_TO_ME')}
|
||||
</Button>
|
||||
);
|
||||
} else {
|
||||
ownerNode = (this.props.ticket.owner) ? this.props.ticket.owner.name : i18n('NONE')
|
||||
}
|
||||
|
||||
return ownerNode;
|
||||
}
|
||||
|
||||
renderOwnerNode() {
|
||||
let ownerNode = null;
|
||||
|
||||
|
@ -358,6 +373,7 @@ class TicketViewer extends React.Component {
|
|||
|
||||
export default connect((store) => {
|
||||
return {
|
||||
userId: store.session.userId,
|
||||
allowAttachments: store.config['allow-attachments'],
|
||||
userSystemEnabled: store.config['user-system-enabled']
|
||||
};
|
||||
|
|
|
@ -235,6 +235,7 @@ class StaffEditor extends React.Component {
|
|||
getTicketListProps() {
|
||||
return {
|
||||
type: 'secondary',
|
||||
userId: this.props.staffId,
|
||||
tickets: this.props.tickets,
|
||||
departments: this.props.departments,
|
||||
ticketPath: '/admin/panel/tickets/view-ticket/'
|
||||
|
|
|
@ -13,6 +13,7 @@ import Message from 'core-components/message';
|
|||
class AdminPanelAllTickets extends React.Component {
|
||||
|
||||
static defaultProps = {
|
||||
userId: 0,
|
||||
departments: [],
|
||||
tickets: []
|
||||
};
|
||||
|
@ -40,6 +41,7 @@ class AdminPanelAllTickets extends React.Component {
|
|||
|
||||
getTicketListProps() {
|
||||
return {
|
||||
userId: this.props.userId,
|
||||
showDepartmentDropdown: false,
|
||||
departments: this.props.departments,
|
||||
tickets: this.props.tickets,
|
||||
|
@ -75,6 +77,7 @@ class AdminPanelAllTickets extends React.Component {
|
|||
|
||||
export default connect((store) => {
|
||||
return {
|
||||
userId: store.session.userId,
|
||||
departments: store.session.userDepartments,
|
||||
tickets: store.adminData.allTickets,
|
||||
pages: store.adminData.allTicketsPages,
|
||||
|
|
|
@ -5,13 +5,18 @@ import i18n from 'lib-app/i18n';
|
|||
|
||||
import AdminDataAction from 'actions/admin-data-actions';
|
||||
import TicketList from 'app-components/ticket-list';
|
||||
import ModalContainer from 'app-components/modal-container';
|
||||
import CreateTicketForm from 'app/main/dashboard/dashboard-create-ticket/create-ticket-form';
|
||||
|
||||
import Button from 'core-components/button';
|
||||
import Icon from 'core-components/icon';
|
||||
import Header from 'core-components/header';
|
||||
import Message from 'core-components/message';
|
||||
|
||||
class AdminPanelMyTickets extends React.Component {
|
||||
|
||||
static defaultProps = {
|
||||
userId: 0,
|
||||
departments: [],
|
||||
tickets: []
|
||||
};
|
||||
|
@ -19,18 +24,24 @@ class AdminPanelMyTickets extends React.Component {
|
|||
componentDidMount() {
|
||||
this.props.dispatch(AdminDataAction.retrieveMyTickets());
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="admin-panel-my-tickets">
|
||||
<Header title={i18n('MY_TICKETS')} description={i18n('MY_TICKETS_DESCRIPTION')} />
|
||||
{(this.props.error) ? <Message type="error">{i18n('ERROR_RETRIEVING_TICKETS')}</Message> : <TicketList {...this.getProps()}/>}
|
||||
<div style={{textAlign: 'right', marginTop: 10}}>
|
||||
<Button onClick={this.onCreateTicket.bind(this)} type="secondary" size="medium">
|
||||
<Icon size="sm" name="plus"/> Create ticket
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
getProps() {
|
||||
return {
|
||||
userId: this.props.userId,
|
||||
departments: this.props.departments,
|
||||
tickets: this.props.tickets,
|
||||
type: 'secondary',
|
||||
|
@ -38,10 +49,27 @@ class AdminPanelMyTickets extends React.Component {
|
|||
ticketPath: '/admin/panel/tickets/view-ticket/'
|
||||
};
|
||||
}
|
||||
|
||||
onCreateTicket() {
|
||||
ModalContainer.openModal(
|
||||
<div>
|
||||
<CreateTicketForm onSuccess={this.onCreateTicketSuccess.bind(this)} />
|
||||
<div style={{textAlign: 'center'}}>
|
||||
<Button onClick={ModalContainer.closeModal} type="link">Close</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
onCreateTicketSuccess() {
|
||||
ModalContainer.closeModal();
|
||||
this.props.dispatch(AdminDataAction.retrieveMyTickets());
|
||||
}
|
||||
}
|
||||
|
||||
export default connect((store) => {
|
||||
return {
|
||||
userId: store.session.userId,
|
||||
departments: store.session.userDepartments,
|
||||
tickets: store.adminData.myTickets,
|
||||
loading: !store.adminData.myTicketsLoaded,
|
||||
|
|
|
@ -12,6 +12,7 @@ import Message from 'core-components/message';
|
|||
class AdminPanelNewTickets extends React.Component {
|
||||
|
||||
static defaultProps = {
|
||||
userId: 0,
|
||||
departments: [],
|
||||
tickets: []
|
||||
};
|
||||
|
@ -31,6 +32,7 @@ class AdminPanelNewTickets extends React.Component {
|
|||
|
||||
getProps() {
|
||||
return {
|
||||
userId: this.props.userId,
|
||||
departments: this.props.departments,
|
||||
tickets: this.props.tickets,
|
||||
type: 'secondary',
|
||||
|
@ -42,6 +44,7 @@ class AdminPanelNewTickets extends React.Component {
|
|||
|
||||
export default connect((store) => {
|
||||
return {
|
||||
userId: store.session.userId,
|
||||
departments: store.session.userDepartments,
|
||||
tickets: store.adminData.newTickets,
|
||||
loading: !store.adminData.newTicketsLoaded,
|
||||
|
|
|
@ -75,7 +75,10 @@ class AdminPanelViewTicket extends React.Component {
|
|||
onChange: this.retrieveTicket.bind(this),
|
||||
assignmentAllowed: this.props.assignmentAllowed,
|
||||
customResponses: this.props.customResponses,
|
||||
editable: this.state.ticket.owner && this.state.ticket.owner.id == SessionStore.getSessionData().userId
|
||||
editable: (
|
||||
(this.state.ticket.owner && this.state.ticket.owner.id == SessionStore.getSessionData().userId) ||
|
||||
(this.state.ticket.author && this.state.ticket.author.staff && this.state.ticket.author.id == SessionStore.getSessionData().userId)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -94,7 +97,7 @@ class AdminPanelViewTicket extends React.Component {
|
|||
ticket: result.data
|
||||
});
|
||||
|
||||
if(!this.props.avoidSeen && result.data.unreadStaff) {
|
||||
if(!this.props.avoidSeen) {
|
||||
API.call({
|
||||
path: '/ticket/seen',
|
||||
data: {
|
||||
|
@ -109,7 +112,7 @@ class AdminPanelViewTicket extends React.Component {
|
|||
loading: false,
|
||||
ticket: {}
|
||||
});
|
||||
|
||||
|
||||
if(this.props.onRetrieveFail) {
|
||||
this.props.onRetrieveFail();
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ import history from 'lib-app/history';
|
|||
import i18n from 'lib-app/i18n';
|
||||
import API from 'lib-app/api-call';
|
||||
import SessionStore from 'lib-app/session-store';
|
||||
import store from 'app/store';
|
||||
import SessionActions from 'actions/session-actions';
|
||||
import LanguageSelector from 'app-components/language-selector';
|
||||
import Captcha from 'app/main/captcha';
|
||||
|
||||
|
@ -21,7 +19,8 @@ import Message from 'core-components/message';
|
|||
class CreateTicketForm extends React.Component {
|
||||
|
||||
static propTypes = {
|
||||
userLogged: React.PropTypes.bool
|
||||
userLogged: React.PropTypes.bool,
|
||||
onSuccess: React.PropTypes.func,
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
|
@ -138,14 +137,11 @@ class CreateTicketForm extends React.Component {
|
|||
this.setState({
|
||||
loading: false,
|
||||
message: 'success'
|
||||
}, () => {
|
||||
if(this.props.onSuccess) {
|
||||
this.props.onSuccess();
|
||||
}
|
||||
});
|
||||
|
||||
if(this.props.userLogged) {
|
||||
store.dispatch(SessionActions.getUserData());
|
||||
setTimeout(() => {history.push('/dashboard')}, 2000);
|
||||
} else {
|
||||
setTimeout(() => {history.push('/check-ticket/' + result.data.ticketNumber + '/' + email)}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
onTicketFail() {
|
||||
|
|
|
@ -2,7 +2,9 @@ import React from 'react';
|
|||
import classNames from 'classnames';
|
||||
import {connect} from 'react-redux';
|
||||
|
||||
import SessionActions from 'actions/session-actions';
|
||||
import CreateTicketForm from 'app/main/dashboard/dashboard-create-ticket/create-ticket-form';
|
||||
|
||||
import Widget from 'core-components/widget';
|
||||
|
||||
class DashboardCreateTicketPage extends React.Component {
|
||||
|
@ -21,12 +23,23 @@ class DashboardCreateTicketPage extends React.Component {
|
|||
return (
|
||||
<div className={this.getClass()}>
|
||||
<Wrapper>
|
||||
<CreateTicketForm userLogged={(this.props.location.pathname !== '/create-ticket')} />
|
||||
<CreateTicketForm
|
||||
userLogged={(this.props.location.pathname !== '/create-ticket')}
|
||||
onSuccess={this.onCreateTicketSuccess.bind(this)}/>
|
||||
</Wrapper>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
getClass() {
|
||||
let classes = {
|
||||
'dashboard-create-ticket-page': true,
|
||||
|
|
|
@ -15,7 +15,7 @@ use Respect\Validation\Validator as DataValidator;
|
|||
* @apiPermission staff1
|
||||
*
|
||||
* @apiUse NO_PERMISSION
|
||||
*
|
||||
*
|
||||
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data Array of new tickets.
|
||||
*
|
||||
*/
|
||||
|
@ -41,13 +41,13 @@ class GetNewTicketsStaffController extends Controller {
|
|||
foreach ($user->sharedDepartmentList as $department) {
|
||||
$query .= 'department_id=' . $department->id . ' OR ';
|
||||
}
|
||||
$query = substr($query,0,-3);
|
||||
|
||||
$ownerExists = RedBean::exec('SHOW COLUMNS FROM ticket LIKE \'owner_id\'');
|
||||
|
||||
if($ownerExists != 0) {
|
||||
$query .= ') AND owner_id IS NULL';
|
||||
$query .= 'FALSE) AND owner_id IS NULL';
|
||||
} else {
|
||||
$query .= ')';
|
||||
$query .= 'FALSE)';
|
||||
}
|
||||
|
||||
$ticketList = Ticket::find($query);
|
||||
|
|
|
@ -45,9 +45,11 @@ class UnAssignStaffController extends Controller {
|
|||
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
||||
$owner = $ticket->owner;
|
||||
|
||||
if(($owner && $owner->id === $user->id) || $user->level > 1) {
|
||||
$owner->sharedTicketList->remove($ticket);
|
||||
$owner->store();
|
||||
if($ticket->isOwner($user) || $user->level > 1) {
|
||||
if(!$ticket->isAuthor($user)) {
|
||||
$owner->sharedTicketList->remove($ticket);
|
||||
$owner->store();
|
||||
}
|
||||
|
||||
$ticket->owner = null;
|
||||
$ticket->unread = !$ticket->isAuthor($user);
|
||||
|
|
|
@ -134,16 +134,18 @@ class CreateController extends Controller {
|
|||
|
||||
$ticket->setAuthor($author);
|
||||
|
||||
if(Controller::isUserSystemEnabled() && !Controller::isStaffLogged()) {
|
||||
if(Controller::isUserSystemEnabled() || Controller::isStaffLogged()) {
|
||||
$author->sharedTicketList->add($ticket);
|
||||
}
|
||||
|
||||
if(Controller::isUserSystemEnabled() && !Controller::isStaffLogged()) {
|
||||
$author->tickets++;
|
||||
|
||||
$this->email = $author->email;
|
||||
$this->name = $author->name;
|
||||
|
||||
$author->store();
|
||||
}
|
||||
|
||||
$author->store();
|
||||
$ticket->store();
|
||||
|
||||
$this->ticketNumber = $ticket->ticketNumber;
|
||||
|
|
|
@ -43,20 +43,20 @@ class SeenController extends Controller {
|
|||
$ticketnumber = Controller::request('ticketNumber');
|
||||
$user = Controller::getLoggedUser();
|
||||
$ticket = Ticket::getByTicketNumber($ticketnumber);
|
||||
|
||||
if (Controller::isStaffLogged() && $ticket->owner && $ticket->owner->id === $user->id) {
|
||||
|
||||
if(!$ticket->isOwner($user) && !$ticket->isAuthor($user)) {
|
||||
throw new Exception(ERRORS::NO_PERMISSION);
|
||||
}
|
||||
|
||||
if ($ticket->isOwner($user)) {
|
||||
$ticket->unreadStaff = false;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
return;
|
||||
}
|
||||
if (!Controller::isStaffLogged() && $ticket->author && $user->id === $ticket->author->id) {
|
||||
$ticket->unread = false;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
return;
|
||||
if ($ticket->isAuthor($user)) {
|
||||
$ticket->unread = false;
|
||||
}
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
|
||||
|
||||
$ticket->store();
|
||||
|
||||
Response::respondSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue