"use client" import * as React from "react" import { type Row } from "@tanstack/react-table" import { Loader, Trash } from "lucide-react" import { toast } from "sonner" import { useMediaQuery } from "@/hooks/use-media-query" import { Button } from "@/components/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@/components/ui/drawer" import { VendorCandidates } from "@/db/schema/vendors" import { removeCandidates } from "../service" interface DeleteCandidatesDialogProps extends React.ComponentPropsWithoutRef { candidates: Row["original"][] showTrigger?: boolean onSuccess?: () => void } export function DeleteCandidatesDialog({ candidates, showTrigger = true, onSuccess, ...props }: DeleteCandidatesDialogProps) { const [isDeletePending, startDeleteTransition] = React.useTransition() const isDesktop = useMediaQuery("(min-width: 640px)") function onDelete() { startDeleteTransition(async () => { const { error } = await removeCandidates({ ids: candidates.map((candidate) => candidate.id), }) if (error) { toast.error(error) return } props.onOpenChange?.(false) toast.success("Candidates deleted") onSuccess?.() }) } if (isDesktop) { return ( {showTrigger ? ( ) : null} Are you absolutely sure? This action cannot be undone. This will permanently delete your{" "} {candidates.length} {candidates.length === 1 ? " candidate" : " candidates"} from our servers. ) } return ( {showTrigger ? ( ) : null} Are you absolutely sure? This action cannot be undone. This will permanently delete your{" "} {candidates.length} {candidates.length === 1 ? " candidate" : " candidates"} from our servers. ) }