diff --git a/apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx b/apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx index 998fe2c2390b..bc0d8a2f0d58 100644 --- a/apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx +++ b/apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx @@ -1,7 +1,14 @@ -import React, { useEffect, useState } from 'react' -import { config, boostChatPanelEndpoints } from './config' +import React, { useEffect, useMemo, useState } from 'react' +import { useQuery } from '@apollo/client' + +import { Query, QueryGetNamespaceArgs } from '@island.is/web/graphql/schema' +import { useNamespaceStrict } from '@island.is/web/hooks' +import { useI18n } from '@island.is/web/i18n' +import { GET_NAMESPACE_QUERY } from '@island.is/web/screens/queries' + import { ChatBubble } from '../ChatBubble' import { BoostChatPanelProps } from '../types' +import { boostChatPanelEndpoints, config } from './config' declare global { interface Window { @@ -16,6 +23,7 @@ export const BoostChatPanel: React.FC< React.PropsWithChildren > = ({ endpoint, pushUp = false }) => { const [showButton, setShowButton] = useState(Boolean(window.boost)) // we show button when chat already loaded + const { activeLocale } = useI18n() useEffect(() => { // recreate the chat panel if we are on a different endpoint @@ -60,19 +68,43 @@ export const BoostChatPanel: React.FC< ) setShowButton(true) + + const queryParam = new URLSearchParams(window.location.search).get( + 'wa_lid', + ) + if (queryParam && ['t10', 't11'].includes(queryParam)) { + window.boost.chatPanel.show() + } }) el.src = boostChatPanelEndpoints[endpoint].url el.id = 'boost-script' document.body.appendChild(el) } - }, []) + }, [endpoint]) + + const { data } = useQuery(GET_NAMESPACE_QUERY, { + variables: { + input: { + lang: activeLocale, + namespace: 'ChatPanels', + }, + }, + }) + + const namespace = useMemo( + () => JSON.parse(data?.getNamespace?.fields || '{}'), + [data?.getNamespace?.fields], + ) + + const n = useNamespaceStrict(namespace) return ( window.boost.chatPanel.show()} isVisible={showButton} + pushUp={pushUp} /> ) }