fix(priority/delete): pass actorId from useAuth to Convex mutations

This commit is contained in:
esdrasrenan 2025-10-04 15:04:12 -03:00
parent 97ca2b3b54
commit 65ccb98741
3 changed files with 14 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import { useMutation } from "convex/react"
// @ts-ignore // @ts-ignore
import { api } from "@/convex/_generated/api" import { api } from "@/convex/_generated/api"
import type { Id } from "@/convex/_generated/dataModel" 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 { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogTrigger } from "@/components/ui/dialog"
import { Button } from "@/components/ui/button" import { Button } from "@/components/ui/button"
import { AlertTriangle, Trash2 } from "lucide-react" import { AlertTriangle, Trash2 } from "lucide-react"
@ -16,12 +17,14 @@ export function DeleteTicketDialog({ ticketId }: { ticketId: Id<"tickets"> }) {
const remove = useMutation(api.tickets.remove) const remove = useMutation(api.tickets.remove)
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const { userId } = useAuth()
async function confirm() { async function confirm() {
setLoading(true) setLoading(true)
toast.loading("Excluindo ticket...", { id: "del" }) toast.loading("Excluindo ticket...", { id: "del" })
try { 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" }) toast.success("Ticket excluído.", { id: "del" })
setOpen(false) setOpen(false)
router.push("/tickets") router.push("/tickets")
@ -58,4 +61,3 @@ export function DeleteTicketDialog({ ticketId }: { ticketId: Id<"tickets"> }) {
</Dialog> </Dialog>
) )
} }

View file

@ -46,13 +46,18 @@ export function NewTicketDialog() {
async function submit(values: z.infer<typeof schema>) { async function submit(values: z.infer<typeof schema>) {
if (!userId) return if (!userId) return
const subjectTrimmed = (values.subject ?? "").trim()
if (subjectTrimmed.length < 3) {
form.setError("subject", { type: "min", message: "Informe um assunto" })
return
}
setLoading(true) setLoading(true)
toast.loading("Criando ticket…", { id: "new-ticket" }) toast.loading("Criando ticket…", { id: "new-ticket" })
try { try {
const sel = queues.find((q) => q.name === values.queueName) const sel = queues.find((q) => q.name === values.queueName)
const id = await create({ const id = await create({
tenantId: DEFAULT_TENANT_ID, tenantId: DEFAULT_TENANT_ID,
subject: values.subject, subject: subjectTrimmed,
summary: values.summary, summary: values.summary,
priority: values.priority, priority: values.priority,
channel: values.channel, channel: values.channel,

View file

@ -5,7 +5,7 @@ import { useMutation } from "convex/react"
// @ts-ignore // @ts-ignore
import { api } from "@/convex/_generated/api" import { api } from "@/convex/_generated/api"
import type { Id } from "@/convex/_generated/dataModel" 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 { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Badge } from "@/components/ui/badge" import { Badge } from "@/components/ui/badge"
import { toast } from "sonner" 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" }) { export function PrioritySelect({ ticketId, value }: { ticketId: Id<"tickets">; value: "LOW" | "MEDIUM" | "HIGH" | "URGENT" }) {
const updatePriority = useMutation(api.tickets.updatePriority) const updatePriority = useMutation(api.tickets.updatePriority)
const [priority, setPriority] = useState(value) const [priority, setPriority] = useState(value)
const { userId } = useAuth()
return ( return (
<Select <Select
value={priority} value={priority}
@ -41,7 +42,8 @@ export function PrioritySelect({ ticketId, value }: { ticketId: Id<"tickets">; v
setPriority(val as typeof priority) setPriority(val as typeof priority)
toast.loading("Atualizando prioridade...", { id: "prio" }) toast.loading("Atualizando prioridade...", { id: "prio" })
try { try {
await updatePriority({ ticketId, priority: val as any, actorId: undefined as unknown as Id<"users"> }) if (!userId) throw new Error("No user")
await updatePriority({ ticketId, priority: val as any, actorId: userId as Id<"users"> })
toast.success("Prioridade atualizada!", { id: "prio" }) toast.success("Prioridade atualizada!", { id: "prio" })
} catch { } catch {
setPriority(prev) setPriority(prev)
@ -64,4 +66,3 @@ export function PrioritySelect({ ticketId, value }: { ticketId: Id<"tickets">; v
</Select> </Select>
) )
} }