Skip to content

Commit

Permalink
CAL-1673: Use dark/light colors from user profile settings in booker (#…
Browse files Browse the repository at this point in the history
…8905)

* CAL-1673: Use dark/light colors from user profile settings in booker

* Use system theme for dynamic booking, instead of theme set by first user.
  • Loading branch information
JeroenReumkens committed May 18, 2023
1 parent f20a5df commit 175fc4f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/features/bookings/Booker/Booker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import StickyBox from "react-sticky-box";
import { shallow } from "zustand/shallow";

import classNames from "@calcom/lib/classNames";
import useGetBrandingColours from "@calcom/lib/getBrandColours";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
import { ToggleGroup, useCalcomTheme } from "@calcom/ui";
import { ToggleGroup } from "@calcom/ui";
import { Calendar, Columns, Grid } from "@calcom/ui/components/icon";

import { AvailableTimeSlots } from "./components/AvailableTimeSlots";
Expand All @@ -23,20 +22,13 @@ import { fadeInLeft, getBookerSizeClassNames, useBookerResizeAnimation } from ".
import { useBookerStore, useInitializeBookerStore } from "./store";
import type { BookerLayout, BookerProps } from "./types";
import { useEvent } from "./utils/event";
import { useBrandColors } from "./utils/use-brand-colors";

const PoweredBy = dynamic(() => import("@calcom/ee/components/PoweredBy"));
const DatePicker = dynamic(() => import("./components/DatePicker").then((mod) => mod.DatePicker), {
ssr: false,
});

const useBrandColors = ({ brandColor, darkBrandColor }: { brandColor?: string; darkBrandColor?: string }) => {
const brandTheme = useGetBrandingColours({
lightVal: brandColor,
darkVal: darkBrandColor,
});
useCalcomTheme(brandTheme);
};

const BookerComponent = ({ username, eventSlug, month, rescheduleBooking }: BookerProps) => {
const { t } = useLocale();
const isMobile = useMediaQuery("(max-width: 768px)");
Expand All @@ -61,6 +53,7 @@ const BookerComponent = ({ username, eventSlug, month, rescheduleBooking }: Book
useBrandColors({
brandColor: event.data?.profile.brandColor,
darkBrandColor: event.data?.profile.darkBrandColor,
theme: event.data?.profile.theme,
});

useInitializeBookerStore({
Expand Down
26 changes: 26 additions & 0 deletions packages/features/bookings/Booker/utils/use-brand-colors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect } from "react";

import useGetBrandingColours from "@calcom/lib/getBrandColours";
import useTheme from "@calcom/lib/hooks/useTheme";
import { useCalcomTheme } from "@calcom/ui";

export const useBrandColors = ({
brandColor,
darkBrandColor,
theme,
}: {
brandColor?: string;
darkBrandColor?: string;
theme?: string | null;
}) => {
const brandTheme = useGetBrandingColours({
lightVal: brandColor,
darkVal: darkBrandColor,
});
useCalcomTheme(brandTheme);
const { setTheme } = useTheme(theme);

useEffect(() => {
if (theme) setTheme(theme);
}, [setTheme, theme]);
};
4 changes: 4 additions & 0 deletions packages/features/eventtypes/lib/getPublicEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
weekStart: true,
brandColor: true,
darkBrandColor: true,
theme: true,
},
},
},
Expand All @@ -80,6 +81,7 @@ export const getPublicEvent = async (username: string, eventSlug: string, prisma
metadata: true,
brandColor: true,
darkBrandColor: true,
theme: true,
},
});

Expand Down Expand Up @@ -113,6 +115,7 @@ export const getPublicEvent = async (username: string, eventSlug: string, prisma
image: `${WEBAPP_URL}/${users[0].username}/avatar.png`,
brandColor: users[0].brandColor,
darkBrandColor: users[0].darkBrandColor,
theme: null,
},
};
}
Expand Down Expand Up @@ -179,6 +182,7 @@ function getProfileFromEvent(event: Event) {
logo: !team ? undefined : team.logo,
brandColor: profile.brandColor,
darkBrandColor: profile.darkBrandColor,
theme: profile.theme,
};
}

Expand Down

1 comment on commit 175fc4f

@vercel
Copy link

@vercel vercel bot commented on 175fc4f May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./apps/storybook

cal-com-storybook.vercel.app
timelessui.com
www.timelessui.com
ui-git-main-cal.vercel.app
ui-cal.vercel.app
ui.cal.com

Please sign in to comment.