**Related issue:** Resolves #38874 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added macOS enrollment details in the “Add hosts” flow, including a clearer choice between **Personal (BYOD)** and **Company-owned** devices. * Shows a copyable macOS enrollment URL when MDM is configured, updating the URL based on the selected device type. * Keeps the macOS setup experience aligned with the enrollment method, including packaging guidance when MDM isn’t enabled. * **Tests** * Added coverage for macOS enrollment URL rendering and device-type switching in the “Add hosts” modal. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
110 lines
3.1 KiB
TypeScript
110 lines
3.1 KiB
TypeScript
import React, { useContext, useState } from "react";
|
|
|
|
import { AppContext } from "context/app";
|
|
import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants";
|
|
import { getPathWithQueryParams } from "utilities/url";
|
|
import CustomLink from "components/CustomLink";
|
|
import Radio from "components/forms/fields/Radio";
|
|
import InputField from "components/forms/fields/InputField";
|
|
|
|
type DeviceType = "companyOwned" | "personalBYOD";
|
|
|
|
const generateInstallerString = (
|
|
serverUrl: string,
|
|
enrollSecret: string,
|
|
scriptsDisabled: boolean
|
|
) => {
|
|
return `fleetctl package --type=pkg ${
|
|
!scriptsDisabled ? "--enable-scripts " : ""
|
|
}--fleet-desktop --fleet-url=${serverUrl} --enroll-secret=${enrollSecret}`;
|
|
};
|
|
|
|
const baseClass = "macos-panel";
|
|
|
|
interface IMacosPanelProps {
|
|
enrollSecret: string;
|
|
}
|
|
|
|
const MacosPanel = ({ enrollSecret }: IMacosPanelProps) => {
|
|
const { config, isMacMdmEnabledAndConfigured } = useContext(AppContext);
|
|
|
|
const [deviceType, setDeviceType] = useState<DeviceType>("companyOwned");
|
|
|
|
if (!config) return null;
|
|
|
|
if (isMacMdmEnabledAndConfigured) {
|
|
const enrollUrl = getPathWithQueryParams(
|
|
`${config.server_settings.server_url}/enroll`,
|
|
{
|
|
enroll_secret: enrollSecret,
|
|
byod: deviceType === "personalBYOD" ? "true" : undefined,
|
|
}
|
|
);
|
|
|
|
return (
|
|
<div className={baseClass}>
|
|
<form>
|
|
<fieldset className="form-field">
|
|
<Radio
|
|
label="Personal (BYOD)"
|
|
id="personal-byod"
|
|
checked={deviceType === "personalBYOD"}
|
|
value="personalBYOD"
|
|
name="device-type"
|
|
onChange={() => setDeviceType("personalBYOD")}
|
|
/>
|
|
<Radio
|
|
label="Company-owned"
|
|
id="company-owned"
|
|
checked={deviceType === "companyOwned"}
|
|
value="companyOwned"
|
|
name="device-type"
|
|
onChange={() => setDeviceType("companyOwned")}
|
|
/>
|
|
</fieldset>
|
|
<InputField
|
|
readOnly
|
|
inputWrapperClass={`${baseClass}__enroll-link`}
|
|
name="enroll-link"
|
|
enableCopy
|
|
label="Send this to your end users:"
|
|
value={enrollUrl}
|
|
/>
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const installerString = generateInstallerString(
|
|
config.server_settings.server_url,
|
|
enrollSecret,
|
|
config.server_settings.scripts_disabled
|
|
);
|
|
|
|
return (
|
|
<div className={baseClass}>
|
|
<InputField
|
|
readOnly
|
|
inputWrapperClass={`${baseClass}__installer-input`}
|
|
name="installer"
|
|
enableCopy
|
|
label={
|
|
<>
|
|
Use this command to generate Fleet's agent.{" "}
|
|
<CustomLink
|
|
url={`${LEARN_MORE_ABOUT_BASE_LINK}/generate-fleets-agent`}
|
|
text="Learn how"
|
|
newTab
|
|
/>
|
|
</>
|
|
}
|
|
type="textarea"
|
|
value={installerString}
|
|
helpText="Run this on your computer, then deploy the generated package to your hosts."
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default MacosPanel;
|