Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

1.4 KB
Raw Blame
import { createNotification } from "@app/components/notifications";
import { ConfirmationAlertDialog } from "@app/components/v3";
import { useDeleteAgentVaultAccessBundle } from "@app/hooks/api/agentVault";
import { TAgentVaultAccessBundle } from "@app/hooks/api/agentVault/types";

type Props = {
  accessBundle: TAgentVaultAccessBundle | null;
  onOpenChange: (isOpen: boolean) => void;
  onDeleted?: () => void;
};

export const DeleteAccessBundleDialog = ({ accessBundle, onOpenChange, onDeleted }: Props) => {
  const deleteAccessBundle = useDeleteAgentVaultAccessBundle();

  const handleDelete = async () => {
    try {
      if (!accessBundle) return;

      await deleteAccessBundle.mutateAsync(accessBundle.id);
      createNotification({ text: `Access bundle "${accessBundle.name}" deleted`, type: "success" });
      onOpenChange(false);
      onDeleted?.();
    } catch {
      // A failed request returns a 4xx that the global request handler surfaces as a toast
    }
  };

  return (
    <ConfirmationAlertDialog
      isOpen={Boolean(accessBundle)}
      onOpenChange={onOpenChange}
      title={`Delete "${accessBundle?.name}"`}
      description="Its services and access grants are deleted with it. Any active session associated with this bundle loses access at the next proxy poll. This cannot be undone."
      confirmKey={accessBundle?.name ?? ""}
      isPending={deleteAccessBundle.isPending}
      onConfirm={handleDelete}
    />
  );
};