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
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"> }) {
</Dialog>
)
}

View file

@ -46,13 +46,18 @@ export function NewTicketDialog() {
async function submit(values: z.infer<typeof schema>) {
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,

View file

@ -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 (
<Select
value={priority}
@ -41,7 +42,8 @@ export function PrioritySelect({ ticketId, value }: { ticketId: Id<"tickets">; v
setPriority(val as typeof priority)
toast.loading("Atualizando prioridade...", { id: "prio" })
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" })
} catch {
setPriority(prev)
@ -64,4 +66,3 @@ export function PrioritySelect({ ticketId, value }: { ticketId: Id<"tickets">; v
</Select>
)
}