fleet/frontend/pages/ManageControlsPage/SetupExperience/cards/EndUserAuthentication/EndUserAuthentication.tsx
Gabriel Hernandez 489035ef2b
Various setup exp UI fixes (#23328)
relates to #23321, #23322, #23323

This contains three UI fixes:

1. fix when we show the empty state for install software. We were
expecting an empty array but the response from `GET
/setup_experience/software` sends null when no software has been added


![image](https://github.com/user-attachments/assets/0300fffa-5586-4073-a6df-491e844516c9)

2. fix to add responsive style to install software and run script panels
that matches the other setup experience panels.


![image](https://github.com/user-attachments/assets/5494146f-583d-4816-9c1b-6227bb520108)


![image](https://github.com/user-attachments/assets/a2e3c43d-64bf-4695-9870-029482080172)

3. Fix and clean up the copy of the first three setup experience panels
to match the new ones. Also, update the alt text on the images to be
more descriptive.

- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-10-29 14:29:05 +00:00

105 lines
3 KiB
TypeScript

import React from "react";
import { InjectedRouter } from "react-router";
import PATHS from "router/paths";
import { useQuery } from "react-query";
import configAPI from "services/entities/config";
import teamsAPI, { ILoadTeamResponse } from "services/entities/teams";
import { IConfig, IMdmConfig } from "interfaces/config";
import { ITeamConfig } from "interfaces/team";
import SectionHeader from "components/SectionHeader/SectionHeader";
import Spinner from "components/Spinner";
import RequireEndUserAuth from "./components/RequireEndUserAuth/RequireEndUserAuth";
import EndUserAuthForm from "./components/EndUserAuthForm/EndUserAuthForm";
import EndUserExperiencePreview from "./components/EndUserExperiencePreview";
const baseClass = "end-user-authentication";
const getEnabledEndUserAuth = (
currentTeamId: number,
globalConfig?: IConfig,
teamConfig?: ITeamConfig
) => {
if (globalConfig === undefined && teamConfig === undefined) {
return false;
}
// team is "No team" when currentTeamId === 0
if (currentTeamId === 0) {
return (
globalConfig?.mdm?.macos_setup.enable_end_user_authentication ?? false
);
}
return teamConfig?.mdm?.macos_setup.enable_end_user_authentication ?? false;
};
const isIdPConfigured = ({
end_user_authentication: idp,
}: Pick<IMdmConfig, "end_user_authentication">) => {
return !!idp.entity_id && !!idp.metadata_url && !!idp.idp_name;
};
interface IEndUserAuthenticationProps {
currentTeamId: number;
router: InjectedRouter;
}
const EndUserAuthentication = ({
currentTeamId,
router,
}: IEndUserAuthenticationProps) => {
const { data: globalConfig, isLoading: isLoadingGlobalConfig } = useQuery<
IConfig,
Error
>(["config", currentTeamId], () => configAPI.loadAll(), {
refetchOnWindowFocus: false,
retry: false,
});
const { data: teamConfig, isLoading: isLoadingTeamConfig } = useQuery<
ILoadTeamResponse,
Error,
ITeamConfig
>(["team", currentTeamId], () => teamsAPI.load(currentTeamId), {
refetchOnWindowFocus: false,
retry: false,
enabled: currentTeamId !== 0,
select: (res) => res.team,
});
const defaultIsEndUserAuthEnabled = getEnabledEndUserAuth(
currentTeamId,
globalConfig,
teamConfig
);
const onClickConnect = () => {
router.push(PATHS.ADMIN_INTEGRATIONS_MDM);
};
return (
<div className={baseClass}>
<SectionHeader title="End user authentication" />
{isLoadingGlobalConfig || isLoadingTeamConfig ? (
<Spinner />
) : (
<div className={`${baseClass}__content`}>
{!globalConfig || !isIdPConfigured(globalConfig.mdm) ? (
<RequireEndUserAuth onClickConnect={onClickConnect} />
) : (
<EndUserAuthForm
currentTeamId={currentTeamId}
defaultIsEndUserAuthEnabled={defaultIsEndUserAuthEnabled}
/>
)}
<EndUserExperiencePreview />
</div>
)}
</div>
);
};
export default EndUserAuthentication;