import DOMPurify from "dompurify"; import { useSession } from "next-auth/react"; import React, { AriaRole, ComponentType, Fragment } from "react"; import { APP_NAME, CONSOLE_URL, SUPPORT_MAIL_ADDRESS } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { EmptyScreen, Icon } from "@calcom/ui"; type LicenseRequiredProps = { as?: keyof JSX.IntrinsicElements | ""; className?: string; role?: AriaRole | undefined; children: React.ReactNode; toHide?: boolean; // if true, the component will be hidden instead of showing the empty screen }; /** * This component will only render it's children if the installation has a valid * license. * @param toHide - will hide the component with a license instead of showing the empty screen */ const LicenseRequired = ({ children, as = "", toHide = false, ...rest }: LicenseRequiredProps) => { const session = useSession(); const { t } = useLocale(); const Component = as || Fragment; const hasValidLicense = session.data ? session.data.hasValidLicense : null; return ( {hasValidLicense === null || hasValidLicense ? ( !toHide && children ) : toHide ? ( children ) : ( ${APP_NAME} `, supportMail: ` ${SUPPORT_MAIL_ADDRESS} `, }) ), }} /> } /> )} ); }; export const withLicenseRequired = (Component: ComponentType) => // eslint-disable-next-line react/display-name (hocProps: T) => ( ); export default LicenseRequired;