feat: Settings for dashboard theme that is separate from system (#13779)
* feat(db): add new col: user appTheme * feat(event-types page): apply appTheme color * add appTheme for trpc * feat: mutate main page theme * feat: add english translation for app theme update section * modify keys in common (en) * add woring * Revert yarn.lock to its state before unintended changes * feat(i18n): add back the i18n string (for dark/light mode switching) * refactor: refactor ThemeLabel * fix: add new user field "appTheme" to test files * chore: modify TODO comment * chore: update common.json (en) for "theme" since we had appTheme now, I think it's better to update the wording here to avoid confusion * fix: update button's data-testid to fix e2e test error * chore: remove comment * fix: fix brand-color-not-apply bug * solve type error * fix: fix type error * fix: use correct storageKey for booker / dashboard * fix: tidy up * fix: skeleton --------- Co-authored-by: swh00tw <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
14 files changed
+126
-18
No files matched your search
@@ -4,23 +4,24 @@ interface ThemeLabelProps {
|
||||
label: string;
|
||||
defaultChecked?: boolean;
|
||||
register: any;
|
||||
fieldName?: string;
|
||||
}
|
||||
|
||||
export default function ThemeLabel(props: ThemeLabelProps) {
|
||||
const { variant, label, value, defaultChecked, register } = props;
|
||||
const { variant, label, value, defaultChecked, register, fieldName = "theme" } = props;
|
||||
|
||||
return (
|
||||
<label
|
||||
className="relative mb-4 flex-1 cursor-pointer text-center last:mb-0 last:mr-0 sm:mb-0 sm:mr-4"
|
||||
htmlFor={`theme-${variant}`}
|
||||
data-testid={`theme-${variant}`}>
|
||||
htmlFor={`${fieldName}-${variant}`}
|
||||
data-testid={`${fieldName}-${variant}`}>
|
||||
<input
|
||||
className="peer absolute left-8 top-8"
|
||||
type="radio"
|
||||
value={value}
|
||||
id={`theme-${variant}`}
|
||||
id={`${fieldName}-${variant}`}
|
||||
defaultChecked={defaultChecked}
|
||||
{...register("theme")}
|
||||
{...register(fieldName)}
|
||||
/>
|
||||
<div className="ring-inverted relative z-10 rounded-lg ring-offset-2 transition-all peer-checked:ring-2">
|
||||
<img
|
||||
|
||||
@@ -48,6 +48,7 @@ import { useFormbricks } from "@calcom/lib/formbricks-client";
|
||||
import getBrandColours from "@calcom/lib/getBrandColours";
|
||||
import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import useTheme from "@calcom/lib/hooks/useTheme";
|
||||
import { isKeyInObject } from "@calcom/lib/isKeyInObject";
|
||||
import type { User } from "@calcom/prisma/client";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
@@ -329,13 +330,14 @@ type LayoutProps = {
|
||||
hideHeadingOnMobile?: boolean;
|
||||
};
|
||||
|
||||
const useBrandColors = () => {
|
||||
const useAppTheme = () => {
|
||||
const { data: user } = useMeQuery();
|
||||
const brandTheme = getBrandColours({
|
||||
lightVal: user?.brandColor,
|
||||
darkVal: user?.darkBrandColor,
|
||||
});
|
||||
useCalcomTheme(brandTheme);
|
||||
useTheme(user?.appTheme);
|
||||
};
|
||||
|
||||
const KBarWrapper = ({ children, withKBar = false }: { withKBar: boolean; children: React.ReactNode }) =>
|
||||
@@ -361,9 +363,7 @@ export default function Shell(props: LayoutProps) {
|
||||
// if a page is unauthed and isPublic is true, the redirect does not happen.
|
||||
useRedirectToLoginIfUnauthenticated(props.isPublic);
|
||||
useRedirectToOnboardingIfNeeded();
|
||||
// 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();
|
||||
useAppTheme();
|
||||
|
||||
return !props.isPublic ? (
|
||||
<KBarWrapper withKBar>
|
||||
|
||||
@@ -234,6 +234,7 @@ export const buildUser = <T extends Partial<UserPayload>>(
|
||||
selectedCalendars: [],
|
||||
startTime: 0,
|
||||
theme: null,
|
||||
appTheme: null,
|
||||
timeFormat: null,
|
||||
trialEndsAt: null,
|
||||
twoFactorEnabled: false,
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "appTheme" TEXT;
|
||||
@@ -221,7 +221,9 @@ model User {
|
||||
// </DEPRECATED>
|
||||
bufferTime Int @default(0)
|
||||
hideBranding Boolean @default(false)
|
||||
// TODO: should be renamed since it only affects the booking page
|
||||
theme String?
|
||||
appTheme String?
|
||||
createdDate DateTime @default(now()) @map(name: "created")
|
||||
trialEndsAt DateTime?
|
||||
eventTypes EventType[] @relation("user_eventtype")
|
||||
|
||||
@@ -45,6 +45,7 @@ export async function getUserFromSession(ctx: TRPCContextInner, session: Maybe<S
|
||||
defaultScheduleId: true,
|
||||
bufferTime: true,
|
||||
theme: true,
|
||||
appTheme: true,
|
||||
createdDate: true,
|
||||
hideBranding: true,
|
||||
twoFactorEnabled: true,
|
||||
|
||||
@@ -54,6 +54,7 @@ export const meHandler = async ({ ctx }: MeOptions) => {
|
||||
bio: user.bio,
|
||||
weekStart: user.weekStart,
|
||||
theme: user.theme,
|
||||
appTheme: user.appTheme,
|
||||
hideBranding: user.hideBranding,
|
||||
metadata: user.metadata,
|
||||
defaultBookerLayouts: user.defaultBookerLayouts,
|
||||
|
||||
@@ -23,6 +23,7 @@ export const ZUpdateProfileInputSchema = z.object({
|
||||
brandColor: z.string().optional(),
|
||||
darkBrandColor: z.string().optional(),
|
||||
theme: z.string().optional().nullable(),
|
||||
appTheme: z.string().optional().nullable(),
|
||||
completedOnboarding: z.boolean().optional(),
|
||||
locale: z.string().optional(),
|
||||
timeFormat: z.number().optional(),
|
||||
|
||||
Reference in new issue
Block a user