-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1200 from IntersectMBO/chore/add-proposal-discuss…
…ion-forum-enable-feature-flag chore: add proposal discussion forum feature flag
- Loading branch information
Showing
10 changed files
with
120 additions
and
50 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
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
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
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,44 @@ | ||
import { PropsWithChildren, useMemo, createContext, useContext } from "react"; | ||
|
||
const FeatureFlagContext = createContext({ | ||
isProposalDiscussionForumEnabled: false, | ||
}); | ||
|
||
/** | ||
* Provides feature flag context to its children components. | ||
* | ||
* @param children - The child components to render. | ||
*/ | ||
const FeatureFlagProvider = ({ children }: PropsWithChildren) => { | ||
const value = useMemo( | ||
() => ({ | ||
isProposalDiscussionForumEnabled: | ||
import.meta.env.VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED === "true" || | ||
false, | ||
}), | ||
[], | ||
); | ||
|
||
return ( | ||
<FeatureFlagContext.Provider value={value}> | ||
{children} | ||
</FeatureFlagContext.Provider> | ||
); | ||
}; | ||
|
||
/** | ||
* Custom hook that provides access to the feature flag context. | ||
* Throws an error if used outside of a FeatureFlagProvider. | ||
* @returns The feature flag context. | ||
*/ | ||
const useFeatureFlag = () => { | ||
const context = useContext(FeatureFlagContext); | ||
|
||
if (!context) { | ||
throw new Error("useFeatureFlag must be used within a FeatureFlagProvider"); | ||
} | ||
|
||
return context; | ||
}; | ||
|
||
export { FeatureFlagProvider, useFeatureFlag }; |
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
This file was deleted.
Oops, something went wrong.