2021-11-15 21:16:06 +00:00
|
|
|
import React from "react";
|
2021-10-15 13:40:42 +00:00
|
|
|
|
2022-07-19 19:28:06 +00:00
|
|
|
import { ITeamSummary } from "interfaces/team";
|
|
|
|
|
import DataError from "components/DataError";
|
2021-11-07 06:41:09 +00:00
|
|
|
import Modal from "components/Modal";
|
2022-07-19 19:28:06 +00:00
|
|
|
import Spinner from "components/Spinner";
|
|
|
|
|
|
2021-10-15 13:40:42 +00:00
|
|
|
import PlatformWrapper from "./PlatformWrapper/PlatformWrapper";
|
2022-07-19 19:28:06 +00:00
|
|
|
import DownloadInstallers from "./DownloadInstallers/DownloadInstallers";
|
2021-10-15 13:40:42 +00:00
|
|
|
|
2022-02-16 21:21:42 +00:00
|
|
|
const baseClass = "add-hosts-modal";
|
2021-10-15 13:40:42 +00:00
|
|
|
|
2022-02-16 21:21:42 +00:00
|
|
|
interface IAddHostsModal {
|
2022-07-19 19:28:06 +00:00
|
|
|
currentTeam?: ITeamSummary;
|
|
|
|
|
enrollSecret?: string;
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
isSandboxMode?: boolean;
|
2021-10-15 13:40:42 +00:00
|
|
|
onCancel: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 21:21:42 +00:00
|
|
|
const AddHostsModal = ({
|
2022-07-19 19:28:06 +00:00
|
|
|
currentTeam,
|
|
|
|
|
enrollSecret,
|
|
|
|
|
isLoading,
|
|
|
|
|
isSandboxMode,
|
2021-10-15 13:40:42 +00:00
|
|
|
onCancel,
|
2022-02-16 21:21:42 +00:00
|
|
|
}: IAddHostsModal): JSX.Element => {
|
2022-07-19 19:28:06 +00:00
|
|
|
const renderModalContent = () => {
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return <Spinner />;
|
|
|
|
|
}
|
|
|
|
|
if (!enrollSecret) {
|
|
|
|
|
return <DataError />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Currently, prepacked installers in Fleet Sandbox use the global enroll secret,
|
|
|
|
|
// and Fleet Sandbox runs Fleet Free so the currentTeam check here is an
|
|
|
|
|
// additional precaution/reminder to revisit this in connection with future changes.
|
|
|
|
|
// See https://github.com/fleetdm/fleet/issues/4970#issuecomment-1187679407.
|
|
|
|
|
return isSandboxMode && !currentTeam ? (
|
|
|
|
|
<DownloadInstallers onCancel={onCancel} enrollSecret={enrollSecret} />
|
|
|
|
|
) : (
|
|
|
|
|
<PlatformWrapper onCancel={onCancel} enrollSecret={enrollSecret} />
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-15 13:40:42 +00:00
|
|
|
return (
|
2022-02-16 21:21:42 +00:00
|
|
|
<Modal onExit={onCancel} title={"Add hosts"} className={baseClass}>
|
2022-07-19 19:28:06 +00:00
|
|
|
{renderModalContent()}
|
2021-10-15 13:40:42 +00:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-16 21:21:42 +00:00
|
|
|
export default AddHostsModal;
|