import React, { useState } from "react"; import Modal from "components/Modal"; import Button from "components/buttons/Button"; import Slider from "components/forms/fields/Slider"; // @ts-ignore import InputField from "components/forms/fields/InputField"; import { IWebhookSoftwareVulnerabilities } from "interfaces/webhook"; import { useDeepEffect } from "utilities/hooks"; import { size } from "lodash"; import PreviewPayloadModal from "../PreviewPayloadModal"; interface IManageAutomationsModalProps { onCancel: () => void; onCreateWebhookSubmit: (formData: IWebhookSoftwareVulnerabilities) => void; togglePreviewPayloadModal: () => void; showPreviewPayloadModal: boolean; softwareVulnerabilityWebhookEnabled?: boolean; currentDestinationUrl?: string; } const validateWebhookURL = (url: string) => { const errors: { [key: string]: string } = {}; if (url === "") { errors.url = "Please add a destination URL"; } const valid = !size(errors); return { valid, errors }; }; const baseClass = "manage-automations-modal"; const ManageAutomationsModal = ({ onCancel: onReturnToApp, onCreateWebhookSubmit, togglePreviewPayloadModal, showPreviewPayloadModal, softwareVulnerabilityWebhookEnabled, currentDestinationUrl, }: IManageAutomationsModalProps): JSX.Element => { const [destination_url, setDestinationUrl] = useState( currentDestinationUrl || "" ); const [errors, setErrors] = useState<{ [key: string]: string }>({}); const [ softwareAutomationsEnabled, setSoftwareAutomationsEnabled, ] = useState(softwareVulnerabilityWebhookEnabled || false); useDeepEffect(() => { if (destination_url) { setErrors({}); } }, [destination_url]); const onURLChange = (value: string) => { setDestinationUrl(value); }; const handleSaveAutomation = (evt: React.MouseEvent) => { evt.preventDefault(); const { valid, errors: newErrors } = validateWebhookURL(destination_url); setErrors({ ...errors, ...newErrors, }); // URL validation only needed if software automation is checked if (valid || !softwareAutomationsEnabled) { onCreateWebhookSubmit({ destination_url, enable_vulnerabilities_webhook: softwareAutomationsEnabled, }); onReturnToApp(); } }; if (showPreviewPayloadModal) { return ; } return (
setSoftwareAutomationsEnabled(!softwareAutomationsEnabled) } inactiveText={"Vulnerability automations disabled"} activeText={"Vulnerability automations enabled"} />

A request will be sent to your configured Destination URL{" "} if a detected vulnerability (CVE) was published in the last 2 days.

{!softwareAutomationsEnabled && (
)}
); }; export default ManageAutomationsModal;