import { useState } from "react"; import { Button } from "@/src/components/ui/button"; import { Trash } from "lucide-react"; import { api } from "@/src/utils/api"; import { showSuccessToast } from "@/src/features/notifications/showSuccessToast"; import { Popover, PopoverContent, PopoverTrigger, } from "@/src/components/ui/popover"; import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess"; interface DeleteAutomationButtonProps { projectId: string; automationId: string; onSuccess?: () => void; variant?: "icon" | "button"; // "icon" for list view, "button" for form view } export const DeleteAutomationButton: React.FC = ({ projectId, automationId, onSuccess, variant = "icon", }) => { const [isOpen, setIsOpen] = useState(false); const utils = api.useUtils(); const hasAccess = useHasProjectAccess({ projectId, scope: "automations:CUD", }); const deleteAutomationMutation = api.automations.deleteAutomation.useMutation( { onSuccess: () => { showSuccessToast({ title: "Automation deleted", description: "The automation has been deleted successfully.", }); if (onSuccess) { onSuccess(); } void utils.automations.invalidate(); }, }, ); return ( setIsOpen(!isOpen)}> {variant === "icon" ? ( ) : ( )}

Please confirm

This action permanently deletes this automation and execution history. This cannot be undone.

); };