mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-22 01:16:07 +02:00
feat: ability to communicate other license messages (#9192)
## About the changes This gives us the ability to communicate other license messages which are not errors. By default they'll be warning but I'm opening the possibility of using a backend-provided value to make them informative instead of warning. The intention is to communicate things like: - Your license is about to expire in x days. - You are getting close to the maximum number of seats in your license - etc
This commit is contained in:
parent
575bc41af0
commit
b9aa554b0d
@ -1,28 +1,45 @@
|
|||||||
import { Banner } from 'component/banners/Banner/Banner';
|
import { Banner } from 'component/banners/Banner/Banner';
|
||||||
import { useLicenseCheck } from 'hooks/api/getters/useLicense/useLicense';
|
import {
|
||||||
|
useLicense,
|
||||||
|
useLicenseCheck,
|
||||||
|
} from 'hooks/api/getters/useLicense/useLicense';
|
||||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||||
import type { BannerVariant } from 'interfaces/banner';
|
import type { BannerVariant } from 'interfaces/banner';
|
||||||
|
|
||||||
export const LicenseBanner = () => {
|
export const LicenseBanner = () => {
|
||||||
const { isEnterprise } = useUiConfig();
|
const { isEnterprise } = useUiConfig();
|
||||||
const licenseInfo = useLicenseCheck();
|
const licenseInfo = useLicenseCheck();
|
||||||
|
const license = useLicense();
|
||||||
|
|
||||||
// Only for enterprise
|
// Only for enterprise
|
||||||
if (
|
if (
|
||||||
isEnterprise() &&
|
isEnterprise() &&
|
||||||
licenseInfo &&
|
licenseInfo &&
|
||||||
!licenseInfo.isValid &&
|
|
||||||
!licenseInfo.loading &&
|
!licenseInfo.loading &&
|
||||||
!licenseInfo.error
|
!licenseInfo.error
|
||||||
) {
|
) {
|
||||||
const banner = {
|
if (!licenseInfo.isValid) {
|
||||||
message:
|
const banner = {
|
||||||
licenseInfo.message || 'You have an invalid Unleash license.',
|
message:
|
||||||
variant: 'error' as BannerVariant,
|
licenseInfo.message ||
|
||||||
sticky: true,
|
'You have an invalid Unleash license.',
|
||||||
};
|
variant: 'error' as BannerVariant,
|
||||||
|
sticky: true,
|
||||||
|
};
|
||||||
|
|
||||||
return <Banner key={banner.message} banner={banner} />;
|
return <Banner key={banner.message} banner={banner} />;
|
||||||
|
} else {
|
||||||
|
if (!license.loading && !license.error && licenseInfo.message) {
|
||||||
|
const banner = {
|
||||||
|
message: licenseInfo.message,
|
||||||
|
variant:
|
||||||
|
licenseInfo.messageType ?? ('warning' as BannerVariant),
|
||||||
|
sticky: true,
|
||||||
|
};
|
||||||
|
return <Banner key={banner.message} banner={banner} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
@ -2,10 +2,12 @@ import useSWR from 'swr';
|
|||||||
import { formatApiPath } from 'utils/formatPath';
|
import { formatApiPath } from 'utils/formatPath';
|
||||||
import handleErrorResponses from '../httpErrorResponseHandler';
|
import handleErrorResponses from '../httpErrorResponseHandler';
|
||||||
import { useEnterpriseSWR } from '../useEnterpriseSWR/useEnterpriseSWR';
|
import { useEnterpriseSWR } from '../useEnterpriseSWR/useEnterpriseSWR';
|
||||||
|
import type { BannerVariant } from 'interfaces/banner';
|
||||||
|
|
||||||
export interface LicenseInfo {
|
export interface LicenseInfo {
|
||||||
isValid: boolean;
|
isValid: boolean;
|
||||||
message?: string;
|
message?: string;
|
||||||
|
messageType?: BannerVariant;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
reCheckLicense: () => void;
|
reCheckLicense: () => void;
|
||||||
error?: Error;
|
error?: Error;
|
||||||
|
Loading…
Reference in New Issue
Block a user