Paginate ticket list in admin panel view user (#944)
Co-authored-by: Ivan Diaz <ivan@opensupports.com>
This commit is contained in:
parent
1e0e0134a3
commit
51eee4ed7b
|
@ -14,6 +14,11 @@ import Message from 'core-components/message';
|
|||
import InfoTooltip from 'core-components/info-tooltip';
|
||||
import Autocomplete from 'core-components/autocomplete';
|
||||
|
||||
const INITIAL_API_VALUE = {
|
||||
page: 1,
|
||||
departments: undefined,
|
||||
};
|
||||
|
||||
class AdminPanelViewUser extends React.Component {
|
||||
|
||||
state = {
|
||||
|
@ -31,6 +36,7 @@ class AdminPanelViewUser extends React.Component {
|
|||
|
||||
componentDidMount() {
|
||||
this.retrieveUser();
|
||||
this.retrieveUserTickets(INITIAL_API_VALUE);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -248,13 +254,12 @@ class AdminPanelViewUser extends React.Component {
|
|||
}
|
||||
|
||||
onUserRetrieved(result) {
|
||||
const { name, email, verified, tickets, disabled, customfields, userList } = result.data;
|
||||
const { name, email, verified, disabled, customfields, userList } = result.data;
|
||||
|
||||
this.setState({
|
||||
name,
|
||||
email,
|
||||
verified,
|
||||
tickets,
|
||||
disabled,
|
||||
customfields,
|
||||
loading: false,
|
||||
|
@ -308,6 +313,61 @@ class AdminPanelViewUser extends React.Component {
|
|||
invalid: true
|
||||
}));
|
||||
}
|
||||
|
||||
getTicketListProps() {
|
||||
const { departments, params } = this.props;
|
||||
const { tickets, page, pages, loading } = this.state;
|
||||
|
||||
return {
|
||||
type: 'secondary',
|
||||
userId: params.userId,
|
||||
tickets,
|
||||
loading,
|
||||
departments,
|
||||
ticketPath: '/admin/panel/tickets/view-ticket/',
|
||||
page,
|
||||
pages,
|
||||
onPageChange: this.onPageChange.bind(this),
|
||||
onDepartmentChange: this.onDepartmentChange.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
onPageChange(event) {
|
||||
this.setState({
|
||||
page: event.target.value
|
||||
});
|
||||
|
||||
this.retrieveUserTickets({page: event.target.value});
|
||||
}
|
||||
|
||||
onDepartmentChange(department) {
|
||||
this.setState({
|
||||
department
|
||||
});
|
||||
|
||||
this.retrieveUserTickets({
|
||||
department: department ? `[${department}]` : undefined
|
||||
});
|
||||
}
|
||||
|
||||
retrieveUserTickets({page, department}) {
|
||||
API.call({
|
||||
path: '/ticket/search',
|
||||
data: {
|
||||
page,
|
||||
departments: department,
|
||||
authors: `[{"id":${this.props.params.userId}, "isStaff":0}]`
|
||||
}
|
||||
}).then((result) => {
|
||||
const data = result.data;
|
||||
|
||||
this.setState({
|
||||
tickets: data.tickets,
|
||||
page: data.page,
|
||||
pages: data.pages
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default connect((store) => {
|
||||
|
|
|
@ -23,7 +23,6 @@ DataValidator::with('CustomValidations', true);
|
|||
* @apiSuccess {String} data.name Name of the user
|
||||
* @apiSuccess {String} data.email Email of the user
|
||||
* @apiSuccess {Number} data.signupDate Date of signup of the user
|
||||
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data.tickets Array of tickets of the user
|
||||
* @apiSuccess {Boolean} data.verified Indicates if the user is verified
|
||||
*
|
||||
*/
|
||||
|
@ -45,23 +44,14 @@ class GetUserByIdController extends Controller {
|
|||
}
|
||||
|
||||
public function handler() {
|
||||
|
||||
$userId = Controller::request('userId');
|
||||
$user = User::getDataStore($userId);
|
||||
$staff = Controller::getLoggedUser();
|
||||
|
||||
$tickets = new DataStoreList();
|
||||
|
||||
foreach($user->sharedTicketList as $ticket) {
|
||||
if($staff->sharedDepartmentList->includesId($ticket->department->id)) {
|
||||
$tickets->add($ticket);
|
||||
}
|
||||
}
|
||||
Response::respondSuccess([
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'signupDate' => $user->signupDate,
|
||||
'tickets' => $tickets->toArray(true),
|
||||
'verified' => !$user->verificationToken,
|
||||
'disabled' => !!$user->disabled,
|
||||
'customfields' => $user->xownCustomfieldvalueList->toArray(),
|
||||
|
|
|
@ -23,7 +23,6 @@ describe '/user/get-user' do
|
|||
(user['email']).should.equal(result['data']['email'])
|
||||
(user['signup_date']).should.equal(result['data']['signupDate'].to_i)
|
||||
(user['name']).should.equal(result['data']['name'])
|
||||
(user['tickets']).should.equal(result['data']['tickets'].size)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue