import React, { useContext, useState } from "react"; import Modal from "components/Modal"; import Button from "components/buttons/Button"; import TooltipTruncatedText from "components/TooltipTruncatedText"; import { ISecret } from "interfaces/secrets"; import { NotificationContext } from "context/notification"; import formatErrorResponse from "utilities/format_error_response"; import secretsAPI from "services/entities/secrets"; interface DeleteCustomVariableModalProps { secret: ISecret | undefined; onExit: () => void; onDeleteSecret: () => void; } const baseClass = "delete-custom-variable-modal"; const DeleteCustomVariableModal = ({ secret, onExit, onDeleteSecret, }: DeleteCustomVariableModalProps) => { const [isDeleting, setIsDeleting] = useState(false); const { renderFlash } = useContext(NotificationContext); const onClickDelete = async () => { if (!secret) { return; } setIsDeleting(true); try { await secretsAPI.deleteSecret(secret.id); renderFlash("success", "Variable successfully deleted."); onDeleteSecret(); } catch (error) { const errorObject = formatErrorResponse(error); const isInUseError = errorObject.http_status === 409 && /used by/.test(errorObject?.base ?? ""); const message = isInUseError && typeof errorObject?.base === "string" ? errorObject.base : "An error occurred while deleting the custom variable. Please try again."; renderFlash("error", message); onExit(); } finally { setIsDeleting(false); } }; return (
This will delete the custom variable.

If this custom variable is used in any configuration profiles or scripts, they will fail. To resolve, edit the configuration profile or script.
); }; export default DeleteCustomVariableModal;