From 5d5e85a6c67312d9115e892799363db650cd8e27 Mon Sep 17 00:00:00 2001
From: frab1t <33671357+frab1t@users.noreply.github.com>
Date: Fri, 10 May 2019 16:25:24 +0200
Subject: [PATCH] Add TicketManager
---
.../Administration/TicketManager.js | 211 ++++++++++++++++++
1 file changed, 211 insertions(+)
create mode 100644 src/containers/Administration/TicketManager.js
diff --git a/src/containers/Administration/TicketManager.js b/src/containers/Administration/TicketManager.js
new file mode 100644
index 0000000..8d79b46
--- /dev/null
+++ b/src/containers/Administration/TicketManager.js
@@ -0,0 +1,211 @@
+import React, { Component } from 'react';
+import { Link, Redirect } from 'react-router-dom';
+
+import {
+ Button,
+ Row,
+ Col,
+ Form,
+ FormGroup,
+ Label,
+ Input
+} from 'reactstrap';
+
+import Card from '../../components/Card';
+import Table from '../../components/Table';
+import DropDown from '../../components/DropDown';
+
+
+class TicketWork extends Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ data: {},
+ categories: [],
+ status: '',
+ message: '',
+ error: '',
+ updateed: false,
+ isLoading: false,
+ };
+
+ this.handleSubmit = this.handleSubmit.bind(this);
+ this.handleInputChange = this.handleInputChange.bind(this);
+ }
+
+ componentDidMount() {
+ this.setState({ isLoading: true });
+
+ const { match: { params } } = this.props;
+
+ fetch(`http://localhost:3001/tickets?id=${params.ticketId}`)
+ .then(response => {
+ if (!response.ok) {
+ throw new Error('Error API');
+ }
+
+ return response.json();
+ })
+ .then(json => {
+ if (!json.length) {
+ throw new Error('Ticket Not found');
+ }
+
+ this.setState({ data: json[0], isLoading: false })
+ })
+ .catch(error => this.setState({ error, isLoading: false }));
+
+
+ fetch("http://localhost:3001/categories?type=ticketStatus")
+ .then((response) => {
+ if (!response.ok) {
+ throw new Error('Error API');
+ }
+
+ return response.json();
+ })
+ .then((json) => {
+ this.setState({
+ categories: json
+ });
+ })
+ .catch((err) => {
+ this.setState({
+ error: err.message
+ });
+ });
+ }
+
+ handleInputChange(event) {
+ const target = event.target;
+ const name = target.name;
+ const value = target.type === 'checkbox' ? target.checked : target.value;
+
+ this.setState({
+ [name]: value
+ });
+ }
+
+
+ handleSubmit(event) {
+ event.preventDefault();
+ const data = this.state;
+ const { match: { params } } = this.props;
+
+ if (!data.type === '---' || !data.message) {
+ alert('Form is invalid');
+ return;
+ }
+
+ fetch(`http://localhost:3001/tickets/${params.ticketId}`, {
+ method: 'PATCH',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ status: this.state.status,
+ note: this.state.message
+ })
+ })
+ .then(res => {
+ if(!res.ok) {
+ throw new Error('Error API');
+ }
+
+ return res.json();
+ })
+ .then((json) => {
+ alert("Ticket Updated");
+ this.setState({
+ updated: true
+ });
+ })
+ .catch((err) => {
+ this.setState({
+ ticketErr: err.message
+ });
+ });
+ }
+
+
+ render() {
+ const { data, updated, isLoading, error} = this.state;
+
+ if (error) {
+ return (
+ {error.message}