import { useQuery } from '@tanstack/react-query'; import { api } from '@/lib/api/client'; interface ModulesResponse { enabled: string[]; } /** * Hook to check if modules are enabled * Uses public endpoint, cached for performance */ export function useModules() { const { data, isLoading } = useQuery({ queryKey: ['modules-enabled'], queryFn: async () => { const response = await api.get('/modules/enabled') as any; // api.get returns the data directly, not wrapped in .data return response || { enabled: [] }; }, staleTime: 5 * 60 * 1000, // Cache for 5 minutes }); const isEnabled = (moduleId: string): boolean => { return data?.enabled?.includes(moduleId) ?? false; }; return { enabledModules: data?.enabled ?? [], isEnabled, isLoading, }; }