feat: implement ticket management

This commit is contained in:
frab1t 2019-07-03 10:28:53 +02:00
parent ee13b24293
commit 3c5ed86e60
1 changed files with 14 additions and 13 deletions

View File

@ -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,14 +70,14 @@ class TicketManager extends Component {
}) })
.then((json) => { .then((json) => {
this.setState({ this.setState({
categories: json categories: json.data
}); });
}) })
.catch((err) => { .catch((err) => {
this.setState({ this.setState({
error: err.message error: err.message
}); });
}); });
} }
handleInputChange(event) { handleInputChange(event) {
@ -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>