Skip to content

Commit

Permalink
feat: delete comments
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Nov 14, 2024
1 parent 89cb593 commit 44204cd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
20 changes: 20 additions & 0 deletions apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,26 @@ export function ticketRoutes(fastify: FastifyInstance) {
}
);

fastify.post(
"/api/v1/ticket/comment/delete",
{
preHandler: requirePermission(["issue::comment"]),
},
async (request: FastifyRequest, reply: FastifyReply) => {
const { id }: any = request.body;

await prisma.comment.delete({
where: {
id: id,
},
});

reply.send({
success: true,
});
}
);

// Update status of a ticket
fastify.put(
"/api/v1/ticket/status/update",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/services/imap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class ImapService {
name: from.value[0].name,
title: imapEmail.subject || "-",
isComplete: false,
priority: "Low",
priority: "low",
fromImap: true,
detail: html || textAsHtml,
},
Expand Down
34 changes: 33 additions & 1 deletion apps/client/components/TicketDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,29 @@ export default function Ticket() {
.then(() => refetch());
}

async function deleteComment(id: string) {
await fetch(`/api/v1/ticket/comment/delete`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({ id }),
})
.then((res) => res.json())
.then((res) => {
if (res.success) {
refetch();
} else {
toast({
variant: "destructive",
title: "Error",
description: "Failed to delete comment",
});
}
});
}

async function addTime() {
if (data && data.ticket && data.ticket.locked) return;

Expand Down Expand Up @@ -846,7 +869,7 @@ export default function Ticket() {
data.ticket.comments.map((comment: any) => (
<li
key={comment.id}
className="flex flex-col space-y-1 text-sm bg-secondary/50 dark:bg-secondary/50 px-4 py-2 rounded-lg "
className="group flex flex-col space-y-1 text-sm bg-secondary/50 dark:bg-secondary/50 px-4 py-2 rounded-lg relative"
>
<div className="flex flex-row space-x-2 items-center">
<Avatar className="w-6 h-6">
Expand All @@ -869,6 +892,15 @@ export default function Ticket() {
<span className="text-xs lowercase">
{moment(comment.createdAt).format("LLL")}
</span>
{comment.user &&
comment.userId === user.id && (
<Trash2
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"
onClick={() => {
deleteComment(comment.id);
}}
/>
)}
</div>
<span className="ml-1">{comment.text}</span>
</li>
Expand Down

0 comments on commit 44204cd

Please sign in to comment.