@hhgtech/hhg-components
Version:
Hello Health Group common components
49 lines (46 loc) • 2.36 kB
JavaScript
import { a as __awaiter } from './tslib.es6-ea4dfe68.js';
import { e as normalizeLinkSlash, c as getDiscoverApiDomain } from './normalizeLink-593b397a.js';
import { g as getDataWithCache } from './core-78466274.js';
import './constantsDomainLocales.js';
import './Locale-f270bd9d.js';
import './constantsIsProduction.js';
const formatHealthTool = (healthTool, locale) => {
var _a, _b;
if (!healthTool)
return {};
const prefix = locale === 'tl-PH' ? '/fil' : '';
return {
id: healthTool.id,
isSubot: healthTool.is_subot,
template: healthTool.template,
icon: healthTool.icon,
link: ((_a = healthTool.link) === null || _a === void 0 ? void 0 : _a.startsWith('http'))
? healthTool.link
: `${prefix}/health-tools` +
((_b = healthTool.link) === null || _b === void 0 ? void 0 : _b.replace(`/${prefix}/`, '/').replace(`/health-tools/`, '/')),
subtitle: healthTool.subtitle,
title: healthTool.title,
};
};
const getDynamicHealthTool = (locale) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
try {
const customLang = locale === 'tl-PH' ? 'lang=fil' : '';
let response = [];
const isMarryBaby = locale.endsWith('_MB');
try {
const healthTools = yield fetch(normalizeLinkSlash(normalizeLinkSlash(`${getDiscoverApiDomain(locale)}/wp-json/api/${isMarryBaby ? 'health-tools' : 'healthtools'}?ismenu=0${customLang ? '&' + customLang : ''}`))).then((res) => res.json());
response =
((_b = (_a = healthTools === null || healthTools === void 0 ? void 0 : healthTools.data) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (healthTool) => formatHealthTool(healthTool, locale))) || [];
}
catch (_c) { }
return response;
}
catch (e) {
console.error(e);
}
});
const getDynamicHealthToolWithCache = (locale) => __awaiter(void 0, void 0, void 0, function* () {
return (yield getDataWithCache('all-health-tools', () => getDynamicHealthTool(locale || 'en-PH'), (res) => !!(res === null || res === void 0 ? void 0 : res.length), 1000 * 60)) || [];
});
export { formatHealthTool, getDynamicHealthTool, getDynamicHealthToolWithCache };