Fix error in edit button for ticket owner. (#872)

* Retrieve staff members after edit staffs.

* Delete retun after throw new RequestException in staff/edit.php

* Resolve github Ivan comments.

* wip
This commit is contained in:
LautaroCesso 2020-08-28 06:27:04 -03:00 committed by GitHub
parent 817240e0b4
commit 5184c31907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 12 deletions

View File

@ -814,23 +814,21 @@ class TicketViewer extends React.Component {
userId, userId,
ticket ticket
} = this.props; } = this.props;
const ticketDepartmentId = ticket.department.id;
const FIRST_ITEM = 0;
let staffAssignmentItems = [ let staffAssignmentItems = [
{content: i18n('NONE'), contentOnSelected: i18n('NONE'), id: 0} {content: i18n('NONE'), contentOnSelected: i18n('NONE'), id: 0}
]; ];
if(_.some(userDepartments, {id: ticketDepartmentId})) { if(_.some(userDepartments, {id: ticket.department.id})) {
staffAssignmentItems.push({ staffAssignmentItems.push({
content: i18n('ASSIGN_TO_ME'), content: i18n('ASSIGN_TO_ME'),
contentOnSelected: this.getStaffList({onlyMe: true})[FIRST_ITEM].name, contentOnSelected: this.getCurrentStaff().name,
id: userId id: userId
}); });
} }
staffAssignmentItems = staffAssignmentItems.concat( staffAssignmentItems = staffAssignmentItems.concat(
_.map( _.map(
this.getStaffList({onlyMe: false}), this.getStaffList(),
({id, name}) => ({content: name, contentOnSelected: name, id: id*1}) ({id, name}) => ({content: name, contentOnSelected: name, id: id*1})
) )
); );
@ -838,7 +836,7 @@ class TicketViewer extends React.Component {
return staffAssignmentItems; return staffAssignmentItems;
} }
getStaffList(onlyMeObject) { getStaffList() {
const { const {
userId, userId,
staffMembers, staffMembers,
@ -846,12 +844,20 @@ class TicketViewer extends React.Component {
} = this.props; } = this.props;
return _.filter(staffMembers, ({id, departments}) => { return _.filter(staffMembers, ({id, departments}) => {
const idComparer = onlyMeObject.onlyMe ? (id == userId) : (id != userId); return (id != userId) && _.some(departments, {id: ticket.department.id});
return idComparer && _.some(departments, {id: ticket.department.id});
}) })
} }
getCurrentStaff() {
const {
userId,
staffMembers,
ticket
} = this.props;
return _.find(staffMembers, ({id}) => {return id == userId});
}
getDepartmentsForTransfer() { getDepartmentsForTransfer() {
return this.props.ticket.author.staff ? SessionStore.getDepartments() : this.getPublicDepartments(); return this.props.ticket.author.staff ? SessionStore.getDepartments() : this.getPublicDepartments();
} }

View File

@ -1,6 +1,9 @@
import React from 'react'; import React from 'react';
import _ from 'lodash'; import _ from 'lodash';
import classNames from 'classnames'; import classNames from 'classnames';
import {connect} from 'react-redux';
import AdminDataActions from 'actions/admin-data-actions';
import i18n from 'lib-app/i18n'; import i18n from 'lib-app/i18n';
import API from 'lib-app/api-call'; import API from 'lib-app/api-call';
@ -312,6 +315,7 @@ class StaffEditor extends React.Component {
departments: (eventType === 'DEPARTMENTS') ? (departments && JSON.stringify(departments)) : null, departments: (eventType === 'DEPARTMENTS') ? (departments && JSON.stringify(departments)) : null,
} }
}).then(() => { }).then(() => {
this.retrieveStaffMembers();
window.scrollTo(0,0); window.scrollTo(0,0);
this.setState({message: eventType}); this.setState({message: eventType});
@ -361,6 +365,10 @@ class StaffEditor extends React.Component {
this.setState({message: 'FAIL', loadingPicture: false}); this.setState({message: 'FAIL', loadingPicture: false});
}); });
} }
retrieveStaffMembers() {
this.props.dispatch(AdminDataActions.retrieveStaffMembers());
}
} }
export default StaffEditor; export default connect()(StaffEditor);

View File

@ -64,11 +64,9 @@ class EditStaffController extends Controller {
if($this->staffInstance->isNull()) { if($this->staffInstance->isNull()) {
throw new RequestException(ERRORS::INVALID_STAFF); throw new RequestException(ERRORS::INVALID_STAFF);
return;
} }
} else { } else {
throw new RequestException(ERRORS::NO_PERMISSION); throw new RequestException(ERRORS::NO_PERMISSION);
return;
} }
if(Controller::request('departments')) { if(Controller::request('departments')) {