The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Delay loading support chat (#10234)
Félix Malfait1dca3694f7b1
diff --git a/packages/twenty-front/src/modules/support/components/__stories__/SupportDropdown.stories.tsx b/packages/twenty-front/src/modules/support/components/__stories__/SupportDropdown.stories.tsxindex c8f3d50e8f3..b1a06718d4a 100644--- a/packages/twenty-front/src/modules/support/components/__stories__/SupportDropdown.stories.tsx+++ b/packages/twenty-front/src/modules/support/components/__stories__/SupportDropdown.stories.tsx@@ -53,6 +53,9 @@ export const Default: Story = {expect(await canvas.findByText('Support')).toBeInTheDocument();await userEvent.click(canvas.getByText('Support'));+ // Add delay to account for the timeout in useSupportChat+ await new Promise((resolve) => setTimeout(resolve, 600));+expect(await canvas.findByText('Documentation')).toBeInTheDocument();expect(await canvas.findByText('Talk to us')).toBeInTheDocument();},diff --git a/packages/twenty-front/src/modules/support/hooks/useSupportChat.ts b/packages/twenty-front/src/modules/support/hooks/useSupportChat.tsindex 6b2b76be79b..ca8ea519380 100644--- a/packages/twenty-front/src/modules/support/hooks/useSupportChat.ts+++ b/packages/twenty-front/src/modules/support/hooks/useSupportChat.ts@@ -12,15 +12,18 @@ const insertScript = ({src,innerHTML,onLoad,+ defer = false,}: {src?: string;innerHTML?: string;onLoad?: (...args: any[]) => void;+ defer?: boolean;}) => {const script = document.createElement('script');if (isNonEmptyString(src)) script.src = src;if (isNonEmptyString(innerHTML)) script.innerHTML = innerHTML;if (isDefined(onLoad)) script.onload = onLoad;+ script.defer = defer;document.body.appendChild(script);};@@ -50,6 +53,7 @@ export const useSupportChat = () => {insertScript({src: url,+ defer: true,onLoad: () => {window.FrontChat?.('init', {chatId,@@ -76,11 +80,13 @@ export const useSupportChat = () => {isDefined(currentWorkspaceMember) &&!isFrontChatLoaded) {- configureFront(- supportChat.supportFrontChatId,- currentUser,- currentWorkspaceMember,- );+ setTimeout(() => {+ configureFront(+ supportChat.supportFrontChatId as string,+ currentUser,+ currentWorkspaceMember,+ );+ }, 500);}}, [configureFront,