From f1d3ba750c9b270b46568caa882ca4961310b5ca Mon Sep 17 00:00:00 2001 From: Gosha Date: Mon, 24 Jul 2023 17:36:55 +0300 Subject: [PATCH] feat: tenant feature flag hook --- apps/web/src/config/index.ts | 4 ++++ apps/web/src/hooks/useFeatureFlags.ts | 16 +++++++++++++++- libs/shared/src/types/feature-flags/index.ts | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/web/src/config/index.ts b/apps/web/src/config/index.ts index 787acb4490b..f122903fef5 100644 --- a/apps/web/src/config/index.ts +++ b/apps/web/src/config/index.ts @@ -68,3 +68,7 @@ export const IS_MULTI_PROVIDER_CONFIGURATION_ENABLED = isCypress : window._env_.IS_MULTI_PROVIDER_CONFIGURATION_ENABLED || process.env.IS_MULTI_PROVIDER_CONFIGURATION_ENABLED || 'false'; + +export const IS_MULTI_TENANCY_ENABLED = isCypress + ? window._env_.IS_MULTI_TENANCY_ENABLED || process.env.IS_MULTI_TENANCY_ENABLED || 'true' + : window._env_.IS_MULTI_TENANCY_ENABLED || process.env.IS_MULTI_TENANCY_ENABLED || 'false'; diff --git a/apps/web/src/hooks/useFeatureFlags.ts b/apps/web/src/hooks/useFeatureFlags.ts index 07e53885677..adce50bda95 100644 --- a/apps/web/src/hooks/useFeatureFlags.ts +++ b/apps/web/src/hooks/useFeatureFlags.ts @@ -1,7 +1,11 @@ import { FeatureFlagsKeysEnum } from '@novu/shared'; import { useFlags } from 'launchdarkly-react-client-sdk'; -import { IS_TEMPLATE_STORE_ENABLED, IS_MULTI_PROVIDER_CONFIGURATION_ENABLED } from '../config'; +import { + IS_TEMPLATE_STORE_ENABLED, + IS_MULTI_PROVIDER_CONFIGURATION_ENABLED, + IS_MULTI_TENANCY_ENABLED, +} from '../config'; const prepareBooleanStringFeatureFlag = (value: string | undefined, defaultValue: boolean): boolean => { const preparedValue = value === 'true'; @@ -36,3 +40,13 @@ export const useIsMultiProviderConfigurationEnabled = (): boolean => { return isMultiProviderConfigurationEnabled ?? defaultValue; }; + +export const useIsMultiTenancyEnabled = (): boolean => { + const value = IS_MULTI_TENANCY_ENABLED; + const fallbackValue = false; + const defaultValue = prepareBooleanStringFeatureFlag(value, fallbackValue); + + const isMultiTenancyEnabled = useGetFlagByKey(FeatureFlagsKeysEnum.IS_MULTI_TENANCY_ENABLED); + + return isMultiTenancyEnabled ?? defaultValue; +}; diff --git a/libs/shared/src/types/feature-flags/index.ts b/libs/shared/src/types/feature-flags/index.ts index 5580fed7512..786c6dc852a 100644 --- a/libs/shared/src/types/feature-flags/index.ts +++ b/libs/shared/src/types/feature-flags/index.ts @@ -2,4 +2,5 @@ export enum FeatureFlagsKeysEnum { IS_TEMPLATE_STORE_ENABLED = 'IS_TEMPLATE_STORE_ENABLED', IS_TOPIC_NOTIFICATION_ENABLED = 'IS_TOPIC_NOTIFICATION_ENABLED', IS_MULTI_PROVIDER_CONFIGURATION_ENABLED = 'IS_MULTI_PROVIDER_CONFIGURATION_ENABLED', + IS_MULTI_TENANCY_ENABLED = 'IS_MULTI_TENANCY_ENABLED', }