import React from 'react'; import { useBuilder, useEditor, FormItem } from '@tempi/core-editor'; import { ChatMultipleFilled } from '@fluentui/react-icons'; import { Badge, Switch, theme, Typography } from 'antd'; import { BUBBLE, ROOT } from '@tempi/core-renderer'; import { ContactBubbleEditor } from '@tempi/core-elements'; import set from 'lodash.set'; import { SidebarDrawer, SidebarItem, SideBarMenuProps, t, } from '@tempi/editor-site'; export const ContactBubbleMenu: React.FC = ({ disabled }) => { const { hideBubbleOnEditor, setHideBubbleOnEditor, showBubbleSetting, setShowBubbleSetting, } = useBuilder(); const { query, nodes, actions } = useEditor((state) => { return { nodes: state.nodes, }; }); const isExistBubble = Object.keys(nodes).includes(BUBBLE); const { token } = theme.useToken(); const { node } = query; const isEnabled = node(BUBBLE)?.get()?.data?.props?.enable || false; const contactBubbleSetting = node(BUBBLE)?.get()?.related?.customAttributes && React.createElement(node(BUBBLE)?.get()?.related?.customAttributes); const onChangeBubbleProps = (key: string, value) => { actions.history.ignore().setProp(BUBBLE, (props) => { set(props, key, value); }); }; const handleSwitch = (checked: boolean) => { if (checked) { if (!isExistBubble) { const newNodeTree = query .parseReactElement() .toNodeTree((node) => { node.id = BUBBLE; }); actions.addNodeTree(newNodeTree, ROOT); } onChangeBubbleProps('enable', true); } else { onChangeBubbleProps('enable', false); } }; return ( <> setShowBubbleSetting(true)} trackingContentName="ContactBubbleBtn" tooltip={t('Bong bóng liên hệ')} active={showBubbleSetting} disabled={disabled} > { setShowBubbleSetting(false); }} width={320} > {t( 'Thêm các nút liên hệ vào website giúp khách hàng dễ dàng liên hệ với bạn', )} {isEnabled && ( )} {t('Bạn cần cấu hình cho cả máy tính và điện thoại')} {contactBubbleSetting} ); };