-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added T&C consent to file upload and refactor feature flags
- Loading branch information
Showing
2 changed files
with
57 additions
and
10 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 |
---|---|---|
@@ -1,30 +1,60 @@ | ||
const FEATURE_FLAGS = { | ||
import { useMemo } from "react"; | ||
|
||
interface FeatureFlags { | ||
/** Controls whether users can edit project details and settings in: | ||
* - /projects/custom-project/details | ||
* - /projects/custom-project/summary | ||
*/ | ||
"edit-project": false, | ||
"edit-project": boolean; | ||
|
||
/** Controls the visibility and sharing functionality in: | ||
* - /profile | ||
*/ | ||
"share-information": false, | ||
"share-information": boolean; | ||
/** Controls the project comparison functionality in: | ||
* - /overview/project-details (scorecard ratings and cost estimates comparison) | ||
*/ | ||
"project-comparison": false, | ||
"project-comparison": boolean; | ||
/** Controls the actions dropdown functionality in: | ||
* - /my-projects table | ||
*/ | ||
"update-selection": false, | ||
"update-selection": boolean; | ||
/** Controls the visibility of the methodology page */ | ||
"methodology-page": boolean; | ||
"compare-with-other-project": boolean; | ||
} | ||
|
||
const DEFAULT_FEATURE_FLAGS: FeatureFlags = { | ||
"edit-project": false, | ||
"share-information": false, | ||
"project-comparison": false, | ||
"update-selection": false, | ||
"methodology-page": false, | ||
"compare-with-other-project": false, | ||
} as const; | ||
|
||
type FeatureFlags = typeof FEATURE_FLAGS; | ||
}; | ||
|
||
/** | ||
* Hook to get the feature flags for the current user. | ||
* Checks the environment variable FEATURE_FLAGS to see which flags are enabled. | ||
* If the environment variable is not set, falls back to default flags. | ||
* | ||
* @returns The feature flags for the current user. | ||
*/ | ||
export function useFeatureFlags(): FeatureFlags { | ||
// TODO: Implement feature flags with env variable | ||
return FEATURE_FLAGS; | ||
return useMemo(() => { | ||
const enabledFeatures = new Set( | ||
process.env.NEXT_PUBLIC_FEATURE_FLAGS?.split(",").map((f) => f.trim()) || | ||
[], | ||
); | ||
|
||
return ( | ||
Object.keys(DEFAULT_FEATURE_FLAGS) as Array<keyof FeatureFlags> | ||
).reduce( | ||
(flags, key) => ({ | ||
...flags, | ||
[key]: enabledFeatures.has(key) || DEFAULT_FEATURE_FLAGS[key], | ||
}), | ||
{} as FeatureFlags, | ||
); | ||
}, []); | ||
} |