Skip to content

Commit 44204cd

Browse files
committed
feat: delete comments
1 parent 89cb593 commit 44204cd

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

apps/api/src/controllers/ticket.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,26 @@ export function ticketRoutes(fastify: FastifyInstance) {
527527
}
528528
);
529529

530+
fastify.post(
531+
"/api/v1/ticket/comment/delete",
532+
{
533+
preHandler: requirePermission(["issue::comment"]),
534+
},
535+
async (request: FastifyRequest, reply: FastifyReply) => {
536+
const { id }: any = request.body;
537+
538+
await prisma.comment.delete({
539+
where: {
540+
id: id,
541+
},
542+
});
543+
544+
reply.send({
545+
success: true,
546+
});
547+
}
548+
);
549+
530550
// Update status of a ticket
531551
fastify.put(
532552
"/api/v1/ticket/status/update",

apps/api/src/lib/services/imap.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class ImapService {
105105
name: from.value[0].name,
106106
title: imapEmail.subject || "-",
107107
isComplete: false,
108-
priority: "Low",
108+
priority: "low",
109109
fromImap: true,
110110
detail: html || textAsHtml,
111111
},

apps/client/components/TicketDetails/index.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,29 @@ export default function Ticket() {
272272
.then(() => refetch());
273273
}
274274

275+
async function deleteComment(id: string) {
276+
await fetch(`/api/v1/ticket/comment/delete`, {
277+
method: "POST",
278+
headers: {
279+
"Content-Type": "application/json",
280+
Authorization: `Bearer ${token}`,
281+
},
282+
body: JSON.stringify({ id }),
283+
})
284+
.then((res) => res.json())
285+
.then((res) => {
286+
if (res.success) {
287+
refetch();
288+
} else {
289+
toast({
290+
variant: "destructive",
291+
title: "Error",
292+
description: "Failed to delete comment",
293+
});
294+
}
295+
});
296+
}
297+
275298
async function addTime() {
276299
if (data && data.ticket && data.ticket.locked) return;
277300

@@ -846,7 +869,7 @@ export default function Ticket() {
846869
data.ticket.comments.map((comment: any) => (
847870
<li
848871
key={comment.id}
849-
className="flex flex-col space-y-1 text-sm bg-secondary/50 dark:bg-secondary/50 px-4 py-2 rounded-lg "
872+
className="group flex flex-col space-y-1 text-sm bg-secondary/50 dark:bg-secondary/50 px-4 py-2 rounded-lg relative"
850873
>
851874
<div className="flex flex-row space-x-2 items-center">
852875
<Avatar className="w-6 h-6">
@@ -869,6 +892,15 @@ export default function Ticket() {
869892
<span className="text-xs lowercase">
870893
{moment(comment.createdAt).format("LLL")}
871894
</span>
895+
{comment.user &&
896+
comment.userId === user.id && (
897+
<Trash2
898+
className="h-4 w-4 absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer text-muted-foreground hover:text-destructive"
899+
onClick={() => {
900+
deleteComment(comment.id);
901+
}}
902+
/>
903+
)}
872904
</div>
873905
<span className="ml-1">{comment.text}</span>
874906
</li>

0 commit comments

Comments
 (0)