Skip to content

Commit

Permalink
move intercom into EnforceLoginStatePageWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangohjw committed Nov 16, 2024
1 parent a0f1a4d commit ae8a676
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 51 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
17 changes: 0 additions & 17 deletions apps/studio/src/components/Intercom.tsx

This file was deleted.

5 changes: 1 addition & 4 deletions apps/studio/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Flex, Text } from "@chakra-ui/react"

import { WithIntercomWrapper } from "~/components/Intercom"
import { SiteList } from "~/features/dashboard/SiteList"
import { type NextPageWithLayout } from "~/lib/types"
import { AdminLayout } from "~/templates/layouts/AdminLayout"
Expand All @@ -18,8 +17,6 @@ const DashboardPage: NextPageWithLayout = () => {
)
}

DashboardPage.getLayout = (page: React.ReactNode) => {
return <WithIntercomWrapper>{AdminLayout(page)}</WithIntercomWrapper>
}
DashboardPage.getLayout = AdminLayout

export default DashboardPage
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { BiData } from "react-icons/bi"
import { z } from "zod"

import { PermissionsBoundary } from "~/components/AuthWrappers"
import { WithIntercomWrapper } from "~/components/Intercom"
import { folderSettingsModalAtom } from "~/features/dashboard/atoms"
import { CollectionBanner } from "~/features/dashboard/components/CollectionBanner"
import { CollectionTable } from "~/features/dashboard/components/CollectionTable"
Expand Down Expand Up @@ -119,9 +118,7 @@ CollectionResourceListPage.getLayout = (page) => {
return (
<PermissionsBoundary
resourceType={ResourceType.Collection}
page={
<WithIntercomWrapper>{AdminCmsSidebarLayout(page)}</WithIntercomWrapper>
}
page={AdminCmsSidebarLayout(page)}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { z } from "zod"

import type { RouterOutput } from "~/utils/trpc"
import { PermissionsBoundary } from "~/components/AuthWrappers"
import { WithIntercomWrapper } from "~/components/Intercom"
import { folderSettingsModalAtom } from "~/features/dashboard/atoms"
import { DeleteResourceModal } from "~/features/dashboard/components/DeleteResourceModal/DeleteResourceModal"
import { FolderSettingsModal } from "~/features/dashboard/components/FolderSettingsModal"
Expand Down Expand Up @@ -251,9 +250,7 @@ FolderPage.getLayout = (page) => {
return (
<PermissionsBoundary
resourceType={ResourceType.Folder}
page={
<WithIntercomWrapper>{AdminCmsSidebarLayout(page)}</WithIntercomWrapper>
}
page={AdminCmsSidebarLayout(page)}
/>
)
}
Expand Down
5 changes: 1 addition & 4 deletions apps/studio/src/pages/sites/[siteId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { BiData, BiFileBlank, BiFolder, BiHomeAlt } from "react-icons/bi"
import { z } from "zod"

import { PermissionsBoundary } from "~/components/AuthWrappers"
import { WithIntercomWrapper } from "~/components/Intercom"
import { DeleteResourceModal } from "~/features/dashboard/components/DeleteResourceModal/DeleteResourceModal"
import { FolderSettingsModal } from "~/features/dashboard/components/FolderSettingsModal"
import { PageSettingsModal } from "~/features/dashboard/components/PageSettingsModal"
Expand Down Expand Up @@ -175,9 +174,7 @@ SitePage.getLayout = (page) => {
return (
<PermissionsBoundary
resourceType={ResourceType.RootPage}
page={
<WithIntercomWrapper>{AdminCmsSidebarLayout(page)}</WithIntercomWrapper>
}
page={AdminCmsSidebarLayout(page)}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Grid, GridItem } from "@chakra-ui/react"
import { z } from "zod"

import { WithIntercomWrapper } from "~/components/Intercom"
import { EditCollectionLinkPreview } from "~/features/editing-experience/components/EditLinkPreview"
import { LinkEditorDrawer } from "~/features/editing-experience/components/LinkEditorDrawer"
import { LinkEditingLayout } from "~/templates/layouts/LinkEditingLayout"
Expand Down Expand Up @@ -30,8 +29,6 @@ export const EditLink = () => {
)
}

EditLink.getLayout = (page: React.ReactNode) => {
return <WithIntercomWrapper>{LinkEditingLayout(page)}</WithIntercomWrapper>
}
EditLink.getLayout = LinkEditingLayout

export default EditLink
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ResourceType } from "~prisma/generated/generatedEnums"

import type { NextPageWithLayout } from "~/lib/types"
import { PermissionsBoundary } from "~/components/AuthWrappers"
import { WithIntercomWrapper } from "~/components/Intercom"
import { EditorDrawerProvider } from "~/contexts/EditorDrawerContext"
import EditPageDrawer from "~/features/editing-experience/components/EditPageDrawer"
import { EditPagePreview } from "~/features/editing-experience/components/EditPagePreview"
Expand Down Expand Up @@ -64,9 +63,7 @@ EditPage.getLayout = (page) => {
return (
<PermissionsBoundary
resourceType={ResourceType.Page}
page={
<WithIntercomWrapper>{PageEditingLayout(page)}</WithIntercomWrapper>
}
page={PageEditingLayout(page)}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { z } from "zod"

import type { NextPageWithLayout } from "~/lib/types"
import { PermissionsBoundary } from "~/components/AuthWrappers"
import { WithIntercomWrapper } from "~/components/Intercom"
import { ErrorProvider } from "~/features/editing-experience/components/form-builder/ErrorProvider"
import FormBuilder from "~/features/editing-experience/components/form-builder/FormBuilder"
import { editPageSchema } from "~/features/editing-experience/schema"
Expand Down Expand Up @@ -138,9 +137,7 @@ PageSettings.getLayout = (page) => {
return (
<PermissionsBoundary
resourceType={ResourceType.Page}
page={
<WithIntercomWrapper>{PageEditingLayout(page)}</WithIntercomWrapper>
}
page={PageEditingLayout(page)}
/>
)
}
Expand Down
7 changes: 1 addition & 6 deletions apps/studio/src/pages/sites/[siteId]/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { ResourceType } from "~prisma/generated/generatedEnums"
import { z } from "zod"

import { PermissionsBoundary } from "~/components/AuthWrappers"
import { WithIntercomWrapper } from "~/components/Intercom"
import { UnsavedSettingModal } from "~/features/editing-experience/components/UnsavedSettingModal"
import { useQueryParse } from "~/hooks/useQueryParse"
import { useZodForm } from "~/lib/form"
Expand Down Expand Up @@ -225,11 +224,7 @@ SiteSettingsPage.getLayout = (page) => {
return (
<PermissionsBoundary
resourceType={ResourceType.RootPage}
page={
<WithIntercomWrapper>
{AdminSidebarOnlyLayout(page)}
</WithIntercomWrapper>
}
page={AdminSidebarOnlyLayout(page)}
/>
)
}
Expand Down

0 comments on commit ae8a676

Please sign in to comment.