2022-07-26 12:05:57 +00:00
|
|
|
import React, { ReactChild, useContext } from "react";
|
|
|
|
|
import classnames from "classnames";
|
|
|
|
|
import { formatDistanceToNow } from "date-fns";
|
|
|
|
|
|
|
|
|
|
import SandboxExpiryMessage from "components/Sandbox/SandboxExpiryMessage";
|
2023-01-16 14:10:12 +00:00
|
|
|
import AppleBMTermsMessage from "components/MDM/AppleBMTermsMessage";
|
|
|
|
|
|
2022-07-26 12:05:57 +00:00
|
|
|
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);
|
2023-03-30 18:22:41 +00:00
|
|
|
const {
|
|
|
|
|
sandboxExpiry,
|
|
|
|
|
config,
|
|
|
|
|
isSandboxMode,
|
|
|
|
|
isPremiumTier,
|
|
|
|
|
noSandboxHosts,
|
|
|
|
|
} = useContext(AppContext);
|
2023-01-16 14:10:12 +00:00
|
|
|
|
|
|
|
|
const isAppleBmTermsExpired = config?.mdm?.apple_bm_terms_expired;
|
2022-07-26 12:05:57 +00:00
|
|
|
|
2023-01-16 14:10:12 +00:00
|
|
|
const sandboxExpiryTime =
|
2022-07-26 12:05:57 +00:00
|
|
|
sandboxExpiry === undefined
|
|
|
|
|
? "..."
|
|
|
|
|
: formatDistanceToNow(new Date(sandboxExpiry));
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={classes}>
|
2023-01-16 14:10:12 +00:00
|
|
|
{isAppleBmTermsExpired && isPremiumTier && !isSandboxMode && (
|
|
|
|
|
<AppleBMTermsMessage />
|
|
|
|
|
)}
|
2022-07-26 12:05:57 +00:00
|
|
|
<SandboxGate
|
2023-01-16 14:10:12 +00:00
|
|
|
fallbackComponent={() => (
|
2023-03-30 18:22:41 +00:00
|
|
|
<SandboxExpiryMessage
|
|
|
|
|
expiry={sandboxExpiryTime}
|
|
|
|
|
noSandboxHosts={noSandboxHosts}
|
|
|
|
|
/>
|
2023-01-16 14:10:12 +00:00
|
|
|
)}
|
2022-07-26 12:05:57 +00:00
|
|
|
/>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default MainContent;
|