diff --git a/src/components/dog.js b/src/components/dog.js
index e3a0404..1622652 100644
--- a/src/components/dog.js
+++ b/src/components/dog.js
@@ -1,6 +1,6 @@
import React from 'react';
import { withRouter } from 'react-router';
-import { Image, Row, Col, Typography } from 'antd'
+import { Image, Row, Col, Typography, Space, Button } from 'antd'
import DogIcon from './dogicon';
import { status, json } from '../utilities/requestHandlers';
@@ -10,8 +10,9 @@ class Dog extends React.Component {
constructor(props) {
super(props);
+ this.deleteHandler = this.deleteHandler.bind(this)
this.state = {
- dog: undefined
+ dog: {}
}
this.toggleLike = this.toggleLike.bind(this);
}
@@ -23,6 +24,7 @@ class Dog extends React.Component {
.then(status)
.then(json)
.then(dog => {
+ console.log(dog)
this.setState({dog:dog})
})
.catch(err => {
@@ -37,12 +39,44 @@ class Dog extends React.Component {
// and imported into both components.
console.log('like was toggled');
}
+
+ deleteHandler() {
+ const username = this.context.user.username
+ const password = this.context.user.password
+ console.log(`deleting dog: ${this.state.dog.ID}`)
+ fetch(`https://animal-hello-3000.codio-box.uk/api/v1/dogs/${this.state.dog.ID}`, {
+ method: "DELETE",
+ headers: {
+ "Authorization": "Basic " + btoa(username + ":" + password)
+ }
+ })
+ .then(status)
+ .then(user => {
+ console.log(`Deleted dog ${this.state.dog.ID}`);
+ this.props.history.push('/')
+ })
+ .catch(error => {
+ console.log('Delete failed' + error);
+ });
+ }
render() {
- if (!this.state.dog) {
+ const user = this.state.user;
+ const dog = this.state.dog;
+ /*
+ //Error Here!! Change the user.role to a valid verification
+ let adminSpace =