2024-05-13 17:36:17 +00:00
|
|
|
|
import React, { useCallback, useContext } from "react";
|
2024-05-09 13:06:58 +00:00
|
|
|
|
|
|
|
|
|
|
import softwareAPI from "services/entities/software";
|
|
|
|
|
|
import { NotificationContext } from "context/notification";
|
|
|
|
|
|
|
2024-09-03 22:35:33 +00:00
|
|
|
|
import { getErrorReason } from "interfaces/errors";
|
|
|
|
|
|
|
2024-05-09 13:06:58 +00:00
|
|
|
|
import Modal from "components/Modal";
|
|
|
|
|
|
import Button from "components/buttons/Button";
|
|
|
|
|
|
|
|
|
|
|
|
const baseClass = "delete-software-modal";
|
|
|
|
|
|
|
2024-09-03 22:35:33 +00:00
|
|
|
|
const DELETE_SW_USED_BY_POLICY_ERROR_MSG =
|
|
|
|
|
|
"Couldn't delete. Policy automation uses this software. Please disable policy automation for this software and try again.";
|
2024-10-16 12:26:23 +00:00
|
|
|
|
const DELETE_SW_INSTALLED_DURING_SETUP_ERROR_MSG =
|
|
|
|
|
|
"Couldn't delete. This software is installed when new Macs boot. Please remove software in Controls > Setup experience and try again.";
|
|
|
|
|
|
|
2024-05-09 13:06:58 +00:00
|
|
|
|
interface IDeleteSoftwareModalProps {
|
|
|
|
|
|
softwareId: number;
|
2024-05-10 17:47:59 +00:00
|
|
|
|
teamId: number;
|
2024-10-31 23:04:06 +00:00
|
|
|
|
softwarePackageName?: string;
|
2024-05-09 13:06:58 +00:00
|
|
|
|
onExit: () => void;
|
2024-05-13 17:36:17 +00:00
|
|
|
|
onSuccess: () => void;
|
2024-05-09 13:06:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const DeleteSoftwareModal = ({
|
|
|
|
|
|
softwareId,
|
2024-05-10 17:47:59 +00:00
|
|
|
|
teamId,
|
2024-10-31 23:04:06 +00:00
|
|
|
|
softwarePackageName,
|
2024-05-09 13:06:58 +00:00
|
|
|
|
onExit,
|
2024-05-13 17:36:17 +00:00
|
|
|
|
onSuccess,
|
2024-05-09 13:06:58 +00:00
|
|
|
|
}: IDeleteSoftwareModalProps) => {
|
|
|
|
|
|
const { renderFlash } = useContext(NotificationContext);
|
|
|
|
|
|
|
2024-05-13 17:36:17 +00:00
|
|
|
|
const onDeleteSoftware = useCallback(async () => {
|
2024-05-09 13:06:58 +00:00
|
|
|
|
try {
|
2024-05-10 17:47:59 +00:00
|
|
|
|
await softwareAPI.deleteSoftwarePackage(softwareId, teamId);
|
2024-05-09 13:06:58 +00:00
|
|
|
|
renderFlash("success", "Software deleted successfully!");
|
2024-05-13 17:36:17 +00:00
|
|
|
|
onSuccess();
|
2024-09-03 22:35:33 +00:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
const reason = getErrorReason(error);
|
|
|
|
|
|
if (reason.includes("Policy automation uses this software")) {
|
|
|
|
|
|
renderFlash("error", DELETE_SW_USED_BY_POLICY_ERROR_MSG);
|
2024-10-16 12:26:23 +00:00
|
|
|
|
} else if (reason.includes("This software is installed when")) {
|
|
|
|
|
|
renderFlash("error", DELETE_SW_INSTALLED_DURING_SETUP_ERROR_MSG);
|
2024-09-03 22:35:33 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
renderFlash("error", "Couldn't delete. Please try again.");
|
|
|
|
|
|
}
|
2024-05-09 13:06:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
onExit();
|
2024-05-13 17:36:17 +00:00
|
|
|
|
}, [softwareId, teamId, renderFlash, onSuccess, onExit]);
|
2024-05-09 13:06:58 +00:00
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Modal className={baseClass} title="Delete software" onExit={onExit}>
|
|
|
|
|
|
<>
|
2024-10-31 23:04:06 +00:00
|
|
|
|
<p>
|
|
|
|
|
|
Software won't be uninstalled from existing hosts, but any
|
|
|
|
|
|
pending pending installs and uninstalls{" "}
|
|
|
|
|
|
{softwarePackageName ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
for <b> {softwarePackageName}</b>{" "}
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
""
|
|
|
|
|
|
)}
|
|
|
|
|
|
will be canceled.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
Installs or uninstalls currently running on a host will still
|
|
|
|
|
|
complete, but results won’t appear in Fleet.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p>You cannot undo this action.</p>
|
2024-05-09 13:06:58 +00:00
|
|
|
|
<div className="modal-cta-wrap">
|
|
|
|
|
|
<Button variant="alert" onClick={onDeleteSoftware}>
|
|
|
|
|
|
Delete
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button variant="inverse-alert" onClick={onExit}>
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default DeleteSoftwareModal;
|