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>
)
}