From ae8a676565d5556633f511e34a69c517586025b6 Mon Sep 17 00:00:00 2001 From: adriangohjw Date: Sun, 17 Nov 2024 02:25:07 +0800 Subject: [PATCH] move intercom into EnforceLoginStatePageWrapper --- .../EnforceLoginStatePageWrapper.tsx | 9 +++++++++ apps/studio/src/components/Intercom.tsx | 17 ----------------- apps/studio/src/pages/index.tsx | 5 +---- .../sites/[siteId]/collections/[resourceId].tsx | 5 +---- .../sites/[siteId]/folders/[folderId]/index.tsx | 5 +---- apps/studio/src/pages/sites/[siteId]/index.tsx | 5 +---- .../sites/[siteId]/links/[linkId]/index.tsx | 5 +---- .../sites/[siteId]/pages/[pageId]/index.tsx | 5 +---- .../sites/[siteId]/pages/[pageId]/settings.tsx | 5 +---- .../src/pages/sites/[siteId]/settings.tsx | 7 +------ 10 files changed, 17 insertions(+), 51 deletions(-) delete mode 100644 apps/studio/src/components/Intercom.tsx diff --git a/apps/studio/src/components/AuthWrappers/EnforceLoginStatePageWrapper.tsx b/apps/studio/src/components/AuthWrappers/EnforceLoginStatePageWrapper.tsx index 765d61751..2cce04210 100644 --- a/apps/studio/src/components/AuthWrappers/EnforceLoginStatePageWrapper.tsx +++ b/apps/studio/src/components/AuthWrappers/EnforceLoginStatePageWrapper.tsx @@ -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" @@ -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} } diff --git a/apps/studio/src/components/Intercom.tsx b/apps/studio/src/components/Intercom.tsx deleted file mode 100644 index 3b003d18a..000000000 --- a/apps/studio/src/components/Intercom.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import type { ReactNode } from "react" -import Intercom from "@intercom/messenger-js-sdk" - -import { env } from "~/env.mjs" - -interface WithIntercomWrapperProps { - children: ReactNode -} -export const WithIntercomWrapper = ({ children }: WithIntercomWrapperProps) => { - if (env.NEXT_PUBLIC_INTERCOM_APP_ID) { - Intercom({ - app_id: env.NEXT_PUBLIC_INTERCOM_APP_ID, - }) - } - - return children -} diff --git a/apps/studio/src/pages/index.tsx b/apps/studio/src/pages/index.tsx index 02f5f0962..55bacfebf 100644 --- a/apps/studio/src/pages/index.tsx +++ b/apps/studio/src/pages/index.tsx @@ -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" @@ -18,8 +17,6 @@ const DashboardPage: NextPageWithLayout = () => { ) } -DashboardPage.getLayout = (page: React.ReactNode) => { - return {AdminLayout(page)} -} +DashboardPage.getLayout = AdminLayout export default DashboardPage diff --git a/apps/studio/src/pages/sites/[siteId]/collections/[resourceId].tsx b/apps/studio/src/pages/sites/[siteId]/collections/[resourceId].tsx index e4fbe3190..a4d579de2 100644 --- a/apps/studio/src/pages/sites/[siteId]/collections/[resourceId].tsx +++ b/apps/studio/src/pages/sites/[siteId]/collections/[resourceId].tsx @@ -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" @@ -119,9 +118,7 @@ CollectionResourceListPage.getLayout = (page) => { return ( {AdminCmsSidebarLayout(page)} - } + page={AdminCmsSidebarLayout(page)} /> ) } diff --git a/apps/studio/src/pages/sites/[siteId]/folders/[folderId]/index.tsx b/apps/studio/src/pages/sites/[siteId]/folders/[folderId]/index.tsx index 9785339f3..4a1c28575 100644 --- a/apps/studio/src/pages/sites/[siteId]/folders/[folderId]/index.tsx +++ b/apps/studio/src/pages/sites/[siteId]/folders/[folderId]/index.tsx @@ -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" @@ -251,9 +250,7 @@ FolderPage.getLayout = (page) => { return ( {AdminCmsSidebarLayout(page)} - } + page={AdminCmsSidebarLayout(page)} /> ) } diff --git a/apps/studio/src/pages/sites/[siteId]/index.tsx b/apps/studio/src/pages/sites/[siteId]/index.tsx index 04eaaa260..7f1b21d9e 100644 --- a/apps/studio/src/pages/sites/[siteId]/index.tsx +++ b/apps/studio/src/pages/sites/[siteId]/index.tsx @@ -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" @@ -175,9 +174,7 @@ SitePage.getLayout = (page) => { return ( {AdminCmsSidebarLayout(page)} - } + page={AdminCmsSidebarLayout(page)} /> ) } diff --git a/apps/studio/src/pages/sites/[siteId]/links/[linkId]/index.tsx b/apps/studio/src/pages/sites/[siteId]/links/[linkId]/index.tsx index 6624ab928..5e0b72c81 100644 --- a/apps/studio/src/pages/sites/[siteId]/links/[linkId]/index.tsx +++ b/apps/studio/src/pages/sites/[siteId]/links/[linkId]/index.tsx @@ -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" @@ -30,8 +29,6 @@ export const EditLink = () => { ) } -EditLink.getLayout = (page: React.ReactNode) => { - return {LinkEditingLayout(page)} -} +EditLink.getLayout = LinkEditingLayout export default EditLink diff --git a/apps/studio/src/pages/sites/[siteId]/pages/[pageId]/index.tsx b/apps/studio/src/pages/sites/[siteId]/pages/[pageId]/index.tsx index fb8424d8f..e4148a681 100644 --- a/apps/studio/src/pages/sites/[siteId]/pages/[pageId]/index.tsx +++ b/apps/studio/src/pages/sites/[siteId]/pages/[pageId]/index.tsx @@ -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" @@ -64,9 +63,7 @@ EditPage.getLayout = (page) => { return ( {PageEditingLayout(page)} - } + page={PageEditingLayout(page)} /> ) } diff --git a/apps/studio/src/pages/sites/[siteId]/pages/[pageId]/settings.tsx b/apps/studio/src/pages/sites/[siteId]/pages/[pageId]/settings.tsx index 5575f63e6..deb0c951a 100644 --- a/apps/studio/src/pages/sites/[siteId]/pages/[pageId]/settings.tsx +++ b/apps/studio/src/pages/sites/[siteId]/pages/[pageId]/settings.tsx @@ -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" @@ -138,9 +137,7 @@ PageSettings.getLayout = (page) => { return ( {PageEditingLayout(page)} - } + page={PageEditingLayout(page)} /> ) } diff --git a/apps/studio/src/pages/sites/[siteId]/settings.tsx b/apps/studio/src/pages/sites/[siteId]/settings.tsx index 01edd1e63..7afb7e9f2 100644 --- a/apps/studio/src/pages/sites/[siteId]/settings.tsx +++ b/apps/studio/src/pages/sites/[siteId]/settings.tsx @@ -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" @@ -225,11 +224,7 @@ SiteSettingsPage.getLayout = (page) => { return ( - {AdminSidebarOnlyLayout(page)} - - } + page={AdminSidebarOnlyLayout(page)} /> ) }