Skip to content

Commit

Permalink
feat: add plan checks to uiconfig (#2600)
Browse files Browse the repository at this point in the history
Hopefully a cleaner and DRY way of checking for the current Unleash plan
level, which may help in cases like
#2585 (comment)
  • Loading branch information
nunogois committed Dec 6, 2022
1 parent f4146bf commit b976fee
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ interface IUseUIConfigOutput {
error?: Error;
refetch: () => void;
isOss: () => boolean;
isPro: () => boolean;
isEnterprise: () => boolean;
}

const useUiConfig = (): IUseUIConfigOutput => {
const path = formatApiPath(`api/admin/ui-config`);
const { data, error, mutate } = useSWR<IUiConfig>(path, fetcher);

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]);

const uiConfig: IUiConfig = useMemo(() => {
Expand All @@ -35,6 +48,8 @@ const useUiConfig = (): IUseUIConfigOutput => {
error,
refetch: mutate,
isOss,
isPro,
isEnterprise,
};
};

Expand Down

0 comments on commit b976fee

Please sign in to comment.