Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions packages/apps/human-app/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,12 @@
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script type="text/javascript" id="zsiqchat">
var $zoho = $zoho || {};
$zoho.salesiq = $zoho.salesiq || {
widgetcode:
'siqa18acfe081f579aac3e319f82ebb5e4009c0d32440c1be563e9aadb57830fa90',
values: {},
ready: function () {},
};
var d = document;
s = d.createElement('script');
s.type = 'text/javascript';
s.id = 'zsiqscript';
s.defer = true;
s.src = 'https://salesiq.zohopublic.com/widget';
t = d.getElementsByTagName('script')[0];
t.parentNode.insertBefore(s, t);
<script>
window.$zoho=window.$zoho || {};
$zoho.salesiq=$zoho.salesiq || {
ready: function() {}
}
</script>
<script id="zsiqscript" src="https://salesiq.zohopublic.com/widget?wc=siqa18acfe081f579aac3e319f82ebb5e4009c0d32440c1be563e9aadb57830fa90" defer></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
import { useEffect, useRef } from 'react';
import { useIsMobile } from '@/shared/hooks/use-is-mobile';
import { useEffect } from 'react';

export function Chat({
displayChatIcon = true,
}: {
displayChatIcon?: boolean;
}) {
const ref = useRef<HTMLDivElement>(null);
const isMobile = useIsMobile();

useEffect(() => {
let chatElement: HTMLElement | undefined;
const root = document.getElementById('root') as Element | undefined;
if (!root) return;

const positionChatElement = () => {
if (chatElement && ref.current) {
const refRect = ref.current.getBoundingClientRect();
const rootRect = root.getBoundingClientRect();

chatElement.style.position = 'absolute';
if (displayChatIcon) {
chatElement.style.opacity = '1';
chatElement.style.top = `${(refRect.top - rootRect.top).toString()}px`;
chatElement.style.right = isMobile ? '16px' : '80px';
chatElement.style.width = `${refRect.width.toString()}px`;
chatElement.style.height = `${refRect.height.toString()}px`;
} else {
chatElement.style.opacity = '0';
}
const applyVisibility = () => {
const chatElement = document.querySelector('[data-id="zsalesiq"]') as
| HTMLElement
| undefined;
if (chatElement) {
chatElement.style.opacity = displayChatIcon ? '1' : '0';
chatElement.style.pointerEvents = displayChatIcon ? 'auto' : 'none';
chatElement.childNodes.forEach((element, idx) => {
if (element instanceof HTMLElement) {
element.style.right = isMobile ? '16px' : '24px';
if (idx === 1) {
element.style.bottom = isMobile ? '16px' : '20px';
}
}
});
return true;
}

return false;
};

const mutationObserver = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
chatElement = document.querySelector('[data-id="zsalesiq"]') as
| HTMLElement
| undefined;
if (chatElement && ref.current) {
positionChatElement();
}
}
if (applyVisibility()) {
return;
}

const mutationObserver = new MutationObserver(() => {
if (applyVisibility()) {
mutationObserver.disconnect();
}
});

Expand All @@ -50,33 +45,10 @@ export function Chat({
subtree: true,
});

const resizeObserverElement = document.createElement('div');
resizeObserverElement.style.position = 'absolute';
resizeObserverElement.style.width = '100%';
resizeObserverElement.style.height = '100%';
resizeObserverElement.style.top = '0';
resizeObserverElement.style.left = '0';
resizeObserverElement.style.opacity = '0';
resizeObserverElement.style.pointerEvents = 'none';
document.body.appendChild(resizeObserverElement);

const resizeObserver = new ResizeObserver(positionChatElement);

resizeObserver.observe(resizeObserverElement);

return () => {
resizeObserver.disconnect();
mutationObserver.disconnect();
if (resizeObserverElement.parentNode) {
resizeObserverElement.parentNode.removeChild(resizeObserverElement);
}
};
}, [ref, displayChatIcon, isMobile]);
}, [displayChatIcon, isMobile]);

return (
<div
ref={ref}
style={{ width: '60px', height: '60px', position: 'relative' }}
/>
);
return null;
}
Loading