mirror of
https://github.com/franjsco/tick3t
synced 2025-01-15 19:00:38 +01:00
refactor: TicketList component
This commit is contained in:
parent
fa610280e0
commit
9ad5722b5b
@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
import PaginationComponent from "react-reactstrap-pagination";
|
import PaginationComponent from "react-reactstrap-pagination";
|
||||||
|
|
||||||
import { formatDate, decode } from '../../utils/helper';
|
import { formatDate, formatStatus } from '../../utils/helper';
|
||||||
import { getTickets, findTicket, filterTicketStatus } from '../../api/tickets';
|
import { getTickets, viewTicket, findTicket} from '../../api/tickets';
|
||||||
import { getAllTicketStatus } from '../../api/categories';
|
import { getAllTicketStatus } from '../../api/categories';
|
||||||
|
|
||||||
import Card from '../../components/Card';
|
import Card from '../../components/Card';
|
||||||
@ -40,6 +40,7 @@ class TicketList extends Component {
|
|||||||
this.filterStatus = this.filterStatus.bind(this);
|
this.filterStatus = this.filterStatus.bind(this);
|
||||||
this.handleInputChange = this.handleInputChange.bind(this);
|
this.handleInputChange = this.handleInputChange.bind(this);
|
||||||
this.handleSelected = this.handleSelected.bind(this);
|
this.handleSelected = this.handleSelected.bind(this);
|
||||||
|
this.resetError = this.resetError.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -88,7 +89,11 @@ class TicketList extends Component {
|
|||||||
this.setState({ selectedStatus: value })
|
this.setState({ selectedStatus: value })
|
||||||
|
|
||||||
getTickets(1, value)
|
getTickets(1, value)
|
||||||
.then(json => this.setState({ data: json.data, isLoading: false, totalPages: json.totalPages, selectedPage: 1 }))
|
.then(json => this.setState({
|
||||||
|
data: json.data,
|
||||||
|
isLoading: false,
|
||||||
|
totalPages: json.totalPages,
|
||||||
|
selectedPage: 1 }))
|
||||||
.catch(error => this.setState({ error, isLoading: false }));
|
.catch(error => this.setState({ error, isLoading: false }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +109,22 @@ class TicketList extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetError() {
|
||||||
|
this.setState({error: ''});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
|
if (this.state.error) {
|
||||||
|
return (
|
||||||
|
<Card
|
||||||
|
title="Error"
|
||||||
|
>
|
||||||
|
<p>{this.state.error.message}</p>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let tickets = this.state.data;
|
let tickets = this.state.data;
|
||||||
if (tickets) {
|
if (tickets) {
|
||||||
tickets = tickets.map((ticket) => {
|
tickets = tickets.map((ticket) => {
|
||||||
@ -117,10 +136,10 @@ class TicketList extends Component {
|
|||||||
</Link>
|
</Link>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
{decode(ticket.status)}
|
{formatStatus(ticket.status)}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{decode(ticket.type)}
|
{formatStatus(ticket.type)}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{ticket.subject}
|
{ticket.subject}
|
||||||
|
Loading…
Reference in New Issue
Block a user