Fix/Keep themes in peace across embed and booking pages and App (#8108)

This commit is contained in:
Hariom Balhara authored and GitHub committed 2023-04-17 17:46:54 +05:30
1 parent 39c48e7f79
commit 2c96444058
20 files changed
+86 -49

No files matched your search

@@ -332,7 +332,6 @@ export default function FormEditPage({
/>
);
}
FormEditPage.isThemeSupported = true;
FormEditPage.getLayout = (page: React.ReactElement) => {
return (
@@ -252,8 +252,6 @@ export default function RoutingForms({
);
}
RoutingForms.isThemeSupported = true;
RoutingForms.getLayout = (page: React.ReactElement) => {
return <Shell withoutMain={true}>{page}</Shell>;
};
@@ -197,8 +197,6 @@ export default function ReporterWrapper({
);
}
ReporterWrapper.isThemeSupported = true;
ReporterWrapper.getLayout = (page: React.ReactElement) => {
return (
<Shell backPath="/apps/routing-forms/forms" withoutMain={true}>
@@ -523,7 +523,6 @@ export default function RouteBuilder({
/>
);
}
RouteBuilder.isThemeSupported = true;
RouteBuilder.getLayout = (page: React.ReactElement) => {
return (
@@ -26,8 +26,6 @@ export default function Router({ form, message }: inferSSRProps<typeof getServer
);
}
Router.isThemeSupported = true;
const querySchema = z
.object({
form: z.string(),
@@ -165,7 +165,7 @@ export default function RoutingLink(props: inferSSRProps<typeof getServerSidePro
return <RoutingForm {...props} />;
}
RoutingLink.isThemeSupported = true;
RoutingLink.isBookingPage = true;
export const getServerSideProps = async function getServerSideProps(
context: AppGetServerSidePropsContext,
+2 -2
View File
@@ -22,7 +22,6 @@ import classNames from "@calcom/lib/classNames";
import { APP_NAME, DESKTOP_APP_LINK, JOIN_SLACK, ROADMAP, WEBAPP_URL } from "@calcom/lib/constants";
import getBrandColours from "@calcom/lib/getBrandColours";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import useTheme from "@calcom/lib/hooks/useTheme";
import { isKeyInObject } from "@calcom/lib/isKeyInObject";
import { trpc } from "@calcom/trpc/react";
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
@@ -231,7 +230,8 @@ export default function Shell(props: LayoutProps) {
// if a page is unauthed and isPublic is true, the redirect does not happen.
useRedirectToLoginIfUnauthenticated(props.isPublic);
useRedirectToOnboardingIfNeeded();
useTheme();
// System Theme is automatically supported using ThemeProvider. If we intend to use user theme throughout the app we need to uncomment this.
// useTheme(profile.theme);
useBrandColors();
return !props.isPublic ? (
+17 -12
View File
@@ -4,23 +4,28 @@ import { useEffect } from "react";
import { useEmbedTheme } from "@calcom/embed-core/embed-iframe";
import type { Maybe } from "@calcom/trpc/server";
// makes sure the ui doesn't flash
export default function useTheme(theme?: Maybe<string>) {
/**
* It should be called once per route and only if you want to use app configured theme. System only theme works automatically by using ThemeProvider
* Calling it without a theme will just returns the current theme.
* It handles embed configured theme as well.
*/
export default function useTheme(themeToSet?: Maybe<string>) {
const { resolvedTheme, setTheme, forcedTheme, theme: activeTheme } = useNextTheme();
const embedTheme = useEmbedTheme();
// Embed UI configuration takes more precedence over App Configuration
const currentTheme = embedTheme || theme || "system";
useEffect(() => {
if (currentTheme !== activeTheme && typeof currentTheme === "string") {
setTheme(currentTheme);
}
// If themeToSet is not provided the purpose is to just return the current the current values
if (themeToSet === undefined) return;
// Embed theme takes precedence over theme configured in app. This allows embeds to be themed differently
const finalThemeToSet = embedTheme || themeToSet || "system";
if (!finalThemeToSet || finalThemeToSet === activeTheme) return;
console.log("Setting theme", { resolvedTheme, finalThemeToSet, activeTheme, forcedTheme });
setTheme(finalThemeToSet);
// eslint-disable-next-line react-hooks/exhaustive-deps -- we do not want activeTheme to re-render this effect
}, [currentTheme, setTheme]);
useEffect(() => {
if (forcedTheme) setTheme(forcedTheme);
}, [forcedTheme, setTheme]);
}, [themeToSet, setTheme]);
return {
resolvedTheme,