import { useSession } from "next-auth/react"; import type { AriaRole, ComponentType } from "react"; import React, { Fragment, useEffect } from "react"; import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { EmptyScreen, Alert, Button } from "@calcom/ui"; type LicenseRequiredProps = { as?: keyof JSX.IntrinsicElements | ""; className?: string; role?: AriaRole | undefined; children: React.ReactNode; }; const LicenseRequired = ({ children, as = "", ...rest }: LicenseRequiredProps) => { const session = useSession(); const { t } = useLocale(); const Component = as || Fragment; const hasValidLicense = session.data ? session.data.hasValidLicense : null; useEffect(() => { if (process.env.NODE_ENV === "development" && hasValidLicense === false) { // Very few people will see this, so we don't need to translate it console.info( `You're using a feature that requires a valid license. Please go to ${WEBAPP_URL}/auth/setup to enter a license key.` ); } }, []); return ( {hasValidLicense === null || hasValidLicense ? ( children ) : process.env.NODE_ENV === "development" ? ( /** We only show a warning in development mode, but allow the feature to be displayed for development/testing purposes */ <> {t("enterprise_license_locally")} {t("enterprise_license_sales")}{" "} {t("contact_sales")} } /> {children} ) : ( {t(`contact_sales`)} } description={t("enterprise_license_sales")} /> )} ); }; export const withLicenseRequired = (Component: ComponentType) => // eslint-disable-next-line react/display-name (hocProps: T) => ( ); export default LicenseRequired;