2023-06-08 15:15:31 +00:00
|
|
|
import React, { useContext } from "react";
|
|
|
|
|
import { useQuery } from "react-query";
|
|
|
|
|
import configAPI from "services/entities/config";
|
|
|
|
|
import { AppContext } from "context/app";
|
2021-10-15 13:40:42 +00:00
|
|
|
|
2022-11-08 15:06:58 +00:00
|
|
|
import Button from "components/buttons/Button";
|
2022-07-19 19:28:06 +00:00
|
|
|
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-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 {
|
2023-03-31 17:40:14 +00:00
|
|
|
currentTeamName?: string;
|
2022-07-19 19:28:06 +00:00
|
|
|
enrollSecret?: string;
|
2023-03-31 17:40:14 +00:00
|
|
|
isAnyTeamSelected: boolean;
|
2022-07-19 19:28:06 +00:00
|
|
|
isLoading: boolean;
|
2021-10-15 13:40:42 +00:00
|
|
|
onCancel: () => void;
|
2022-11-08 15:06:58 +00:00
|
|
|
openEnrollSecretModal?: () => void;
|
2021-10-15 13:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 21:21:42 +00:00
|
|
|
const AddHostsModal = ({
|
2023-03-31 17:40:14 +00:00
|
|
|
currentTeamName,
|
2022-07-19 19:28:06 +00:00
|
|
|
enrollSecret,
|
2023-03-31 17:40:14 +00:00
|
|
|
isAnyTeamSelected,
|
2022-07-19 19:28:06 +00:00
|
|
|
isLoading,
|
2021-10-15 13:40:42 +00:00
|
|
|
onCancel,
|
2022-11-08 15:06:58 +00:00
|
|
|
openEnrollSecretModal,
|
2022-02-16 21:21:42 +00:00
|
|
|
}: IAddHostsModal): JSX.Element => {
|
2023-06-08 15:15:31 +00:00
|
|
|
const { isPreviewMode, config } = useContext(AppContext);
|
2023-03-31 17:40:14 +00:00
|
|
|
const teamDisplayName = (isAnyTeamSelected && currentTeamName) || "Fleet";
|
|
|
|
|
|
2023-06-08 15:15:31 +00:00
|
|
|
const {
|
|
|
|
|
data: certificate,
|
|
|
|
|
error: fetchCertificateError,
|
|
|
|
|
isFetching: isFetchingCertificate,
|
2024-04-03 16:25:16 +00:00
|
|
|
} = useQuery<string, Error>(
|
2023-06-08 15:15:31 +00:00
|
|
|
["certificate"],
|
|
|
|
|
() => configAPI.loadCertificate(),
|
|
|
|
|
{
|
|
|
|
|
enabled: !isPreviewMode,
|
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2022-11-08 15:06:58 +00:00
|
|
|
const onManageEnrollSecretsClick = () => {
|
|
|
|
|
onCancel();
|
|
|
|
|
openEnrollSecretModal && openEnrollSecretModal();
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-19 19:28:06 +00:00
|
|
|
const renderModalContent = () => {
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return <Spinner />;
|
|
|
|
|
}
|
|
|
|
|
if (!enrollSecret) {
|
2022-11-08 15:06:58 +00:00
|
|
|
return (
|
|
|
|
|
<DataError>
|
|
|
|
|
<span className="info__data">
|
|
|
|
|
You have no enroll secrets.{" "}
|
|
|
|
|
{openEnrollSecretModal ? (
|
2025-09-29 17:10:41 +00:00
|
|
|
<Button onClick={onManageEnrollSecretsClick} variant="inverse">
|
2022-11-08 15:06:58 +00:00
|
|
|
Manage enroll secrets
|
|
|
|
|
</Button>
|
|
|
|
|
) : (
|
|
|
|
|
"Manage enroll secrets"
|
|
|
|
|
)}{" "}
|
2023-03-31 17:40:14 +00:00
|
|
|
to enroll hosts to <b>{teamDisplayName}</b>.
|
2022-11-08 15:06:58 +00:00
|
|
|
</span>
|
|
|
|
|
</DataError>
|
|
|
|
|
);
|
2022-07-19 19:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-09 13:18:00 +00:00
|
|
|
return (
|
2023-06-08 15:15:31 +00:00
|
|
|
<PlatformWrapper
|
|
|
|
|
onCancel={onCancel}
|
|
|
|
|
enrollSecret={enrollSecret}
|
|
|
|
|
certificate={certificate}
|
|
|
|
|
isFetchingCertificate={isFetchingCertificate}
|
|
|
|
|
fetchCertificateError={fetchCertificateError}
|
|
|
|
|
config={config}
|
|
|
|
|
/>
|
2022-07-19 19:28:06 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-15 13:40:42 +00:00
|
|
|
return (
|
2023-05-30 20:47:29 +00:00
|
|
|
<Modal
|
|
|
|
|
onExit={onCancel}
|
2024-02-23 14:57:18 +00:00
|
|
|
title="Add hosts"
|
2023-05-30 20:47:29 +00:00
|
|
|
className={baseClass}
|
2023-05-30 23:17:14 +00:00
|
|
|
width="large"
|
2023-05-30 20:47:29 +00:00
|
|
|
>
|
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;
|