2024-04-16 16:22:08 +00:00
|
|
|
import React, { ReactNode, useContext } from "react";
|
2022-07-26 12:05:57 +00:00
|
|
|
import classnames from "classnames";
|
2025-03-10 13:16:43 +00:00
|
|
|
|
2025-01-07 14:18:51 +00:00
|
|
|
import { hasLicenseExpired } from "utilities/helpers";
|
2025-03-10 13:16:43 +00:00
|
|
|
import { AppContext } from "context/app";
|
2022-07-26 12:05:57 +00:00
|
|
|
|
2023-01-16 14:10:12 +00:00
|
|
|
import AppleBMTermsMessage from "components/MDM/AppleBMTermsMessage";
|
2024-05-29 13:41:07 +00:00
|
|
|
import LicenseExpirationBanner from "components/LicenseExpirationBanner";
|
2024-05-29 16:03:05 +00:00
|
|
|
import ApplePNCertRenewalMessage from "components/MDM/ApplePNCertRenewalMessage";
|
|
|
|
|
import AppleBMRenewalMessage from "components/MDM/AppleBMRenewalMessage";
|
2025-03-10 13:16:43 +00:00
|
|
|
import AndroidEnterpriseDeletedMessage from "components/MDM/AndroidEnterpriseDeletedMessage";
|
|
|
|
|
|
2024-07-26 14:39:27 +00:00
|
|
|
import VppRenewalMessage from "./banners/VppRenewalMessage";
|
2022-07-26 12:05:57 +00:00
|
|
|
|
2025-07-23 19:38:11 +00:00
|
|
|
export interface IMainContentConfig {
|
|
|
|
|
renderedBanner: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-26 12:05:57 +00:00
|
|
|
interface IMainContentProps {
|
2025-07-23 19:38:11 +00:00
|
|
|
children: ReactNode | ((mainContentConfig: IMainContentConfig) => ReactNode);
|
2022-07-26 12:05:57 +00:00
|
|
|
/** 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 {
|
|
|
|
|
config,
|
|
|
|
|
isPremiumTier,
|
2025-09-04 12:17:37 +00:00
|
|
|
isAndroidEnterpriseDeleted,
|
2024-08-02 11:52:52 +00:00
|
|
|
isApplePnsExpired,
|
|
|
|
|
isAppleBmExpired,
|
|
|
|
|
isVppExpired,
|
2024-08-29 22:51:46 +00:00
|
|
|
needsAbmTermsRenewal,
|
2024-08-02 11:52:52 +00:00
|
|
|
willAppleBmExpire,
|
|
|
|
|
willApplePnsExpire,
|
|
|
|
|
willVppExpire,
|
2023-03-30 18:22:41 +00:00
|
|
|
} = useContext(AppContext);
|
2023-01-16 14:10:12 +00:00
|
|
|
|
2024-05-29 16:03:05 +00:00
|
|
|
const renderAppWideBanner = () => {
|
|
|
|
|
const isFleetLicenseExpired = hasLicenseExpired(
|
|
|
|
|
config?.license.expiration || ""
|
|
|
|
|
);
|
|
|
|
|
|
2024-07-26 14:39:27 +00:00
|
|
|
let banner: JSX.Element | null = null;
|
2024-05-29 16:03:05 +00:00
|
|
|
|
2025-03-10 13:16:43 +00:00
|
|
|
// the order of these checks is important. This is the priority order
|
|
|
|
|
// for showing banners and only one banner is shown at a time.
|
2026-03-04 13:12:33 +00:00
|
|
|
if (isApplePnsExpired || willApplePnsExpire) {
|
|
|
|
|
// APNs expiration banner will show for either premium or free tiers
|
|
|
|
|
// but all other banners are only for premium tiers
|
|
|
|
|
banner = <ApplePNCertRenewalMessage expired={isApplePnsExpired} />;
|
|
|
|
|
} else if (isPremiumTier) {
|
|
|
|
|
if (isAndroidEnterpriseDeleted) {
|
2025-03-10 13:16:43 +00:00
|
|
|
banner = <AndroidEnterpriseDeletedMessage />;
|
2024-08-02 11:52:52 +00:00
|
|
|
} else if (isAppleBmExpired || willAppleBmExpire) {
|
2024-07-26 14:39:27 +00:00
|
|
|
banner = <AppleBMRenewalMessage expired={isAppleBmExpired} />;
|
2024-08-29 22:51:46 +00:00
|
|
|
} else if (needsAbmTermsRenewal) {
|
2024-07-26 14:39:27 +00:00
|
|
|
banner = <AppleBMTermsMessage />;
|
2024-08-02 11:52:52 +00:00
|
|
|
} else if (isVppExpired || willVppExpire) {
|
2024-07-26 14:39:27 +00:00
|
|
|
banner = <VppRenewalMessage expired={isVppExpired} />;
|
2025-02-19 21:33:46 +00:00
|
|
|
} else if (isFleetLicenseExpired) {
|
2024-08-29 22:51:46 +00:00
|
|
|
banner = <LicenseExpirationBanner />;
|
2024-05-29 16:03:05 +00:00
|
|
|
}
|
2024-07-26 14:39:27 +00:00
|
|
|
}
|
2023-10-27 15:05:19 +00:00
|
|
|
|
2024-07-26 14:39:27 +00:00
|
|
|
if (banner) {
|
2025-01-07 14:18:51 +00:00
|
|
|
return (
|
|
|
|
|
<div className={`${baseClass}--animation-disabled`}>
|
|
|
|
|
<div className={`${baseClass}__warning-banner`}>{banner}</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2024-05-29 16:03:05 +00:00
|
|
|
}
|
2024-05-29 13:41:07 +00:00
|
|
|
|
2024-07-26 14:39:27 +00:00
|
|
|
return null;
|
2024-05-29 16:03:05 +00:00
|
|
|
};
|
2025-07-23 19:38:11 +00:00
|
|
|
|
|
|
|
|
const appWideBanner = renderAppWideBanner();
|
|
|
|
|
const mainContentConfig: IMainContentConfig = {
|
|
|
|
|
renderedBanner: !!appWideBanner,
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-26 12:05:57 +00:00
|
|
|
return (
|
|
|
|
|
<div className={classes}>
|
2025-07-23 19:38:11 +00:00
|
|
|
{appWideBanner}
|
|
|
|
|
{typeof children === "function" ? children(mainContentConfig) : children}
|
2022-07-26 12:05:57 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default MainContent;
|