"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 { removeTemplates } from "../service" import { BasicContractTemplate } from "@/db/schema" interface DeleteBasicContractsDialogProps extends React.ComponentPropsWithoutRef { templates: Row["original"][] showTrigger?: boolean onSuccess?: () => void } export function DeleteTemplatesDialog({ templates, showTrigger = true, onSuccess, ...props }: DeleteBasicContractsDialogProps) { const [isDeletePending, startDeleteTransition] = React.useTransition() const isDesktop = useMediaQuery("(min-width: 640px)") function onDelete() { startDeleteTransition(async () => { const { error } = await removeTemplates({ ids: templates.map((template) => template.id), }) if (error) { toast.error(error) return } props.onOpenChange?.(false) toast.success("Templates deleted") onSuccess?.() }) } if (isDesktop) { return ( {showTrigger ? ( ) : null} Are you absolutely sure? This action cannot be undone. This will permanently delete your{" "} {templates.length} {templates.length === 1 ? " template" : " templates"} from our servers. ) } return ( {showTrigger ? ( ) : null} Are you absolutely sure? This action cannot be undone. This will permanently delete your{" "} {templates.length} {templates.length === 1 ? " template" : " templates"} from our servers. ) }