analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
50 lines (45 loc) • 2.15 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunkMKN3J57Sjs = require('./chunk-MKN3J57S.js');
// src/hooks/useSupportFeatureFlag.ts
var _react = require('react');
var useSupportFeatureFlag = (config) => {
const [supportType, setSupportType] = _react.useState.call(void 0,
"NATIVE" /* NATIVE */
);
const [loading, setLoading] = _react.useState.call(void 0, true);
const { institutionId } = _chunkMKN3J57Sjs.useAppStore.call(void 0, );
_react.useEffect.call(void 0, () => {
if (!institutionId) {
setLoading(false);
return;
}
const fetchSupportFlag = async () => {
try {
const { data: response } = await config.apiClient.get(`/featureFlags/institution/${institutionId}/page/SUPPORT`);
const type = _optionalChain([response, 'optionalAccess', _ => _.data, 'optionalAccess', _2 => _2.featureFlags, 'optionalAccess', _3 => _3.version, 'optionalAccess', _4 => _4.supportType]);
if (type) {
setSupportType(type);
}
} catch (e) {
setSupportType("NATIVE" /* NATIVE */);
} finally {
setLoading(false);
}
};
fetchSupportFlag();
}, [institutionId]);
const openZendeskChat = () => {
if (typeof globalThis !== "undefined" && globalThis.zE) {
globalThis.zE("messenger", "open");
}
};
return {
supportType,
loading,
isZendesk: supportType === "ZENDESK" /* ZENDESK */,
isNative: supportType === "NATIVE" /* NATIVE */,
openZendeskChat
};
};
exports.useSupportFeatureFlag = useSupportFeatureFlag;
//# sourceMappingURL=chunk-PTNSCCDJ.js.map