Improves UI stability of availability page. No CLS now. (#3347)
This commit is contained in:
1 parent
b1e4c23adc
commit
ebd4750f2d
11 files changed
+87
-78
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from "react";
|
import Head from "next/head";
|
||||||
|
|
||||||
import { useBrandColors } from "@calcom/embed-core/embed-iframe";
|
import { useBrandColors } from "@calcom/embed-core/embed-iframe";
|
||||||
|
|
||||||
@@ -238,54 +238,32 @@ const BrandColor = ({
|
|||||||
? darkVal
|
? darkVal
|
||||||
: "#" + darkVal
|
: "#" + darkVal
|
||||||
: fallBackHex(darkVal, true);
|
: fallBackHex(darkVal, true);
|
||||||
useEffect(() => {
|
return (
|
||||||
document.documentElement.style.setProperty(
|
<Head>
|
||||||
"--booking-highlight-color",
|
<style>
|
||||||
embedBrandingColors.highlightColor || "#10B981" // green--500
|
{`body {
|
||||||
|
/* green--500*/
|
||||||
|
--booking-highlight-color: ${embedBrandingColors.highlightColor || "#10B981"};
|
||||||
|
/* gray--200 */
|
||||||
|
--booking-lightest-color: ${embedBrandingColors.lightestColor || "#E1E1E1"};
|
||||||
|
/* gray--400 */
|
||||||
|
--booking-lighter-color: ${embedBrandingColors.lighterColor || "#ACACAC"};
|
||||||
|
/* gray--500 */
|
||||||
|
--booking-light-color: ${embedBrandingColors.lightColor || "#888888"};
|
||||||
|
/* gray--600 */
|
||||||
|
--booking-median-color: ${embedBrandingColors.medianColor || "#494949"};
|
||||||
|
/* gray--800 */
|
||||||
|
--booking-dark-color: ${embedBrandingColors.darkColor || "#313131"};
|
||||||
|
/* gray--900 */
|
||||||
|
--booking-darker-color: ${embedBrandingColors.darkerColor || "#292929"};
|
||||||
|
--brand-color: ${lightVal};
|
||||||
|
--brand-text-color: ${getContrastingTextColor(lightVal, true)};
|
||||||
|
--brand-color-dark-mode: ${darkVal};
|
||||||
|
--brand-text-color-dark-mode: ${getContrastingTextColor(darkVal, true)};
|
||||||
|
`}
|
||||||
|
</style>
|
||||||
|
</Head>
|
||||||
);
|
);
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--booking-lightest-color",
|
|
||||||
embedBrandingColors.lightestColor || "#E1E1E1" // gray--200
|
|
||||||
);
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--booking-lighter-color",
|
|
||||||
embedBrandingColors.lighterColor || "#ACACAC" // gray--400
|
|
||||||
);
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--booking-light-color",
|
|
||||||
embedBrandingColors.lightColor || "#888888" // gray--500
|
|
||||||
);
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--booking-median-color",
|
|
||||||
embedBrandingColors.medianColor || "#494949" // gray--600
|
|
||||||
);
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--booking-dark-color",
|
|
||||||
embedBrandingColors.darkColor || "#313131" // gray--800
|
|
||||||
);
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--booking-darker-color",
|
|
||||||
embedBrandingColors.darkerColor || "#292929" // gray--900
|
|
||||||
);
|
|
||||||
document.documentElement.style.setProperty("--brand-color", lightVal);
|
|
||||||
document.documentElement.style.setProperty("--brand-text-color", getContrastingTextColor(lightVal, true));
|
|
||||||
document.documentElement.style.setProperty("--brand-color-dark-mode", darkVal);
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--brand-text-color-dark-mode",
|
|
||||||
getContrastingTextColor(darkVal, true)
|
|
||||||
);
|
|
||||||
}, [
|
|
||||||
embedBrandingColors.highlightColor,
|
|
||||||
embedBrandingColors.lightestColor,
|
|
||||||
embedBrandingColors.lighterColor,
|
|
||||||
embedBrandingColors.lightColor,
|
|
||||||
embedBrandingColors.medianColor,
|
|
||||||
embedBrandingColors.darkColor,
|
|
||||||
embedBrandingColors.darkerColor,
|
|
||||||
lightVal,
|
|
||||||
darkVal,
|
|
||||||
]);
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default BrandColor;
|
export default BrandColor;
|
||||||
@@ -113,7 +113,7 @@ const useSlots = ({
|
|||||||
eventTypeId: number;
|
eventTypeId: number;
|
||||||
startTime?: Dayjs;
|
startTime?: Dayjs;
|
||||||
endTime?: Dayjs;
|
endTime?: Dayjs;
|
||||||
timeZone: string;
|
timeZone?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const { data, isLoading, isIdle } = trpc.useQuery(
|
const { data, isLoading, isIdle } = trpc.useQuery(
|
||||||
[
|
[
|
||||||
@@ -150,7 +150,7 @@ const SlotPicker = ({
|
|||||||
}: {
|
}: {
|
||||||
eventType: Pick<EventType, "id" | "schedulingType" | "slug">;
|
eventType: Pick<EventType, "id" | "schedulingType" | "slug">;
|
||||||
timeFormat: string;
|
timeFormat: string;
|
||||||
timeZone: string;
|
timeZone?: string;
|
||||||
seatsPerTimeSlot?: number;
|
seatsPerTimeSlot?: number;
|
||||||
recurringEventCount?: number;
|
recurringEventCount?: number;
|
||||||
weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
||||||
@@ -198,12 +198,10 @@ const SlotPicker = ({
|
|||||||
<>
|
<>
|
||||||
<DatePicker
|
<DatePicker
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
className={
|
className={classNames(
|
||||||
"mt-8 w-full sm:mt-0 sm:min-w-[455px] " +
|
"mt-8 w-full sm:mt-0 sm:min-w-[455px]",
|
||||||
(selectedDate
|
selectedDate ? "sm:w-1/2 sm:border-r sm:pl-4 sm:pr-6 sm:dark:border-gray-700 md:w-1/3 " : "sm:pl-4"
|
||||||
? "sm:w-1/2 sm:border-r sm:pl-4 sm:pr-6 sm:dark:border-gray-700 md:w-1/3 "
|
)}
|
||||||
: "sm:pl-4")
|
|
||||||
}
|
|
||||||
includedDates={Object.keys(slots).filter((k) => slots[k].length > 0)}
|
includedDates={Object.keys(slots).filter((k) => slots[k].length > 0)}
|
||||||
locale={isLocaleReady ? i18n.language : "en"}
|
locale={isLocaleReady ? i18n.language : "en"}
|
||||||
selected={selectedDate}
|
selected={selectedDate}
|
||||||
@@ -668,19 +666,12 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
)*/}
|
)*/}
|
||||||
</div>
|
</div>
|
||||||
{timeZone && (
|
|
||||||
<SlotPicker
|
<SlotPicker
|
||||||
weekStart={
|
weekStart={
|
||||||
typeof profile.weekStart === "string"
|
typeof profile.weekStart === "string"
|
||||||
? ([
|
? (["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"].indexOf(
|
||||||
"Sunday",
|
profile.weekStart
|
||||||
"Monday",
|
) as 0 | 1 | 2 | 3 | 4 | 5 | 6)
|
||||||
"Tuesday",
|
|
||||||
"Wednesday",
|
|
||||||
"Thursday",
|
|
||||||
"Friday",
|
|
||||||
"Saturday",
|
|
||||||
].indexOf(profile.weekStart) as 0 | 1 | 2 | 3 | 4 | 5 | 6)
|
|
||||||
: profile.weekStart /* Allows providing weekStart as number */
|
: profile.weekStart /* Allows providing weekStart as number */
|
||||||
}
|
}
|
||||||
eventType={eventType}
|
eventType={eventType}
|
||||||
@@ -689,7 +680,6 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
|
|||||||
seatsPerTimeSlot={eventType.seatsPerTimeSlot || undefined}
|
seatsPerTimeSlot={eventType.seatsPerTimeSlot || undefined}
|
||||||
recurringEventCount={recurringEventCount}
|
recurringEventCount={recurringEventCount}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{(!eventType.users[0] || !isBrandingHidden(eventType.users[0])) && !isEmbed && <PoweredByCal />}
|
{(!eventType.users[0] || !isBrandingHidden(eventType.users[0])) && !isEmbed && <PoweredByCal />}
|
||||||
|
|||||||
@@ -492,10 +492,13 @@ const BookingPage = ({
|
|||||||
<AvatarGroup
|
<AvatarGroup
|
||||||
border="border-2 border-white dark:border-gray-800"
|
border="border-2 border-white dark:border-gray-800"
|
||||||
size={14}
|
size={14}
|
||||||
items={[{ image: profile.image || "", alt: profile.name || "" }].concat(
|
items={[
|
||||||
|
{ image: profile.image || "", alt: profile.name || "", title: profile.name || "" },
|
||||||
|
].concat(
|
||||||
eventType.users
|
eventType.users
|
||||||
.filter((user) => user.name !== profile.name)
|
.filter((user) => user.name !== profile.name)
|
||||||
.map((user) => ({
|
.map((user) => ({
|
||||||
|
title: user.name || "",
|
||||||
image: user.avatar || "",
|
image: user.avatar || "",
|
||||||
alt: user.name || "",
|
alt: user.name || "",
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ export type AvatarProps = {
|
|||||||
gravatarFallbackMd5?: string;
|
gravatarFallbackMd5?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use AvatarSSR instead. Once, there is no usage of Avatar, AvatarSSR can be renamed.
|
||||||
|
*/
|
||||||
export default function Avatar(props: AvatarProps) {
|
export default function Avatar(props: AvatarProps) {
|
||||||
const { imageSrc, gravatarFallbackMd5, size, alt, title } = props;
|
const { imageSrc, gravatarFallbackMd5, size, alt, title } = props;
|
||||||
const className = classNames("rounded-full", props.className, size && `h-${size} w-${size}`);
|
const className = classNames("rounded-full", props.className, size && `h-${size} w-${size}`);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import React from "react";
|
|||||||
import classNames from "@lib/classNames";
|
import classNames from "@lib/classNames";
|
||||||
|
|
||||||
import Avatar from "@components/ui/Avatar";
|
import Avatar from "@components/ui/Avatar";
|
||||||
|
import { AvatarSSR } from "@components/ui/AvatarSSR";
|
||||||
|
|
||||||
export type AvatarGroupProps = {
|
export type AvatarGroupProps = {
|
||||||
border?: string; // this needs to be the color of the parent container background, i.e.: border-white dark:border-gray-900
|
border?: string; // this needs to be the color of the parent container background, i.e.: border-white dark:border-gray-900
|
||||||
@@ -23,7 +24,7 @@ export const AvatarGroup = function AvatarGroup(props: AvatarGroupProps) {
|
|||||||
if (item.image != null) {
|
if (item.image != null) {
|
||||||
return (
|
return (
|
||||||
<li key={idx} className="-mr-2 inline-block">
|
<li key={idx} className="-mr-2 inline-block">
|
||||||
<Avatar
|
<AvatarSSR
|
||||||
className={props.border}
|
className={props.border}
|
||||||
imageSrc={item.image}
|
imageSrc={item.image}
|
||||||
title={item.title}
|
title={item.title}
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
import { User } from "@prisma/client";
|
import { User } from "@prisma/client";
|
||||||
|
import * as Tooltip from "@radix-ui/react-tooltip";
|
||||||
|
|
||||||
import classNames from "@lib/classNames";
|
import classNames from "@lib/classNames";
|
||||||
|
|
||||||
export type AvatarProps = {
|
export type AvatarProps = (
|
||||||
|
| {
|
||||||
user: Pick<User, "name" | "username" | "avatar"> & { emailMd5?: string };
|
user: Pick<User, "name" | "username" | "avatar"> & { emailMd5?: string };
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
user?: null;
|
||||||
|
imageSrc: string;
|
||||||
|
}
|
||||||
|
) & {
|
||||||
className?: string;
|
className?: string;
|
||||||
size?: number;
|
size?: number;
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -16,18 +24,38 @@ function defaultAvatarSrc(md5: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// An SSR Supported version of Avatar component.
|
// An SSR Supported version of Avatar component.
|
||||||
// FIXME: title support is missing
|
|
||||||
export function AvatarSSR(props: AvatarProps) {
|
export function AvatarSSR(props: AvatarProps) {
|
||||||
const { user, size } = props;
|
const { size, title } = props;
|
||||||
|
|
||||||
|
let imgSrc = "";
|
||||||
|
let alt: string = props.alt;
|
||||||
|
|
||||||
|
if (props.user) {
|
||||||
|
const user = props.user;
|
||||||
const nameOrUsername = user.name || user.username || "";
|
const nameOrUsername = user.name || user.username || "";
|
||||||
const className = classNames("rounded-full", props.className, size && `h-${size} w-${size}`);
|
alt = alt || nameOrUsername;
|
||||||
let imgSrc;
|
|
||||||
const alt = props.alt || nameOrUsername;
|
|
||||||
if (user.avatar) {
|
if (user.avatar) {
|
||||||
imgSrc = user.avatar;
|
imgSrc = user.avatar;
|
||||||
} else if (user.emailMd5) {
|
} else if (user.emailMd5) {
|
||||||
imgSrc = defaultAvatarSrc(user.emailMd5);
|
imgSrc = defaultAvatarSrc(user.emailMd5);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
} else {
|
||||||
return imgSrc ? <img alt={alt} className={className} src={imgSrc} /> : null;
|
imgSrc = props.imageSrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
const className = classNames("rounded-full", props.className, size && `h-${size} w-${size}`);
|
||||||
|
|
||||||
|
const avatar = imgSrc ? <img alt={alt} className={className} src={imgSrc} /> : null;
|
||||||
|
return title ? (
|
||||||
|
<Tooltip.Tooltip delayDuration={300}>
|
||||||
|
<Tooltip.TooltipTrigger className="cursor-default">{avatar}</Tooltip.TooltipTrigger>
|
||||||
|
<Tooltip.Content className="rounded-sm bg-black p-2 text-sm text-white shadow-sm">
|
||||||
|
<Tooltip.Arrow />
|
||||||
|
{title}
|
||||||
|
</Tooltip.Content>
|
||||||
|
</Tooltip.Tooltip>
|
||||||
|
) : (
|
||||||
|
<>{avatar}</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,6 @@ export type BookPageProps = inferSSRProps<typeof getServerSideProps>;
|
|||||||
export default function Book(props: BookPageProps) {
|
export default function Book(props: BookPageProps) {
|
||||||
const { t } = useLocale();
|
const { t } = useLocale();
|
||||||
const locationLabels = getLocationLabels(t);
|
const locationLabels = getLocationLabels(t);
|
||||||
|
|
||||||
return props.away ? (
|
return props.away ? (
|
||||||
<div className="h-screen dark:bg-neutral-900">
|
<div className="h-screen dark:bg-neutral-900">
|
||||||
<main className="mx-auto max-w-3xl px-4 py-24">
|
<main className="mx-auto max-w-3xl px-4 py-24">
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class MyDocument extends Document<Props> {
|
|||||||
return (
|
return (
|
||||||
<Html lang={locale} dir={dir}>
|
<Html lang={locale} dir={dir}>
|
||||||
<Head>
|
<Head>
|
||||||
|
<link rel="preload" href="/cal.ttf" as="font" type="font/ttf" />
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
|
||||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
|
||||||
|
|||||||
@@ -250,6 +250,7 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
|
|||||||
items={type.users.map((organizer) => ({
|
items={type.users.map((organizer) => ({
|
||||||
alt: organizer.name || "",
|
alt: organizer.name || "",
|
||||||
image: `${WEBAPP_URL}/${organizer.username}/avatar.png`,
|
image: `${WEBAPP_URL}/${organizer.username}/avatar.png`,
|
||||||
|
title: organizer.name || "",
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ function TeamPage({ team }: TeamPageProps) {
|
|||||||
size={10}
|
size={10}
|
||||||
items={type.users.map((user) => ({
|
items={type.users.map((user) => ({
|
||||||
alt: user.name || "",
|
alt: user.name || "",
|
||||||
|
title: user.name || "",
|
||||||
image: CAL_URL + "/" + user.username + "/avatar.png" || "",
|
image: CAL_URL + "/" + user.username + "/avatar.png" || "",
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import { inferSSRProps } from "@lib/types/inferSSRProps";
|
|||||||
|
|
||||||
import AvailabilityPage from "@components/booking/pages/AvailabilityPage";
|
import AvailabilityPage from "@components/booking/pages/AvailabilityPage";
|
||||||
|
|
||||||
|
import { ssgInit } from "@server/lib/ssg";
|
||||||
|
|
||||||
export type AvailabilityTeamPageProps = inferSSRProps<typeof getServerSideProps>;
|
export type AvailabilityTeamPageProps = inferSSRProps<typeof getServerSideProps>;
|
||||||
|
|
||||||
export default function TeamType(props: AvailabilityTeamPageProps) {
|
export default function TeamType(props: AvailabilityTeamPageProps) {
|
||||||
@@ -24,6 +26,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
const typeParam = asStringOrNull(context.query.type);
|
const typeParam = asStringOrNull(context.query.type);
|
||||||
const dateParam = asStringOrNull(context.query.date);
|
const dateParam = asStringOrNull(context.query.date);
|
||||||
const rescheduleUid = asStringOrNull(context.query.rescheduleUid);
|
const rescheduleUid = asStringOrNull(context.query.rescheduleUid);
|
||||||
|
const ssg = await ssgInit(context);
|
||||||
|
|
||||||
if (!slugParam || !typeParam) {
|
if (!slugParam || !typeParam) {
|
||||||
throw new Error(`File is not named [idOrSlug]/[user]`);
|
throw new Error(`File is not named [idOrSlug]/[user]`);
|
||||||
@@ -145,6 +148,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
workingHours,
|
workingHours,
|
||||||
previousPage: context.req.headers.referer ?? null,
|
previousPage: context.req.headers.referer ?? null,
|
||||||
booking,
|
booking,
|
||||||
|
trpcState: ssg.dehydrate(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user