Skip to content

Commit

Permalink
Studio - only show intercom post-login (#880)
Browse files Browse the repository at this point in the history
* move Intercom into its own component

* only render intercom for post-login pages

* move intercom into EnforceLoginStatePageWrapper
  • Loading branch information
adriangohjw authored Nov 18, 2024
1 parent b70ddc4 commit 0a980d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PropsWithChildren } from "react"
import { useMemo } from "react"
import { useRouter } from "next/router"
import Intercom from "@intercom/messenger-js-sdk"

import { env } from "~/env.mjs"
import { useLoginState } from "~/features/auth"
import { SIGN_IN } from "~/lib/routes"
import { callbackUrlSchema } from "~/schemas/url"
Expand Down Expand Up @@ -46,6 +48,13 @@ export const EnforceLoginStatePageWrapper = ({
const { hasLoginStateFlag } = useLoginState()

if (hasLoginStateFlag) {
// Initialize Intercom
if (env.NEXT_PUBLIC_INTERCOM_APP_ID) {
Intercom({
app_id: env.NEXT_PUBLIC_INTERCOM_APP_ID,
})
}

return <>{children}</>
}

Expand Down
7 changes: 0 additions & 7 deletions apps/studio/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Skeleton, Stack } from "@chakra-ui/react"
import { datadogRum } from "@datadog/browser-rum"
import { GrowthBook } from "@growthbook/growthbook"
import { GrowthBookProvider } from "@growthbook/growthbook-react"
import Intercom from "@intercom/messenger-js-sdk"
import { ThemeProvider } from "@opengovsg/design-system-react"
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
import { ErrorBoundary } from "react-error-boundary"
Expand Down Expand Up @@ -59,12 +58,6 @@ void gb.init({
})

const MyApp = ((props: AppPropsWithAuthAndLayout) => {
if (env.NEXT_PUBLIC_INTERCOM_APP_ID) {
Intercom({
app_id: env.NEXT_PUBLIC_INTERCOM_APP_ID,
})
}

return (
<EnvProvider env={env}>
<LoginStateProvider>
Expand Down

0 comments on commit 0a980d2

Please sign in to comment.