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