fleet/frontend/pages/ManageControlsPage/Scripts/components/DeleteScriptModal/DeleteScriptModal.tsx
2023-10-17 17:35:25 -04:00

67 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useContext } from "react";
import scriptAPI from "services/entities/scripts";
import { NotificationContext } from "context/notification";
import Modal from "components/Modal";
import Button from "components/buttons/Button";
const baseClass = "delete-script-modal";
interface IDeleteScriptModalProps {
scriptName: string;
scriptId: number;
onCancel: () => void;
onDone: () => void;
}
const DeleteScriptModal = ({
scriptName,
scriptId,
onCancel,
onDone,
}: IDeleteScriptModalProps) => {
const { renderFlash } = useContext(NotificationContext);
const onClickDelete = async (id: number) => {
try {
await scriptAPI.deleteScript(id);
renderFlash("success", "Successfully deleted!");
} catch {
renderFlash("error", "Couldnt delete. Please try again.");
}
onDone();
};
return (
<Modal
className={baseClass}
title={"Delete script"}
onExit={onCancel}
onEnter={() => onClickDelete(scriptId)}
>
<>
<p>
This action will cancel script{" "}
<span className={`${baseClass}__script-name`}>{scriptName}</span> from
running on macOS hosts on which the script hasn&apos;t run yet.
</p>
<div className="modal-cta-wrap">
<Button
type="button"
onClick={() => onClickDelete(scriptId)}
variant="alert"
className="delete-loading"
>
Delete
</Button>
<Button onClick={onCancel} variant="inverse-alert">
Cancel
</Button>
</div>
</>
</Modal>
);
};
export default DeleteScriptModal;