fleet/frontend/components/MainContent/MainContent.tsx
Gabriel Hernandez 4d7410d7ae
Fixs multiple banners on host details page when we only want to show ABM expired banner (#14772)
relates to #13010

This fixes the issue where we only want the user to see the ABM banner
on the Host Details page.

We've pulled out the rendering logic of the banners into its own
component and suppress the other banners if the ABM expired banner is
already showing.

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Manual QA for all new/changed functionality
2023-10-27 16:05:19 +01:00

64 lines
1.6 KiB
TypeScript

import React, { ReactChild, useContext } from "react";
import classnames from "classnames";
import { formatDistanceToNow } from "date-fns";
import SandboxExpiryMessage from "components/Sandbox/SandboxExpiryMessage";
import AppleBMTermsMessage from "components/MDM/AppleBMTermsMessage";
import SandboxGate from "components/Sandbox/SandboxGate";
import { AppContext } from "context/app";
interface IMainContentProps {
children: ReactChild;
/** An optional classname to pass to the main content component.
* This can be used to apply styles directly onto the main content div
*/
className?: string;
}
const baseClass = "main-content";
/**
* A component that controls the layout and styling of the main content region
* of the application.
*/
const MainContent = ({
children,
className,
}: IMainContentProps): JSX.Element => {
const classes = classnames(baseClass, className);
const {
sandboxExpiry,
config,
isSandboxMode,
isPremiumTier,
noSandboxHosts,
} = useContext(AppContext);
const isAppleBmTermsExpired = config?.mdm?.apple_bm_terms_expired;
const sandboxExpiryTime =
sandboxExpiry === undefined
? "..."
: formatDistanceToNow(new Date(sandboxExpiry));
const showAppleABMBanner =
isAppleBmTermsExpired && isPremiumTier && !isSandboxMode;
return (
<div className={classes}>
{showAppleABMBanner && <AppleBMTermsMessage />}
<SandboxGate
fallbackComponent={() => (
<SandboxExpiryMessage
expiry={sandboxExpiryTime}
noSandboxHosts={noSandboxHosts}
/>
)}
/>
{children}
</div>
);
};
export default MainContent;