From 7c025a039812b1dc0fbec55d45d1a731657f0012 Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Sun, 19 Oct 2025 02:45:53 -0300 Subject: [PATCH] Allow managers to comment without assignee; keep assignee requirement for admin/agent; reflect in UI --- convex/tickets.ts | 5 +++-- src/components/tickets/ticket-comments.rich.tsx | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/convex/tickets.ts b/convex/tickets.ts index bd7bf00..9f248a4 100644 --- a/convex/tickets.ts +++ b/convex/tickets.ts @@ -781,9 +781,10 @@ export const addComment = mutation({ // Regra: a equipe (ADMIN/AGENT/MANAGER) só pode comentar se o ticket tiver responsável. // O solicitante (colaborador) pode comentar sempre. const isRequester = String(ticketDoc.requesterId) === String(author._id) - const isStaff = normalizedRole === "ADMIN" || normalizedRole === "AGENT" || normalizedRole === "MANAGER" + const isAdminOrAgent = normalizedRole === "ADMIN" || normalizedRole === "AGENT" const hasAssignee = Boolean(ticketDoc.assigneeId) - if (!isRequester && isStaff && !hasAssignee) { + // Gestores podem comentar mesmo sem responsável; admin/agent só com responsável + if (!isRequester && isAdminOrAgent && !hasAssignee) { throw new ConvexError("Somente é possível comentar quando o chamado possui um responsável.") } diff --git a/src/components/tickets/ticket-comments.rich.tsx b/src/components/tickets/ticket-comments.rich.tsx index 849ef8c..08b0e61 100644 --- a/src/components/tickets/ticket-comments.rich.tsx +++ b/src/components/tickets/ticket-comments.rich.tsx @@ -38,7 +38,9 @@ export function TicketComments({ ticket }: TicketCommentsProps) { const canSeeInternalComments = normalizedRole === "admin" || normalizedRole === "agent" const hasAssignee = Boolean(ticket.assignee) const isRequester = convexUserId ? ticket.requester.id === convexUserId : false - const canStaffComment = hasAssignee + // Gestor pode comentar sem responsável; admin/agent só com responsável + const isManager = normalizedRole === "manager" + const canStaffComment = hasAssignee || isManager const canComment = isRequester || (isStaff && canStaffComment) const addComment = useMutation(api.tickets.addComment) const removeAttachment = useMutation(api.tickets.removeCommentAttachment) @@ -366,7 +368,7 @@ export function TicketComments({ ticket }: TicketCommentsProps) { )} {!canComment && (
- Atribua um responsável ao chamado para que a equipe possa comentar. + Atribua um responsável ao chamado para que a equipe técnica possa comentar.
)}