Skip to content
Permalink
Browse files
added delete to the messages for admin
  • Loading branch information
peacoc17 committed Apr 15, 2021
1 parent eea85e2 commit 2daade8dc86a98351946e66f22e4c0456ce30f85
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
@@ -34,24 +34,43 @@ class Messages extends React.Component{
});


fetch(`http://localhost:3000/api/v1/message/${this.context.user.ID}`, {
headers: {
"Authorization": this.context.user.Authorization,
}
})
.then(status)
.then(json)
.then(data => {
console.log(data)
this.setState({messages:data})
})
.catch(errorResponse => {
alert("Creation failed" +errorResponse)
console.log('Creation failed');
alert(`Error: ${JSON.stringify(errorResponse)}`);
});
fetch(`http://localhost:3000/api/v1/message/${this.context.user.ID}`, {
headers: {
"Authorization": this.context.user.Authorization,
}
})
.then(status)
.then(json)
.then(data => {
console.log(data)
this.setState({messages:data})
})
.catch(errorResponse => {
alert("Creation failed" +errorResponse)
console.log('Creation failed');
alert(`Error: ${JSON.stringify(errorResponse)}`);
});

};



delete(ID){
fetch(`http://localhost:3000/api/v1/message/${ID}`, {
method: "DELETE",
headers: {
"Authorization": this.context.user.Authorization,
}
})
.then(status)
.then(data => {
console.log(data)
})
.catch(errorResponse => {
console.log('Delete failed');
alert(`Error: ${JSON.stringify(errorResponse)}`);
});
}



@@ -77,6 +96,7 @@ class Messages extends React.Component{
<h3>User{message.authorID}:</h3>
<p>{message.allText}</p>
<button><Link to ={{pathname: `/reply/${message.authorID}`,state:{data:message.authorID}}}>Reply</Link></button>
<button onClick={()=>{this.delete(message.ID)}}>Delete</button>
</Col>
</div>
)
@@ -51,7 +51,6 @@ class Reply extends React.Component{
render() {
return (
<Form {...formItemLayout} name="Create" onFinish={this.add} scrollToFirstError >
<p>{this.props.location.state.data.ID}</p>

<Form.Item name="allText" label="Your Message">
<Input />

0 comments on commit 2daade8

Please sign in to comment.