Remove intercom from public booking pages (#1835)

* 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 <zomars@me.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/1807/head^2
hariombalhara 2022-02-16 20:56:48 +05:30 committed by GitHub
parent 228dea1308
commit 34c5360a4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View File

@ -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 = (
<SessionProvider session={session || undefined}>
<CustomI18nextProvider {...props}>{props.children}</CustomI18nextProvider>
</SessionProvider>
);
return (
<TelemetryProvider value={createTelemetryClient()}>
<IdProvider>
<DynamicIntercomProvider>
<SessionProvider session={session || undefined}>
<CustomI18nextProvider {...props}>{props.children}</CustomI18nextProvider>
</SessionProvider>
</DynamicIntercomProvider>
{isPublicPage ? (
RemainingProviders
) : (
<DynamicIntercomProvider>{RemainingProviders}</DynamicIntercomProvider>
)}
</IdProvider>
</TelemetryProvider>
);

View File

@ -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;
}