UNPKG

@hhgtech/hhg-components

Version:
198 lines (190 loc) • 10 kB
import { _ as __rest, a as __awaiter } from './tslib.es6-00ab44b2.js'; import React__default, { createContext, useState, useContext, useEffect } from 'react'; import { T as Tabs } from './index-04505e35.js'; import { L as Loading } from './index-072ae440.js'; import './index-fe4471f4.js'; import { b as formatArticle } from './dataTransform-60f9d527.js'; import { PATHS } from './togetherApiPaths.js'; import { T as TogetherComponentGlobalContext, c as callApi, f as getApiPath } from './utils-5e9c89a7.js'; import { Minus, Plus } from '@hhgtech/icons/core'; import { Collapse } from '@mantine/core'; import { C as CardAuthor } from './index-677d3a78.js'; import { L as LOCALE } from './Locale-dc1237b9.js'; import '@hhgtech/icons/other'; import './index-2d25b0f0.js'; import './shared-b07d1eb2.js'; import './index-17c85f76.js'; import './index-0b67696c.js'; import './index-09d9e570.js'; import './translationsContext-18f7b7e0.js'; import './index-67429eb2.js'; import './index-dac15b93.js'; import './miscCookieHelper.js'; import 'slugify'; import './constantsIsProduction.js'; import 'string-format'; import './constants-367949ba.js'; import 'dayjs'; import 'dayjs/plugin/relativeTime'; import './utils-538169b3.js'; import './index-daa074e7.js'; import './paths-4a2d3f94.js'; import './constants-ce67620e.js'; import './index-8c40504a.js'; import 'date-fns/locale'; import './constantsSite.js'; import './constantsDomainLocales.js'; import './constantsRiskScreener.js'; import './index-a22d54f1.js'; import './miscTheme.js'; import './WhatsApp-6a0c0a12.js'; import './Spinner-589f30ad.js'; import './index-a6a9fbc0.js'; import '@emotion/styled'; import './index-50aea2c8.js'; import './index-7adf994c.js'; import './index-4144308c.js'; import '@emotion/react'; import './index-e348d0b2.js'; import './index-3b8592c9.js'; import './index.styles-3adef5f6.js'; const ProfileDetailContext = createContext({}); var styles$1 = {"container":"_0NhMo6T","faq":"nrZtZ-u"}; const Faqs = ({ faqs }) => { const [collapseSelected, setCollapseSelected] = useState([]); const handleClick = (index) => { if (collapseSelected.includes(index)) { const newCollapseSelected = collapseSelected.filter((item) => item !== index); setCollapseSelected(newCollapseSelected); } else { setCollapseSelected((pre) => { return [...pre, index]; }); } }; return (React__default.createElement("div", { className: styles$1.container }, faqs.map((faq, index) => { const collapsed = collapseSelected.includes(index); return (React__default.createElement("div", { className: styles$1.faq, key: index }, React__default.createElement("div", { className: "faq-item", onClick: () => handleClick(index) }, React__default.createElement("div", { className: "faq-question", dangerouslySetInnerHTML: { __html: faq.question || '' } }), collapsed ? React__default.createElement(Minus, null) : React__default.createElement(Plus, null)), React__default.createElement(Collapse, { in: collapsed, className: "faq-answer" }, React__default.createElement("div", { dangerouslySetInnerHTML: { __html: faq.answer || '' } })))); }))); }; var styles = {"container":"_2ugC2Ll","info":"_8IDDHjn","body":"CCwRHCd","description":"RF63WXG","cardAuthorWrapper":"PIaeC0v"}; const formatExperience = (data) => { if (!data) return {}; return { title: data === null || data === void 0 ? void 0 : data.title, organization: data === null || data === void 0 ? void 0 : data.organization, duration: data.duration, }; }; const formatEducation = (data) => { if (!data) return {}; return { completedYear: data === null || data === void 0 ? void 0 : data.completed_year, schoolName: data.school_name, study: data.study, }; }; var TabName; (function (TabName) { TabName[TabName["About"] = 0] = "About"; TabName[TabName["Care"] = 1] = "Care"; TabName[TabName["Answer"] = 2] = "Answer"; TabName[TabName["Posts"] = 3] = "Posts"; })(TabName || (TabName = {})); var UserType; (function (UserType) { UserType[UserType["Expert"] = 0] = "Expert"; UserType[UserType["User"] = 1] = "User"; })(UserType || (UserType = {})); const TabDataInit = { experiences: [], relatedPosts: [], educations: [], awards: [], contact: {}, data: {}, }; const ProfileChatbot = (_a) => { var { authorProps, authActionWrapper, onSkipQuestion, onCloseFromPost, onChatWithBot, showSkipQuestionTag, currentPageUrl } = _a, rest = __rest(_a, ["authorProps", "authActionWrapper", "onSkipQuestion", "onCloseFromPost", "onChatWithBot", "showSkipQuestionTag", "currentPageUrl"]); const { data: { locale, userInfo, env: { isMarryBaby }, }, } = useContext(TogetherComponentGlobalContext); const id = String(authorProps === null || authorProps === void 0 ? void 0 : authorProps.userId); const [countValues, setCountValues] = useState(); const [loading, setLoading] = useState(false); const [info, setInfo] = useState(); const [faqs, setFaqs] = useState([]); const [description, setDescription] = useState(''); const isAuthorLogin = (userInfo === null || userInfo === void 0 ? void 0 : userInfo._togetherUserId) === (authorProps === null || authorProps === void 0 ? void 0 : authorProps.userId); const [activeTab, setActiveTab] = useState(1); const tabsProps = { value: String(activeTab), dataList: [ { value: '1', text: 'FAQs', content: React__default.createElement(Faqs, { faqs: faqs }), }, ], onTabChange: (n) => setActiveTab(Number(n)), }; useEffect(() => { (() => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; setLoading(true); const res = yield Promise.all([ callApi(getApiPath(PATHS.USER.DETAIL, { _locale: locale, id, }), 'GET'), callApi(getApiPath(PATHS.CHATBOT.PROFILE, { _locale: locale, }), 'GET'), callApi(getApiPath(PATHS.CHATBOT.FAQS_LIST, { _locale: locale, }), 'GET'), ]); const [restDetail, profileRes, faqsRes] = res; const resInfo = { data: restDetail === null || restDetail === void 0 ? void 0 : restDetail.data, experiences: (((_b = (_a = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.experiences) || []).map(formatExperience), relatedPosts: (((_c = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _c === void 0 ? void 0 : _c.related_post) || []).map((i) => formatArticle(i.post)), educations: (((_e = (_d = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _d === void 0 ? void 0 : _d.fields) === null || _e === void 0 ? void 0 : _e.educations) || []).map(formatEducation), awards: ((_g = (_f = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _f === void 0 ? void 0 : _f.fields) === null || _g === void 0 ? void 0 : _g.awards_accreditations) || [], contact: ((_j = (_h = restDetail === null || restDetail === void 0 ? void 0 : restDetail.data) === null || _h === void 0 ? void 0 : _h.fields) === null || _j === void 0 ? void 0 : _j.contact) || {}, }; (restDetail === null || restDetail === void 0 ? void 0 : restDetail.status) === 1 && setInfo(resInfo); setFaqs(((_k = faqsRes === null || faqsRes === void 0 ? void 0 : faqsRes.data) === null || _k === void 0 ? void 0 : _k.faqs) || []); setDescription(((_l = profileRes === null || profileRes === void 0 ? void 0 : profileRes.data) === null || _l === void 0 ? void 0 : _l.description) || ''); setLoading(false); }))(); }, []); return (React__default.createElement(ProfileDetailContext.Provider, { value: { isMarryBaby, siteType: isMarryBaby ? 'marryBaby' : 'helloSites', authorId: String((authorProps === null || authorProps === void 0 ? void 0 : authorProps.userId) || ''), authActionWrapper, onSkipQuestion, info, authorProps, onCloseFromPost, countValues, setCountValues, isAuthorLogin, showSkipQuestionTag, currentPageUrl, } }, React__default.createElement("div", Object.assign({}, rest, { className: `${styles.container} ${(rest === null || rest === void 0 ? void 0 : rest.className) || ''}`, "data-is-marrybaby": isMarryBaby }), loading ? (React__default.createElement(Loading, null)) : (React__default.createElement(React__default.Fragment, null, React__default.createElement("div", { className: styles.cardAuthorWrapper }, React__default.createElement(CardAuthor, Object.assign({}, authorProps, { className: "card-author", showDetailPopup: false, showChatbotButton: locale === LOCALE.Vietnam, onChatWithBot: onChatWithBot }))), React__default.createElement("div", { className: styles.description, dangerouslySetInnerHTML: { __html: description } }), faqs.length > 0 && (React__default.createElement("div", { className: styles.body }, React__default.createElement(Tabs, Object.assign({}, tabsProps))))))))); }; export { ProfileChatbot, TabDataInit, TabName, UserType };