From 6df49ba956da59bee8af86a101475baab3f99a49 Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Tue, 14 Oct 2025 22:29:38 -0300 Subject: [PATCH] Portal polishing: hide queue/priority for customers; use RTE + attachments in detail; filter list to requester only for collaborators --- convex/tickets.ts | 7 ++++ src/components/portal/portal-ticket-card.tsx | 20 +++++++---- .../portal/portal-ticket-detail.tsx | 33 +++++++------------ 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/convex/tickets.ts b/convex/tickets.ts index 4cfc8e2..fba7860 100644 --- a/convex/tickets.ts +++ b/convex/tickets.ts @@ -268,6 +268,13 @@ export const list = query({ .query("tickets") .withIndex("by_tenant_queue", (q) => q.eq("tenantId", args.tenantId).eq("queueId", args.queueId!)) .collect(); + } else if (role === "COLLABORATOR") { + // Colaborador: exibir apenas tickets onde ele é o solicitante + const all = await ctx.db + .query("tickets") + .withIndex("by_tenant", (q) => q.eq("tenantId", args.tenantId)) + .collect() + base = all.filter((t) => t.requesterId === args.viewerId) } else { base = await ctx.db .query("tickets") diff --git a/src/components/portal/portal-ticket-card.tsx b/src/components/portal/portal-ticket-card.tsx index 15de559..9f86c10 100644 --- a/src/components/portal/portal-ticket-card.tsx +++ b/src/components/portal/portal-ticket-card.tsx @@ -7,6 +7,7 @@ import Link from "next/link" import { Tag } from "lucide-react" import type { Ticket } from "@/lib/schemas/ticket" +import { useAuth } from "@/lib/auth-client" import { Badge } from "@/components/ui/badge" import { Card, CardContent, CardHeader } from "@/components/ui/card" import { cn } from "@/lib/utils" @@ -44,6 +45,7 @@ interface PortalTicketCardProps { } export function PortalTicketCard({ ticket }: PortalTicketCardProps) { + const { isCustomer } = useAuth() const updatedAgo = formatDistanceToNow(ticket.updatedAt, { addSuffix: true, locale: ptBR, @@ -68,16 +70,20 @@ export function PortalTicketCard({ ticket }: PortalTicketCardProps) { {statusLabel[ticket.status]} - - {priorityLabel[ticket.priority]} - + {!isCustomer ? ( + + {priorityLabel[ticket.priority]} + + ) : null} -
- Fila - {ticket.queue ?? "Sem fila"} -
+ {!isCustomer ? ( +
+ Fila + {ticket.queue ?? "Sem fila"} +
+ ) : null}
Status {statusLabel[ticket.status]} diff --git a/src/components/portal/portal-ticket-detail.tsx b/src/components/portal/portal-ticket-detail.tsx index 427de8c..6941b2c 100644 --- a/src/components/portal/portal-ticket-detail.tsx +++ b/src/components/portal/portal-ticket-detail.tsx @@ -14,12 +14,12 @@ import type { TicketWithDetails } from "@/lib/schemas/ticket" import { useAuth } from "@/lib/auth-client" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" -import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Dropzone } from "@/components/ui/dropzone" import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "@/components/ui/empty" import { Skeleton } from "@/components/ui/skeleton" -import { Textarea } from "@/components/ui/textarea" +import { RichTextEditor } from "@/components/ui/textarea" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" -import { sanitizeEditorHtml } from "@/components/ui/rich-text-editor" +import { sanitizeEditorHtml, RichTextEditor } from "@/components/ui/rich-text-editor" const statusLabel: Record = { PENDING: "Pendente", @@ -69,7 +69,7 @@ interface PortalTicketDetailProps { export function PortalTicketDetail({ ticketId }: PortalTicketDetailProps) { const { convexUserId, session } = useAuth() const addComment = useMutation(api.tickets.addComment) - const [comment, setComment] = useState("") + const [comment, setComment] = useState(""); const [attachments, setAttachments] = useState>([]) const ticketRaw = useQuery( api.tickets.getById, @@ -133,7 +133,7 @@ export function PortalTicketDetail({ ticketId }: PortalTicketDetailProps) { authorId: convexUserId as Id<"users">, visibility: "PUBLIC", body: htmlBody, - attachments: [], + attachments: attachments.map((f) => ({ storageId: f.storageId as Id<"_storage">, name: f.name, size: f.size, type: f.type, })), }) setComment("") toast.success("Comentário enviado!", { id: toastId }) @@ -186,22 +186,7 @@ export function PortalTicketDetail({ ticketId }: PortalTicketDetailProps) {
- -