2022-05-26 17:07:14 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
2023-06-22 02:13:26 +00:00
|
|
|
import { Trans } from "next-i18next";
|
2023-04-12 15:26:31 +00:00
|
|
|
import type { AriaRole, ComponentType } from "react";
|
2023-06-22 02:13:26 +00:00
|
|
|
import React, { Fragment, useEffect } from "react";
|
2022-05-26 17:07:14 +00:00
|
|
|
|
2023-08-18 18:13:21 +00:00
|
|
|
import { 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-06-22 02:13:26 +00:00
|
|
|
import { EmptyScreen, TopBanner } 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;
|
|
|
|
|
2023-06-22 02:13:26 +00:00
|
|
|
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.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
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
|
2023-06-22 02:13:26 +00:00
|
|
|
) : process.env.NODE_ENV === "development" ? (
|
|
|
|
/** We only show a warning in development mode, but allow the feature to be displayed for development/testing purposes */
|
|
|
|
<>
|
|
|
|
<TopBanner
|
|
|
|
text=""
|
|
|
|
actions={
|
|
|
|
<>
|
|
|
|
{t("enterprise_license")}.{" "}
|
|
|
|
<Trans i18nKey="enterprise_license_development">
|
|
|
|
You can test this feature on development mode. For production usage please have an
|
|
|
|
administrator go to{" "}
|
|
|
|
<a href={`${WEBAPP_URL}/auth/setup`} className="underline">
|
|
|
|
/auth/setup
|
|
|
|
</a>{" "}
|
|
|
|
to enter a license key.
|
|
|
|
</Trans>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
variant="warning"
|
|
|
|
/>
|
|
|
|
{children}
|
|
|
|
</>
|
2022-05-26 17:07:14 +00:00
|
|
|
) : (
|
|
|
|
<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={
|
2023-08-18 18:13:21 +00:00
|
|
|
<Trans i18nKey="enterprise_license_description">
|
|
|
|
To enable this feature, have an administrator go to{" "}
|
|
|
|
<a href={`${WEBAPP_URL}/auth/setup`} className="underline">
|
|
|
|
/auth/setup
|
|
|
|
</a>
|
|
|
|
to enter a license key. If a license key is already in place, please contact{" "}
|
|
|
|
<a href={`mailto:${SUPPORT_MAIL_ADDRESS}`} className="underline">
|
|
|
|
<Trans>{{ SUPPORT_MAIL_ADDRESS }}</Trans>
|
|
|
|
</a>
|
|
|
|
for help.
|
|
|
|
</Trans>
|
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;
|