diff --git a/web/src/components/tickets/delete-ticket-dialog.tsx b/web/src/components/tickets/delete-ticket-dialog.tsx index 75d1b31..9cb51c5 100644 --- a/web/src/components/tickets/delete-ticket-dialog.tsx +++ b/web/src/components/tickets/delete-ticket-dialog.tsx @@ -6,6 +6,7 @@ import { useMutation } from "convex/react" // @ts-ignore import { api } from "@/convex/_generated/api" import type { Id } from "@/convex/_generated/dataModel" +import { useAuth } from "@/lib/auth-client" import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogTrigger } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { AlertTriangle, Trash2 } from "lucide-react" @@ -16,12 +17,14 @@ export function DeleteTicketDialog({ ticketId }: { ticketId: Id<"tickets"> }) { const remove = useMutation(api.tickets.remove) const [open, setOpen] = useState(false) const [loading, setLoading] = useState(false) + const { userId } = useAuth() async function confirm() { setLoading(true) toast.loading("Excluindo ticket...", { id: "del" }) try { - await remove({ ticketId, actorId: undefined as unknown as Id<"users"> }) + if (!userId) throw new Error("No user") + await remove({ ticketId, actorId: userId as Id<"users"> }) toast.success("Ticket excluído.", { id: "del" }) setOpen(false) router.push("/tickets") @@ -58,4 +61,3 @@ export function DeleteTicketDialog({ ticketId }: { ticketId: Id<"tickets"> }) { ) } - diff --git a/web/src/components/tickets/new-ticket-dialog.tsx b/web/src/components/tickets/new-ticket-dialog.tsx index e69f978..d52cd73 100644 --- a/web/src/components/tickets/new-ticket-dialog.tsx +++ b/web/src/components/tickets/new-ticket-dialog.tsx @@ -46,13 +46,18 @@ export function NewTicketDialog() { async function submit(values: z.infer) { if (!userId) return + const subjectTrimmed = (values.subject ?? "").trim() + if (subjectTrimmed.length < 3) { + form.setError("subject", { type: "min", message: "Informe um assunto" }) + return + } setLoading(true) toast.loading("Criando ticket…", { id: "new-ticket" }) try { const sel = queues.find((q) => q.name === values.queueName) const id = await create({ tenantId: DEFAULT_TENANT_ID, - subject: values.subject, + subject: subjectTrimmed, summary: values.summary, priority: values.priority, channel: values.channel, diff --git a/web/src/components/tickets/priority-select.tsx b/web/src/components/tickets/priority-select.tsx index d35d8f2..34e53ab 100644 --- a/web/src/components/tickets/priority-select.tsx +++ b/web/src/components/tickets/priority-select.tsx @@ -5,7 +5,7 @@ import { useMutation } from "convex/react" // @ts-ignore import { api } from "@/convex/_generated/api" import type { Id } from "@/convex/_generated/dataModel" -import type { TicketStatus } from "@/lib/schemas/ticket" +import { useAuth } from "@/lib/auth-client" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Badge } from "@/components/ui/badge" import { toast } from "sonner" @@ -33,6 +33,7 @@ function badgeClass(p: string) { export function PrioritySelect({ ticketId, value }: { ticketId: Id<"tickets">; value: "LOW" | "MEDIUM" | "HIGH" | "URGENT" }) { const updatePriority = useMutation(api.tickets.updatePriority) const [priority, setPriority] = useState(value) + const { userId } = useAuth() return ( ) } -