All files / libs/tenants/companies/state/src/lib/hooks useFeatureFlag.ts

100% Statements 27/27
100% Branches 1/1
100% Functions 2/2
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 251x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 142x 2623x 144x 2621x 2623x 2623x 2x  
import { type CompanyFeatureFlags } from '@amalia/tenants/companies/types';
 
import { useCurrentCompany } from '../queries';
 
/**
 * This hook is used to check if a feature flag is enabled or not for the current company.
 *
 * @example
 *
 * Usage:
 *
 * ```tsx
 *  const { isFeatureEnabled } = useFeatureFlag(CompanyFeature.BADGES);
 * ```
 *
 * This will return `{ isFeatureEnabled: true }` if the feature flag BADGES is enabled for the company and `{ isFeatureEnabled: false }` otherwise.
 */
export const useFeatureFlag = (featureFlag: CompanyFeatureFlags) => {
  const isFeatureEnabled = !!useCurrentCompany().data.featureFlags[featureFlag];
 
  return {
    isFeatureEnabled,
  };
};