All files / packages/hooks/src flags.ts

90% Statements 9/10
100% Branches 2/2
66.66% Functions 2/3
88.88% Lines 8/9

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 25 26 27 28 29 30 31 32 33                  1x 10x       10x 10x 8x 8x     10x           1x            
import { useMemo } from "react";
 
import { LAUNCHDARKLY_FLAGS } from "@repo/constants/launchdarkly";
 
import { useLaunchDarklyJson } from "./launchdarkly";
 
/**
 * Hook to check if the old UI should be enabled.
 */
export const useEnableOldUI = (email?: string | null) => {
  const { value: enabledEmails, loading: loadingEmails } = useLaunchDarklyJson<
    Record<string, boolean>
  >(LAUNCHDARKLY_FLAGS.ENABLE_OLD_UI, {});
 
  const isEnabled = useMemo(() => {
    if (!email) return false;
    const normalizedEmail = email.toLowerCase();
    return !!enabledEmails[normalizedEmail];
  }, [email, enabledEmails]);
 
  return { value: isEnabled, loading: loadingEmails };
};
 
/**
 * Hook to get the map of disabled features.
 */
export const useDisabledFeatures = () => {
  return useLaunchDarklyJson<Record<string, boolean>>(
    LAUNCHDARKLY_FLAGS.DISABLE_FEATURES,
    {},
  );
};