-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add useFeature hook, only show workflows when enabled (#12)
* add useFeature hook * only show workflows tab when workflow feature is enabled
- Loading branch information
Showing
3 changed files
with
53 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useMemo } from "react"; | ||
|
||
const isNil = (val: string | null | undefined): boolean => | ||
val === undefined || val === null; | ||
|
||
const getBoolVal = (val?: string | boolean | null): boolean => { | ||
if (typeof val === "string") { | ||
return val === "true"; | ||
} | ||
|
||
return !!val; | ||
}; | ||
|
||
const useFeature = (name: string, enabled = false): boolean => { | ||
const featureEnabled = useMemo((): boolean => { | ||
const localStorageValue = window?.localStorage?.getItem(`FEATURE_${name}`); | ||
const envVar: string | undefined = import.meta.env[`VITE_FEATURE_${name}`]; | ||
|
||
if (!isNil(localStorageValue)) return getBoolVal(localStorageValue); | ||
if (!isNil(envVar)) return getBoolVal(envVar); | ||
|
||
return !!enabled; | ||
}, [name, enabled]); | ||
|
||
return featureEnabled; | ||
}; | ||
|
||
export default useFeature; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters