Skip to content

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

1.6 KB
Raw Blame
import { createNotification } from "@app/components/notifications";
import { Alert, AlertDescription, ConfirmationAlertDialog } from "@app/components/v3";
import { SECRET_SCANNING_DATA_SOURCE_MAP } from "@app/helpers/secretScanningV2";
import {
  TSecretScanningDataSource,
  useDeleteSecretScanningDataSource
} from "@app/hooks/api/secretScanningV2";

type Props = {
  dataSource?: TSecretScanningDataSource;
  isOpen: boolean;
  onOpenChange: (isOpen: boolean) => void;
  onComplete?: () => void;
};

export const DeleteSecretScanningDataSourceModal = ({
  isOpen,
  onOpenChange,
  dataSource,
  onComplete
}: Props) => {
  const deleteDataSource = useDeleteSecretScanningDataSource();

  if (!dataSource) return null;

  const { id: dataSourceId, name, type, projectId } = dataSource;

  const handleDeleteDataSource = async () => {
    const dataSourceType = SECRET_SCANNING_DATA_SOURCE_MAP[type].name;

    await deleteDataSource.mutateAsync({
      dataSourceId,
      type,
      projectId
    });

    createNotification({
      text: `Successfully deleted ${dataSourceType} Data Source`,
      type: "success"
    });

    if (onComplete) onComplete();
    onOpenChange(false);
  };

  return (
    <ConfirmationAlertDialog
      isOpen={isOpen}
      onOpenChange={onOpenChange}
      title={`Delete ${name}?`}
      description={
        <Alert variant="danger" appearance="borderless">
          <AlertDescription>
            This permanently deletes the findings and scan history of this data source. This cannot
            be undone.
          </AlertDescription>
        </Alert>
      }
      confirmKey={name}
      onConfirm={handleDeleteDataSource}
    />
  );
};