analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
54 lines (46 loc) • 2.47 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkYRIJ2GJRjs = require('./chunk-YRIJ2GJR.js');
var _chunkMKN3J57Sjs = require('./chunk-MKN3J57S.js');
// src/hooks/useProfileLabels.ts
var _react = require('react');
var useProfileLabels = (config) => {
const [customLabels, setCustomLabels] = _react.useState.call(void 0, {});
const [loading, setLoading] = _react.useState.call(void 0, true);
const { institutionId } = _chunkMKN3J57Sjs.useAppStore.call(void 0, );
_react.useEffect.call(void 0, () => {
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 = _optionalChain([response, 'optionalAccess', _ => _.data, 'optionalAccess', _2 => _2.featureFlags, 'optionalAccess', _3 => _3.version]);
setCustomLabels(_nullishCoalesce(version, () => ( {})));
} catch (e) {
if (active) setCustomLabels({});
} finally {
if (active) setLoading(false);
}
};
fetchProfileLabels();
return () => {
active = false;
};
}, [institutionId, config.apiClient]);
const labels = _react.useMemo.call(void 0,
() => ({ ..._chunkYRIJ2GJRjs.DEFAULT_PROFILE_LABELS, ...customLabels }),
[customLabels]
);
const getProfileLabel2 = _react.useMemo.call(void 0,
() => (role) => _chunkYRIJ2GJRjs.getProfileLabel.call(void 0, role, labels),
[labels]
);
return { labels, customLabels, getProfileLabel: getProfileLabel2, loading };
};
exports.useProfileLabels = useProfileLabels;
//# sourceMappingURL=chunk-BNGQANDR.js.map