Feature flags seeds, queries and hooks (#2769)
* seed is working * allow graphql to retrieve feature flag data * create useIsFeatureEnabled hook * hook is working * Update icons.ts
This commit is contained in:
@ -4,7 +4,12 @@ import { Workspace } from '~/generated/graphql';
|
||||
|
||||
export type CurrentWorkspace = Pick<
|
||||
Workspace,
|
||||
'id' | 'inviteHash' | 'logo' | 'displayName' | 'allowImpersonation'
|
||||
| 'id'
|
||||
| 'inviteHash'
|
||||
| 'logo'
|
||||
| 'displayName'
|
||||
| 'allowImpersonation'
|
||||
| 'featureFlags'
|
||||
>;
|
||||
|
||||
export const currentWorkspaceState = atom<CurrentWorkspace | null>({
|
||||
|
||||
@ -26,6 +26,12 @@ export const GET_CURRENT_USER = gql`
|
||||
domainName
|
||||
inviteHash
|
||||
allowImpersonation
|
||||
featureFlags {
|
||||
id
|
||||
key
|
||||
value
|
||||
workspaceId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
front/src/modules/workspace/hooks/useIsFeatureEnabled.ts
Normal file
17
front/src/modules/workspace/hooks/useIsFeatureEnabled.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
|
||||
|
||||
export const useIsFeatureEnabled = (featureKey: string): boolean => {
|
||||
const currentWorkspace = useRecoilValue(currentWorkspaceState);
|
||||
|
||||
const featureFlag = currentWorkspace?.featureFlags?.find(
|
||||
(flag) => flag.key === featureKey,
|
||||
);
|
||||
|
||||
if (!featureFlag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return featureFlag.value;
|
||||
};
|
||||
Reference in New Issue
Block a user