UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

54 lines (52 loc) 1.5 kB
import { DEFAULT_PROFILE_LABELS, getProfileLabel } from "./chunk-AL66UXRT.mjs"; import { useAppStore } from "./chunk-C2KAIQ4I.mjs"; // src/hooks/useProfileLabels.ts import { useEffect, useMemo, useState } from "react"; var useProfileLabels = (config) => { const [customLabels, setCustomLabels] = useState({}); const [loading, setLoading] = useState(true); const { institutionId } = useAppStore(); useEffect(() => { setCustomLabels({}); if (!institutionId) { setLoading(false); return; } let active = true; setLoading(true); const fetchProfileLabels = async () => { try { const { data: response } = await config.apiClient.get(`/featureFlags/institution/${institutionId}/page/PROFILE_LABELS`); if (!active) return; const version = response?.data?.featureFlags?.version; setCustomLabels(version ?? {}); } catch { if (active) setCustomLabels({}); } finally { if (active) setLoading(false); } }; fetchProfileLabels(); return () => { active = false; }; }, [institutionId, config.apiClient]); const labels = useMemo( () => ({ ...DEFAULT_PROFILE_LABELS, ...customLabels }), [customLabels] ); const getProfileLabel2 = useMemo( () => (role) => getProfileLabel(role, labels), [labels] ); return { labels, customLabels, getProfileLabel: getProfileLabel2, loading }; }; export { useProfileLabels }; //# sourceMappingURL=chunk-TD4TCHHR.mjs.map