From 34c5360a4d0020b1e974f91ef412e20927d37f87 Mon Sep 17 00:00:00 2001 From: hariombalhara Date: Wed, 16 Feb 2022 20:56:48 +0530 Subject: [PATCH] Remove intercom from public booking pages (#1835) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove intercom from public pages * remove from success and cancel pages as well * remove from Reschedule page as well * Fix comment Co-authored-by: Omar López Co-authored-by: Peer Richelsen Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- apps/web/lib/app-providers.tsx | 19 ++++++++++++++----- apps/web/lib/hooks/usePublicPage.ts | 9 +++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 apps/web/lib/hooks/usePublicPage.ts diff --git a/apps/web/lib/app-providers.tsx b/apps/web/lib/app-providers.tsx index 47280b98b9..c8381599f1 100644 --- a/apps/web/lib/app-providers.tsx +++ b/apps/web/lib/app-providers.tsx @@ -6,6 +6,7 @@ import React, { ComponentProps, ReactNode } from "react"; import DynamicIntercomProvider from "@ee/lib/intercom/providerDynamic"; +import usePublicPage from "@lib/hooks/usePublicPage"; import { createTelemetryClient, TelemetryProvider } from "@lib/telemetry"; import { trpc } from "./trpc"; @@ -40,14 +41,22 @@ const CustomI18nextProvider = (props: AppPropsWithChildren) => { const AppProviders = (props: AppPropsWithChildren) => { const session = trpc.useQuery(["viewer.session"]).data; + // No need to have intercom on public pages - Good for Page Performance + const isPublicPage = usePublicPage(); + const RemainingProviders = ( + + {props.children} + + ); + return ( - - - {props.children} - - + {isPublicPage ? ( + RemainingProviders + ) : ( + {RemainingProviders} + )} ); diff --git a/apps/web/lib/hooks/usePublicPage.ts b/apps/web/lib/hooks/usePublicPage.ts new file mode 100644 index 0000000000..90c88c90c1 --- /dev/null +++ b/apps/web/lib/hooks/usePublicPage.ts @@ -0,0 +1,9 @@ +import { useRouter } from "next/router"; + +export default function usePublicPage() { + const router = useRouter(); + const isPublicPage = ["/[user]", "/success", "/cancel", "/reschedule"].find((route) => + router.pathname.startsWith(route) + ); + return isPublicPage; +}