mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat: add plan checks to uiconfig (#2600)
Hopefully a cleaner and DRY way of checking for the current Unleash plan level, which may help in cases like https://github.com/Unleash/unleash/pull/2585#discussion_r1038138963
This commit is contained in:
parent
f4146bfc4b
commit
b976fee44b
@ -11,6 +11,8 @@ interface IUseUIConfigOutput {
|
|||||||
error?: Error;
|
error?: Error;
|
||||||
refetch: () => void;
|
refetch: () => void;
|
||||||
isOss: () => boolean;
|
isOss: () => boolean;
|
||||||
|
isPro: () => boolean;
|
||||||
|
isEnterprise: () => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useUiConfig = (): IUseUIConfigOutput => {
|
const useUiConfig = (): IUseUIConfigOutput => {
|
||||||
@ -18,7 +20,18 @@ const useUiConfig = (): IUseUIConfigOutput => {
|
|||||||
const { data, error, mutate } = useSWR<IUiConfig>(path, fetcher);
|
const { data, error, mutate } = useSWR<IUiConfig>(path, fetcher);
|
||||||
|
|
||||||
const isOss = useCallback(() => {
|
const isOss = useCallback(() => {
|
||||||
return !data?.versionInfo?.current?.enterprise;
|
return !Boolean(data?.versionInfo?.current?.enterprise);
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
const isPro = useCallback(() => {
|
||||||
|
return data?.environment?.toLowerCase() === 'pro';
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
const isEnterprise = useCallback(() => {
|
||||||
|
return (
|
||||||
|
data?.environment?.toLowerCase() !== 'pro' &&
|
||||||
|
Boolean(data?.versionInfo?.current?.enterprise)
|
||||||
|
);
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
const uiConfig: IUiConfig = useMemo(() => {
|
const uiConfig: IUiConfig = useMemo(() => {
|
||||||
@ -35,6 +48,8 @@ const useUiConfig = (): IUseUIConfigOutput => {
|
|||||||
error,
|
error,
|
||||||
refetch: mutate,
|
refetch: mutate,
|
||||||
isOss,
|
isOss,
|
||||||
|
isPro,
|
||||||
|
isEnterprise,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user