Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide intercom chat launcher by default #1539

Merged
merged 5 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/intercom-web": "^2.8.21",
"@types/jest": "^29.2.5",
"@types/node": "^17.0.36",
"@types/react": "18.0.9",
"@types/react": "^18.2.42",
"@types/react-dom": "18.0.5",
"@types/react-mentions": "^4.1.8",
"@types/testing-library__jest-dom": "^5.14.5",
Expand Down
27 changes: 15 additions & 12 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { QueryClientProvider } from "@tanstack/react-query";
import type { AppProps } from "next/app";
import React from "react";
import useDetermineAuthSystem from "../src/components/Authentication/useDetermineAuthSystem";
import SetupIntercom from "../src/components/Intercom/SetupIntercom";
import { queryClient } from "../src/query-client";
import "./global.css";

Expand All @@ -11,19 +12,21 @@ export default function MyApp({ Component, pageProps }: AppProps) {

return (
<QueryClientProvider client={queryClient}>
<div
id="root"
className="flex flex-col w-screen h-screen overflow-auto"
suppressHydrationWarning
>
{authProvider === "clerk" ? (
<ClerkProvider {...pageProps}>
<SetupIntercom>
<div
id="root"
className="flex flex-col w-screen h-screen overflow-auto"
suppressHydrationWarning
>
{authProvider === "clerk" ? (
<ClerkProvider {...pageProps}>
<Component {...pageProps} />
</ClerkProvider>
) : (
<Component {...pageProps} />
</ClerkProvider>
) : (
<Component {...pageProps} />
)}
</div>
)}
</div>
</SetupIntercom>
</QueryClientProvider>
);
}
47 changes: 22 additions & 25 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import AuthProviderWrapper from "./components/Authentication/AuthProviderWrapper
import { ErrorBoundary } from "./components/ErrorBoundary";
import { LogsIcon } from "./components/Icons/LogsIcon";
import { TopologyIcon } from "./components/Icons/TopologyIcon";
import SetupIntercom from "./components/Intercom/SetupIntercom";
import BootIntercom from "./components/Intercom/BootIntercom";
import JobsHistorySettingsPage from "./components/JobsHistory/JobsHistorySettingsPage";
import { SidebarLayout } from "./components/Layout";
import NotificationsPage from "./components/Notifications/NotificationsSettingsPage";
Expand Down Expand Up @@ -546,29 +546,26 @@ function SidebarWrapper() {

export function App() {
return (
<>
<Head prefix={"Home"} />
<BrowserRouter>
<Provider>
<AuthProviderWrapper>
<SetupIntercom>
<UserAccessStateContextProvider>
<FeatureFlagsContextProvider>
<HealthPageContextProvider>
<ConfigPageContextProvider>
<IncidentPageContextProvider>
<ReactTooltip />
<IncidentManagerRoutes sidebar={<SidebarWrapper />} />
<ReactQueryDevtools initialIsOpen={false} />
</IncidentPageContextProvider>
</ConfigPageContextProvider>
</HealthPageContextProvider>
</FeatureFlagsContextProvider>
</UserAccessStateContextProvider>
</SetupIntercom>
</AuthProviderWrapper>
</Provider>
</BrowserRouter>
</>
<BrowserRouter>
<Provider>
<AuthProviderWrapper>
<BootIntercom>
<UserAccessStateContextProvider>
<FeatureFlagsContextProvider>
<HealthPageContextProvider>
<ConfigPageContextProvider>
<IncidentPageContextProvider>
<ReactTooltip />
<IncidentManagerRoutes sidebar={<SidebarWrapper />} />
<ReactQueryDevtools initialIsOpen={false} />
</IncidentPageContextProvider>
</ConfigPageContextProvider>
</HealthPageContextProvider>
</FeatureFlagsContextProvider>
</UserAccessStateContextProvider>
</BootIntercom>
</AuthProviderWrapper>
</Provider>
</BrowserRouter>
);
}
13 changes: 11 additions & 2 deletions src/components/Authentication/Clerk/ClerkAuthContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AuthContext } from "../../../context";
import ErrorPage from "../../Errors/ErrorPage";
import FullPageSkeletonLoader from "../../SkeletonLoader/FullPageSkeletonLoader";
import InstanceCreationInProgress from "./InstanceCreationInProgress";
import BootIntercom from "../../Intercom/BootIntercom";

type AuthProviderWrapperProps = {
children: React.ReactNode;
Expand Down Expand Up @@ -37,7 +38,11 @@ export default function ClerkAuthContextProvider({
// if the organization backend is not yet created, we need to wait for it to
// be created before showing the UI
if (!backendURL) {
return <InstanceCreationInProgress />;
return (
<BootIntercom>
<InstanceCreationInProgress />
</BootIntercom>
);
}

// if the organization backend returns a 404 or a 5xx error, we need to wait
Expand All @@ -47,7 +52,11 @@ export default function ClerkAuthContextProvider({
(error.response?.status?.toString().startsWith("5") ||
error?.response?.status === 404)
) {
return <InstanceCreationInProgress />;
return (
<BootIntercom>
<InstanceCreationInProgress />
</BootIntercom>
);
}

if (isLoading && !payload) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OrganizationSwitcher, UserButton } from "@clerk/nextjs";
import { Loading } from "../../Loading";
import { HelpDropdown } from "../../../ui/MenuBar/HelpDropdown";

export default function InstanceCreationInProgress() {
return (
Expand All @@ -14,9 +15,10 @@ export default function InstanceCreationInProgress() {
<div className="w-full bg-gray-200 rounded-md h-12"></div>
</div>
<div className="flex flex-col flex-1 h-full">
<div className="flex flex-row h-auto w-full bg-gray-50 p-3 space-x-4 items-end border-b border-gray-300">
<div className="flex flex-row h-auto w-full bg-gray-50 p-3 gap-4 items-end border-b border-gray-300">
<div className="w-36 bg-gray-200 h-full rounded-md animate-pulse"></div>
<div className="flex-1"></div>
<HelpDropdown />
<OrganizationSwitcher
hidePersonal
createOrganizationMode="modal"
Expand Down
14 changes: 11 additions & 3 deletions src/components/Intercom/BootIntercom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function BootIntercomForClerk({ children }: Props) {
name: membership.organization.name
}))
});
}, [boot, clerkUser, user]);

return () => {
shutdown();
};
}, [boot, clerkUser, shutdown, user]);

// on sign out, shutdown intercom
useEffect(() => {
Expand All @@ -42,7 +46,7 @@ function BootIntercomForClerk({ children }: Props) {
}

function BootIntercomForKratos({ children }: Props) {
const { boot } = useIntercom();
const { boot, shutdown } = useIntercom();
const { user } = useContextUser();

useEffect(() => {
Expand All @@ -55,7 +59,11 @@ function BootIntercomForKratos({ children }: Props) {
imageUrl: user?.avatar
}
});
}, [boot, user]);

return () => {
shutdown();
};
}, [boot, shutdown, user]);

// eslint-disable-next-line react/jsx-no-useless-fragment
return <>{children}</>;
Expand Down
5 changes: 1 addition & 4 deletions src/components/Intercom/SetupIntercom.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { IntercomProvider } from "react-use-intercom";
import BootIntercom from "./BootIntercom";

const INTERCOM_APP_ID = process.env.NEXT_PUBLIC_INTERCOM_APP_ID;

function ProvideIntercom({ children }: Props) {
return (
<IntercomProvider appId={INTERCOM_APP_ID!}>
<BootIntercom>{children}</BootIntercom>
</IntercomProvider>
<IntercomProvider appId={INTERCOM_APP_ID!}>{children}S</IntercomProvider>
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/Layout/SearchLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HelpDropdown } from "../../ui/MenuBar/HelpDropdown";
import DashboardErrorBoundary from "../Errors/DashboardErrorBoundary";
import { RefreshButton } from "../RefreshButton";
import { UserProfileDropdown } from "../UserProfile/UserProfile";
Expand Down Expand Up @@ -26,7 +27,8 @@ export function SearchLayout({
<div className="flex items-center">
<div>{title}</div>
</div>
<div className="ml-4 flex items-center md:ml-6">
<div className="ml-4 flex gap-2 items-center md:ml-6">
<HelpDropdown />
{onRefresh && (
<RefreshButton onClick={onRefresh} animate={loading} />
)}
Expand Down
41 changes: 41 additions & 0 deletions src/ui/MenuBar/HelpDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Menu, Transition } from "@headlessui/react";
import { Fragment } from "react";
import { IoHelpOutline } from "react-icons/io5";
import { ClickableSvg } from "../../components/ClickableSvg/ClickableSvg";

export function HelpDropdown() {
return (
<Menu as="div" className="ml-3 relative flex-shrink-0">
<div>
<Menu.Button className="flex items-center text-sm rounded-full text-gray-400">
<ClickableSvg>
<IoHelpOutline size={24} />
</ClickableSvg>
</Menu.Button>
</div>
{/* @ts-ignore */}
<Transition
as={Fragment as any}
enter="transition ease-out duration-100"
enterFrom="transform opacity-0 scale-95"
enterTo="transform opacity-100 scale-100"
leave="transition ease-in duration-75"
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
<Menu.Items className="absolute bg-white focus:outline-none mt-2 opacity-100 origin-top-right right-0 ring-1 ring-black ring-opacity-5 rounded-md scale-100 shadow-md transform w-64">
<Menu.Item>
<a
href="https://docs.flanksource.com/"
target="_blank"
className="block py-2 px-4 text-sm text-gray-700 space-x-2 hover:bg-gray-50 hover:text-gray-900 border-0 border-b border-gray-200"
rel="noreferrer"
>
<span>Docs</span>
</a>
</Menu.Item>
</Menu.Items>
</Transition>
</Menu>
);
}
Loading