From b976fee44bd5d80f303250fe7c99f19c5f82d5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Tue, 6 Dec 2022 13:19:19 +0000 Subject: [PATCH] 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 --- .../api/getters/useUiConfig/useUiConfig.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts b/frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts index 7f5c665ef2..8c7ee3ebd4 100644 --- a/frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts +++ b/frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts @@ -11,6 +11,8 @@ interface IUseUIConfigOutput { error?: Error; refetch: () => void; isOss: () => boolean; + isPro: () => boolean; + isEnterprise: () => boolean; } const useUiConfig = (): IUseUIConfigOutput => { @@ -18,7 +20,18 @@ const useUiConfig = (): IUseUIConfigOutput => { const { data, error, mutate } = useSWR(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(() => { @@ -35,6 +48,8 @@ const useUiConfig = (): IUseUIConfigOutput => { error, refetch: mutate, isOss, + isPro, + isEnterprise, }; };