2022-12-07 20:53:44 +00:00
|
|
|
import DOMPurify from "dompurify";
|
2022-05-26 17:07:14 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
2023-04-12 15:26:31 +00:00
|
|
|
import type { AriaRole, ComponentType } from "react";
|
|
|
|
import React, { Fragment } from "react";
|
2022-05-26 17:07:14 +00:00
|
|
|
|
2023-04-19 14:15:08 +00:00
|
|
|
import { APP_NAME, CONSOLE_URL, SUPPORT_MAIL_ADDRESS, WEBAPP_URL } from "@calcom/lib/constants";
|
2022-11-30 21:52:56 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { EmptyScreen } from "@calcom/ui";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { AlertTriangle } from "@calcom/ui/components/icon";
|
2022-05-26 17:07:14 +00:00
|
|
|
|
|
|
|
type LicenseRequiredProps = {
|
|
|
|
as?: keyof JSX.IntrinsicElements | "";
|
|
|
|
className?: string;
|
|
|
|
role?: AriaRole | undefined;
|
|
|
|
children: React.ReactNode;
|
|
|
|
};
|
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
const LicenseRequired = ({ children, as = "", ...rest }: LicenseRequiredProps) => {
|
2022-05-26 17:07:14 +00:00
|
|
|
const session = useSession();
|
2023-04-19 14:15:08 +00:00
|
|
|
const { t } = useLocale();
|
2022-05-26 17:07:14 +00:00
|
|
|
const Component = as || Fragment;
|
2023-04-19 14:15:08 +00:00
|
|
|
const hasValidLicense = session.data ? session.data.hasValidLicense : null;
|
|
|
|
|
2022-05-26 17:07:14 +00:00
|
|
|
return (
|
|
|
|
<Component {...rest}>
|
2023-04-19 14:15:08 +00:00
|
|
|
{hasValidLicense === null || hasValidLicense ? (
|
2022-05-26 17:07:14 +00:00
|
|
|
children
|
|
|
|
) : (
|
|
|
|
<EmptyScreen
|
2023-04-12 15:26:31 +00:00
|
|
|
Icon={AlertTriangle}
|
2022-12-07 20:53:44 +00:00
|
|
|
headline={t("enterprise_license")}
|
2022-05-26 17:07:14 +00:00
|
|
|
description={
|
2022-11-30 21:52:56 +00:00
|
|
|
<div
|
|
|
|
dangerouslySetInnerHTML={{
|
2022-12-07 20:53:44 +00:00
|
|
|
__html: DOMPurify.sanitize(
|
|
|
|
t("enterprise_license_description", {
|
2023-04-19 14:15:08 +00:00
|
|
|
consoleUrl: `<a href="${CONSOLE_URL}" target="_blank" rel="noopener noreferrer" class="underline">
|
2022-11-30 21:52:56 +00:00
|
|
|
${APP_NAME}
|
|
|
|
</a>`,
|
2023-04-19 14:15:08 +00:00
|
|
|
setupUrl: `<a href="${WEBAPP_URL}/auth/setup" class="underline">/auth/setup</a>`,
|
|
|
|
supportMail: `<a href="mailto:${SUPPORT_MAIL_ADDRESS}" class="underline">
|
|
|
|
${SUPPORT_MAIL_ADDRESS}</a>`,
|
2022-12-07 20:53:44 +00:00
|
|
|
})
|
|
|
|
),
|
2022-11-30 21:52:56 +00:00
|
|
|
}}
|
|
|
|
/>
|
2022-05-26 17:07:14 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Component>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
export const withLicenseRequired =
|
2023-01-27 01:50:56 +00:00
|
|
|
<T extends JSX.IntrinsicAttributes>(Component: ComponentType<T>) =>
|
2022-05-26 17:07:14 +00:00
|
|
|
// eslint-disable-next-line react/display-name
|
2022-07-28 19:58:26 +00:00
|
|
|
(hocProps: T) =>
|
|
|
|
(
|
2022-05-26 17:07:14 +00:00
|
|
|
<LicenseRequired>
|
2022-07-28 19:58:26 +00:00
|
|
|
<Component {...hocProps} />
|
2022-05-26 17:07:14 +00:00
|
|
|
</LicenseRequired>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default LicenseRequired;
|