diff --git a/package.json b/package.json index 0c4405b8..99e5da0f 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "react-dom": "18.2.0", "react-markdown": "^8.0.3", "react-use-measure": "^2.1.1", + "react-zendesk": "^0.1.13", "subscriptions-transport-ws": "^0.11.0", "tailwindcss": "^3.1.6", "twin.macro": "^3.0.0-rc.3", diff --git a/src/components/Layout/LayoutApp.tsx b/src/components/Layout/LayoutApp.tsx index 075115ac..0f028153 100644 --- a/src/components/Layout/LayoutApp.tsx +++ b/src/components/Layout/LayoutApp.tsx @@ -1,6 +1,7 @@ import { Icon } from "@iconify/react"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; +import Zendesk, { ZendeskAPI } from "react-zendesk"; // eslint-disable-next-line @typescript-eslint/no-unused-vars import tw from "twin.macro"; @@ -13,6 +14,7 @@ import { styledNavButton, styledTrigger, } from "src/components"; +import config from "src/config"; import { useDeviceDetect } from "src/hooks"; interface Props { @@ -36,8 +38,31 @@ const LayoutApp = ({ children, renderNavMobile }: Props) => { const [isOpen, setIsOpen] = useState(false); useEffect(() => setIsOpen(false), [router.asPath]); + // ZE + useEffect(() => { + const hideZendesk = config.routesToHideZendeskWidget.some((path) => + router.pathname.startsWith(path), + ); + console.log("hideZendesk", hideZendesk); + + if (hideZendesk) { + ZendeskAPI("webWidget", "hide"); + } + + return () => { + ZendeskAPI("webWidget", "show"); + }; + }, []); + return ( <> + {/* CHAT */} + console.log("ZE is loaded")} + /> + {/* NAVBAR */} {!isSendPath && (
diff --git a/src/config/index.ts b/src/config/index.ts index ec259674..52383d2e 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -11,7 +11,7 @@ const generalConfig = { vanaExploreURL: "https://explore.vana.com", ZENDESK_WIDGET_KEY: "ae33c673-67c2-4bb9-96a4-3b62821d9567", - routesToHideZendeskWidget: ["/share"], + routesToHideZendeskWidget: ["/share", "/login"], preSignedObjectURLTTLInMilliseconds: 10 * 60 * 1000, // Valid for 10 minutes maxFileUploadSize: 2147483648, diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index b755fa82..1c9f594f 100755 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -7,8 +7,6 @@ import { CacheProvider } from "@emotion/react"; import * as Toast from "@radix-ui/react-toast"; import * as Tooltip from "@radix-ui/react-tooltip"; import type { AppProps } from "next/app"; -import { useRouter } from "next/router"; -import Script from "next/script"; import { ThemeProvider } from "next-themes"; // eslint-disable-next-line @typescript-eslint/no-unused-vars import tw from "twin.macro"; @@ -19,14 +17,12 @@ import { LayoutApp, UserProvider, } from "src/components"; -import config from "src/config"; import GlobalStyles from "../styles/GlobalStyles"; import { useApollo } from "../utils/apolloClient"; const NextApp = ({ Component, pageProps }: AppProps) => { const client = useApollo(pageProps); - const router = useRouter(); // Datadog RUM initialization datadogRum.init({ @@ -55,14 +51,6 @@ const NextApp = ({ Component, pageProps }: AppProps) => { - {!config.routesToHideZendeskWidget.some((path) => - router.pathname.startsWith(path), - ) && ( -