mirror of https://github.com/franjsco/tick3t
feat: implement ticket management
This commit is contained in:
parent
ee13b24293
commit
3c5ed86e60
|
@ -10,6 +10,8 @@ import {
|
||||||
Input
|
Input
|
||||||
} from 'reactstrap';
|
} from 'reactstrap';
|
||||||
|
|
||||||
|
import { config } from '../../config';
|
||||||
|
|
||||||
import Card from '../../components/Card';
|
import Card from '../../components/Card';
|
||||||
import Table from '../../components/Table';
|
import Table from '../../components/Table';
|
||||||
import DropDown from '../../components/DropDown';
|
import DropDown from '../../components/DropDown';
|
||||||
|
@ -33,7 +35,6 @@ class TicketManager extends Component {
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
this.handleInputChange = this.handleInputChange.bind(this);
|
this.handleInputChange = this.handleInputChange.bind(this);
|
||||||
|
|
||||||
this.API_URL= process.env.REACT_APP_API_URL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -41,7 +42,7 @@ class TicketManager extends Component {
|
||||||
|
|
||||||
const { match: { params } } = this.props;
|
const { match: { params } } = this.props;
|
||||||
|
|
||||||
fetch(`${this.API_URL}tickets?id=${params.ticketId}`)
|
fetch(`${config.baseURL}tickets/${params.ticketId}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Error API');
|
throw new Error('Error API');
|
||||||
|
@ -50,16 +51,16 @@ class TicketManager extends Component {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if (!json.length) {
|
if (!json.data) {
|
||||||
throw new Error('Ticket Not found');
|
throw new Error('Ticket Not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({ data: json[0], isLoading: false })
|
this.setState({ data: json.data, isLoading: false })
|
||||||
})
|
})
|
||||||
.catch(error => this.setState({ error, isLoading: false }));
|
.catch(error => this.setState({ error, isLoading: false }));
|
||||||
|
|
||||||
|
|
||||||
fetch(`${this.API_URL}categories?type=ticketStatus`)
|
fetch(`${config.baseURL}categories?type=TicketStatus`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Error API');
|
throw new Error('Error API');
|
||||||
|
@ -69,7 +70,7 @@ class TicketManager extends Component {
|
||||||
})
|
})
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
categories: json
|
categories: json.data
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -100,8 +101,8 @@ class TicketManager extends Component {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch(`${this.API_URL}tickets/${params.ticketId}`, {
|
fetch(`${config.baseURL}tickets/${params.ticketId}`, {
|
||||||
method: 'PATCH',
|
method: 'PUT',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
status: this.state.status,
|
status: this.state.status,
|
||||||
|
@ -146,7 +147,7 @@ class TicketManager extends Component {
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
return (
|
return (
|
||||||
<Redirect to="/admin/ticket" />
|
<Redirect to="/admin/" />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +161,7 @@ class TicketManager extends Component {
|
||||||
<Row>
|
<Row>
|
||||||
<Col>
|
<Col>
|
||||||
<Table data={data} />
|
<Table data={data} />
|
||||||
<Link to="/admin/ticket">Go to ticket list</Link>
|
<Link to="/admin/">Go to ticket list</Link>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
@ -196,7 +197,7 @@ class TicketManager extends Component {
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup row>
|
<FormGroup row>
|
||||||
<Col align="right">
|
<Col align="right">
|
||||||
<Button>Update Ticket</Button>
|
<Button type="submit">Update Ticket</Button>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
Loading…
Reference in New Issue