mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
For unreleased bug #23350, introduced because we're no longer cascade-deleting _all_ related installs (related to #22996, #21654, #22087) # Checklist for submitter - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated tests - [x] Manual QA for all new/changed functionality
86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
import React, { useCallback, useContext } from "react";
|
||
|
||
import softwareAPI from "services/entities/software";
|
||
import { NotificationContext } from "context/notification";
|
||
|
||
import { getErrorReason } from "interfaces/errors";
|
||
|
||
import Modal from "components/Modal";
|
||
import Button from "components/buttons/Button";
|
||
|
||
const baseClass = "delete-software-modal";
|
||
|
||
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.";
|
||
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.";
|
||
|
||
interface IDeleteSoftwareModalProps {
|
||
softwareId: number;
|
||
teamId: number;
|
||
softwarePackageName?: string;
|
||
onExit: () => void;
|
||
onSuccess: () => void;
|
||
}
|
||
|
||
const DeleteSoftwareModal = ({
|
||
softwareId,
|
||
teamId,
|
||
softwarePackageName,
|
||
onExit,
|
||
onSuccess,
|
||
}: IDeleteSoftwareModalProps) => {
|
||
const { renderFlash } = useContext(NotificationContext);
|
||
|
||
const onDeleteSoftware = useCallback(async () => {
|
||
try {
|
||
await softwareAPI.deleteSoftwarePackage(softwareId, teamId);
|
||
renderFlash("success", "Software deleted successfully!");
|
||
onSuccess();
|
||
} catch (error) {
|
||
const reason = getErrorReason(error);
|
||
if (reason.includes("Policy automation uses this software")) {
|
||
renderFlash("error", DELETE_SW_USED_BY_POLICY_ERROR_MSG);
|
||
} else if (reason.includes("This software is installed when")) {
|
||
renderFlash("error", DELETE_SW_INSTALLED_DURING_SETUP_ERROR_MSG);
|
||
} else {
|
||
renderFlash("error", "Couldn't delete. Please try again.");
|
||
}
|
||
}
|
||
onExit();
|
||
}, [softwareId, teamId, renderFlash, onSuccess, onExit]);
|
||
|
||
return (
|
||
<Modal className={baseClass} title="Delete software" onExit={onExit}>
|
||
<>
|
||
<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>
|
||
<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;
|