Skip to content

Commit

Permalink
useIsThemeSupported hook (calcom#18746)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj authored Jan 20, 2025
1 parent 1f91fe8 commit 4424b2a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 0 additions & 1 deletion apps/web/app/layoutHOC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export function WithLayout<T extends Record<string, any>>({
requiresLicense={requiresLicense || !!(Page && "requiresLicense" in Page && Page.requiresLicense)}
nonce={nonce}
themeBasis={null}
isThemeSupported={Page && "isThemeSupported" in Page ? (Page.isThemeSupported as boolean) : undefined}
isBookingPage={isBookingPage || !!(Page && "isBookingPage" in Page && Page.isBookingPage)}
{...props}>
{pageWithServerLayout}
Expand Down
1 change: 0 additions & 1 deletion apps/web/components/PageWrapperAppDir.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export type PageWrapperProps = Readonly<{
nonce: string | undefined;
themeBasis: string | null;
dehydratedState?: DehydratedState;
isThemeSupported?: boolean;
isBookingPage?: boolean;
i18n?: SSRConfig;
}>;
Expand Down
10 changes: 5 additions & 5 deletions apps/web/lib/app-providers-app-dir.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FeatureProvider } from "@calcom/features/flags/context/provider";
import { useFlags } from "@calcom/features/flags/hooks";

import useIsBookingPage from "@lib/hooks/useIsBookingPage";
import useIsThemeSupported from "@lib/hooks/useIsThemeSupported";
import PlainChat from "@lib/plain/plainChat";
import type { WithLocaleProps } from "@lib/withLocale";
import type { WithNonceProps } from "@lib/withNonce";
Expand Down Expand Up @@ -48,7 +49,6 @@ export type AppProps = Omit<
> & {
Component: NextAppProps["Component"] & {
requiresLicense?: boolean;
isThemeSupported?: boolean;
isBookingPage?: boolean | ((arg: { router: NextAppProps["router"] }) => boolean);
getLayout?: (page: React.ReactElement) => ReactNode;
PageWrapper?: (props: AppProps) => JSX.Element;
Expand Down Expand Up @@ -129,7 +129,7 @@ type CalcomThemeProps = Readonly<{
themeBasis: string | null;
nonce: string | undefined;
children: React.ReactNode;
isThemeSupported?: boolean;
isThemeSupported: boolean;
}>;

const CalcomThemeProvider = (props: CalcomThemeProps) => {
Expand Down Expand Up @@ -196,8 +196,7 @@ function getThemeProviderProps({
}) {
const themeSupport = props.isBookingPage
? ThemeSupport.Booking
: // if isThemeSupported is explicitly false, we don't use theme there
props.isThemeSupported === false
: props.isThemeSupported === false
? ThemeSupport.None
: ThemeSupport.App;

Expand Down Expand Up @@ -263,6 +262,7 @@ function OrgBrandProvider({ children }: { children: React.ReactNode }) {
const AppProviders = (props: PageWrapperProps) => {
// No need to have intercom on public pages - Good for Page Performance
const isBookingPage = useIsBookingPage();
const isThemeSupported = useIsThemeSupported();

const RemainingProviders = (
<EventCollectionProvider options={{ apiPath: "/api/collect-events" }}>
Expand All @@ -273,7 +273,7 @@ const AppProviders = (props: PageWrapperProps) => {
<CalcomThemeProvider
themeBasis={props.themeBasis}
nonce={props.nonce}
isThemeSupported={/* undefined gets treated as true */ props.isThemeSupported}
isThemeSupported={isThemeSupported}
isBookingPage={props.isBookingPage || isBookingPage}>
<FeatureFlagsProvider>
<OrgBrandProvider>{props.children}</OrgBrandProvider>
Expand Down
14 changes: 14 additions & 0 deletions apps/web/lib/hooks/useIsThemeSupported.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client";

import { usePathname } from "next/navigation";

const THEME_UNSUPPORTED_ROUTES = ["/auth/setup"];

export default function useIsThemeSupported(): boolean {
const pathname = usePathname();

// Check if current pathname matches any unsupported route
const isUnsupportedRoute = THEME_UNSUPPORTED_ROUTES.some((route) => pathname?.startsWith(route));

return !isUnsupportedRoute;
}

0 comments on commit 4424b2a

Please sign in to comment.