forked from kolplattformen/skolplattformen
-
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.
- Loading branch information
1 parent
aa98a40
commit ce05682
Showing
11 changed files
with
87 additions
and
62 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
18 changes: 18 additions & 0 deletions
18
apps/skolplattformen-sthlm/context/feature/featureContext.tsx
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,18 @@ | ||
import { Features, FeatureType } from '@skolplattformen/api' | ||
import React from 'react' | ||
|
||
export const FeatureFlagsContext = React.createContext<Features>({ | ||
LOGIN_BANK_ID_SAME_DEVICE: false, | ||
}) | ||
|
||
interface Props { | ||
features: Features | ||
} | ||
|
||
export const FeatureProvider: React.FC<Props> = (props) => { | ||
return ( | ||
<FeatureFlagsContext.Provider value={props.features} {...props}> | ||
{props.children} | ||
</FeatureFlagsContext.Provider> | ||
) | ||
} |
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,12 @@ | ||
import React from 'react' | ||
import { FeatureType, Features } from '@skolplattformen/api' | ||
import { FeatureFlagsContext } from '../context/feature/featureContext' | ||
|
||
export const useFeature = (name: FeatureType) => { | ||
const features = React.useContext<Features>(FeatureFlagsContext) | ||
if (features === null) { | ||
throw new Error('You must wrap your components in a FeatureProvider.') | ||
} | ||
|
||
return features[name] | ||
} |
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,5 +1,5 @@ | ||
import { Feature } from '@skolplattformen/api' | ||
import { Features } from '@skolplattformen/api' | ||
|
||
export const features: Feature[] = [ | ||
{ name: 'login', enabled: true }, | ||
] | ||
export const features: Features = { | ||
LOGIN_BANK_ID_SAME_DEVICE: false | ||
} |
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,5 @@ | ||
import { Features } from '@skolplattformen/api' | ||
|
||
export const features: Features = { | ||
LOGIN_BANK_ID_SAME_DEVICE: true | ||
} |
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,4 +1,5 @@ | ||
export interface Feature { | ||
name: string; | ||
enabled: boolean; | ||
} | ||
export interface Features { | ||
LOGIN_BANK_ID_SAME_DEVICE: boolean; | ||
} | ||
|
||
export type FeatureType = keyof Features; |
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.