fleet/frontend/components/AddHostsModal/AddHostsModal.tsx
Gabriel Hernandez 35c172dcfd
add ability for end users to enrol their device into fleet mdm (#21751)
relates to #21559

This adds the ability for end users to enrol their own device in fleet
mdm.

> NOTE: this new byod HTML page is a separate HTML asset that contains
all styles and scripts needed for the page to work. We do not send the
fleet UI assets and this drastically cuts down the response time to the
users who will be visiting this page on mobile devices

There are two sides included in this:

**Adding a new add host modal ios and iPad section for IT admins**


![image](https://github.com/user-attachments/assets/1008b190-9c38-4a0e-9b02-19df5da7937d)

**delivering a new byod HTML page to end users that will allow end users
to download the config profile to enrol into fleet mdm**


![image](https://github.com/user-attachments/assets/58d790e4-233b-4b03-ab36-9971aac075de)

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [ ] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-09-05 12:47:34 +01:00

99 lines
2.4 KiB
TypeScript

import React, { useContext } from "react";
import { useQuery } from "react-query";
import configAPI from "services/entities/config";
import { AppContext } from "context/app";
import Button from "components/buttons/Button";
import DataError from "components/DataError";
import Modal from "components/Modal";
import Spinner from "components/Spinner";
import PlatformWrapper from "./PlatformWrapper/PlatformWrapper";
const baseClass = "add-hosts-modal";
interface IAddHostsModal {
currentTeamName?: string;
enrollSecret?: string;
isAnyTeamSelected: boolean;
isLoading: boolean;
onCancel: () => void;
openEnrollSecretModal?: () => void;
}
const AddHostsModal = ({
currentTeamName,
enrollSecret,
isAnyTeamSelected,
isLoading,
onCancel,
openEnrollSecretModal,
}: IAddHostsModal): JSX.Element => {
const { isPreviewMode, config } = useContext(AppContext);
const teamDisplayName = (isAnyTeamSelected && currentTeamName) || "Fleet";
const {
data: certificate,
error: fetchCertificateError,
isFetching: isFetchingCertificate,
} = useQuery<string, Error>(
["certificate"],
() => configAPI.loadCertificate(),
{
enabled: !isPreviewMode,
refetchOnWindowFocus: false,
}
);
const onManageEnrollSecretsClick = () => {
onCancel();
openEnrollSecretModal && openEnrollSecretModal();
};
const renderModalContent = () => {
if (isLoading) {
return <Spinner />;
}
if (!enrollSecret) {
return (
<DataError>
<span className="info__data">
You have no enroll secrets.{" "}
{openEnrollSecretModal ? (
<Button onClick={onManageEnrollSecretsClick} variant="text-link">
Manage enroll secrets
</Button>
) : (
"Manage enroll secrets"
)}{" "}
to enroll hosts to <b>{teamDisplayName}</b>.
</span>
</DataError>
);
}
return (
<PlatformWrapper
onCancel={onCancel}
enrollSecret={enrollSecret}
certificate={certificate}
isFetchingCertificate={isFetchingCertificate}
fetchCertificateError={fetchCertificateError}
config={config}
/>
);
};
return (
<Modal
onExit={onCancel}
title="Add hosts"
className={baseClass}
width="large"
>
{renderModalContent()}
</Modal>
);
};
export default AddHostsModal;