mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +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; | ||||
|     refetch: () => void; | ||||
|     isOss: () => boolean; | ||||
|     isPro: () => boolean; | ||||
|     isEnterprise: () => boolean; | ||||
| } | ||||
| 
 | ||||
| const useUiConfig = (): IUseUIConfigOutput => { | ||||
| @ -18,7 +20,18 @@ const useUiConfig = (): IUseUIConfigOutput => { | ||||
|     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(() => { | ||||
| @ -35,6 +48,8 @@ const useUiConfig = (): IUseUIConfigOutput => { | ||||
|         error, | ||||
|         refetch: mutate, | ||||
|         isOss, | ||||
|         isPro, | ||||
|         isEnterprise, | ||||
|     }; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user