Skip to content

Commit 1d1b128

Browse files
committed
implemented comment deletion
1 parent 0bc6e3e commit 1d1b128

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/user/Admin/Tickets/TicketDiscussion/Discussion/Discussion.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import SendOutlinedIcon from "@material-ui/icons/SendOutlined";
1313
import userIcon2 from "../../../../../assets/images/userIcon2.jpg";
1414
import ThumbDownOutlinedIcon from "@material-ui/icons/ThumbDownOutlined";
1515
import ThumbUpAltOutlinedIcon from "@material-ui/icons/ThumbUpAltOutlined";
16+
import DeleteOutlineOutlinedIcon from "@material-ui/icons/DeleteOutlineOutlined";
1617

1718
class Discussion extends Component {
1819
constructor(props) {
@@ -169,7 +170,17 @@ class Discussion extends Component {
169170
/>
170171
</div>
171172
<div className="img-desc">
172-
<h2>{ele.createdBy.name}</h2>
173+
<h2>
174+
{ele.createdBy.name}
175+
{this.props.deleteAllowed && <DeleteOutlineOutlinedIcon
176+
style={{
177+
color: "rgba(0,0,0,0.5)",
178+
fontSize: "18px",
179+
cursor: "pointer"
180+
}}
181+
onClick={() => this.props.deleteComment(ele._id)}
182+
/>}
183+
</h2>
173184
<p className="discussion-date">
174185
<Moment format="DD MMM YYYY">{ele.createdAt}</Moment>
175186
</p>

src/user/Admin/Tickets/TicketDiscussion/TicketDiscussion.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
width: 50px;
147147
height: 40px;
148148
display: flex;
149+
cursor: pointer;
149150
align-items: center;
150151
span {
151152
margin-left: 5px;

src/user/Admin/Tickets/TicketDiscussion/TicketDiscussions.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class TicketDiscussions extends Component {
3737
localStorage.getItem("ticketModerator") === "true" ||
3838
localStorage.getItem("admin") === "true" ||
3939
localStorage.getItem("userId") === ticket.createdBy.id;
40+
this.deleteAllowed =
41+
localStorage.getItem("ticketModerator") === "true" ||
42+
localStorage.getItem("admin") === "true";
4043
this.setState({ ticket: ticket });
4144
};
4245

@@ -106,6 +109,21 @@ class TicketDiscussions extends Component {
106109
}
107110
};
108111

112+
handleCommentDelete = async (commentId) => {
113+
try {
114+
const newTicket = (
115+
await Axios.delete(
116+
`${BASE_URL}/ticket/${this.state.ticket._id}/comment/${commentId}`
117+
)
118+
).data.ticket;
119+
this.setState({
120+
ticket: newTicket,
121+
});
122+
} catch (err) {
123+
console.log(err);
124+
}
125+
};
126+
109127
handleAddTag = async (tagName) => {
110128
if (this.state.ticket.tags.indexOf(tagName) !== -1) {
111129
toast.error("Tag already present");
@@ -172,8 +190,10 @@ class TicketDiscussions extends Component {
172190
ticket={this.state.ticket}
173191
sendComment={this.sendComment}
174192
editsAllowed={this.editsAllowed}
193+
deleteAllowed={this.deleteAllowed}
175194
updateTicket={this.handleUpdateTicket}
176195
upVoteComment={this.handleCommentUpvote}
196+
deleteComment={this.handleCommentDelete}
177197
downVoteComment={this.handleCommentDownvote}
178198
/>
179199
)}

0 commit comments

Comments
 (0)