import dayjs from "@calcom/dayjs"; import type { CalendarEvent } from "@calcom/features/calendars/weeklyview/types/events"; import type { BookingStatus } from "@calcom/prisma/enums"; import classNames from "@calcom/ui/classNames"; import { Tooltip } from "@calcom/ui/components/tooltip"; import { cva } from "class-variance-authority"; type EventProps = { event: CalendarEvent; currentlySelectedEventId?: number; eventDuration: number; onEventClick?: (event: CalendarEvent) => void; disabled?: boolean; isHovered?: boolean; }; const eventClasses = cva( "group flex h-full w-full overflow-hidden rounded-[6px] px-[6px] text-xs leading-5 border-default font-medium", { variants: { status: { ACCEPTED: "bg-subtle hover:bg-emphasis text-emphasis border-[1px] border-default", PENDING: "bg-subtle text-subtle border-[1px] border-dashed border-default", REJECTED: "bg-subtle border-[1px] border-dashed text-subtle line-through", CANCELLED: "bg-subtle border-[1px] border-dashed text-subtle line-through", AWAITING_HOST: "bg-subtle text-emphasis border-[1px] border-dashed border-default", }, disabled: { true: "hover:cursor-default", false: "hover:cursor-pointer", }, selected: { true: "", false: "", }, borderOnly: { true: "bg-transparent border-[1.5px] border-subtle border-dashed opacity-60", false: "", }, }, } ); const STATUS_COLOR_MAP: Record = { ACCEPTED: "bg-green-500", PENDING: "bg-orange-500", REJECTED: "bg-red-500", CANCELLED: "bg-red-500", AWAITING_HOST: "bg-blue-500", }; // Maps booking status to color classes for the color bar // Follows the same pattern as BookingDetailsSheet badge variants const getStatusColorClass = (status?: BookingStatus): string | undefined => { if (!status) return undefined; return STATUS_COLOR_MAP[status]; }; export function Event({ event, currentlySelectedEventId, eventDuration, disabled, onEventClick, isHovered = false, }: EventProps) { const selected = currentlySelectedEventId === event.id; const { options } = event; // Use custom color if provided, otherwise derive from status const colorClass = !options?.color ? getStatusColorClass(options?.status) : undefined; const Component = onEventClick ? "button" : "div"; const dayOfWeek = dayjs(event.start).day(); const tooltipSide = dayOfWeek >= 1 && dayOfWeek <= 4 ? "right" : "left"; const tooltipContent = (
{(options?.color || colorClass) && (
)}
{event.title}
{!event.options?.hideTime && (
{dayjs(event.start).format("HH:mm")} - {dayjs(event.end).format("HH:mm")}
)} {event.description && (
{event.description}
)} {options?.status && options.status !== "ACCEPTED" && (
{options.status.toLowerCase().replace("_", " ")}
)}
); const displayType = eventDuration < 40 ? "single-line" : eventDuration < 45 ? "multi-line" : "full"; return ( onEventClick?.(event)} {...(options?.bookingUid ? { "data-booking-uid": options.bookingUid } : {})} className={classNames( eventClasses({ status: options?.status, disabled, selected, borderOnly: options?.borderOnly ?? false, }), options?.className, (isHovered || selected) && "ring-brand-default shadow-lg ring-2 ring-offset-0" )} style={{ transition: "all 100ms ease-out", }}> {(options?.color || colorClass) && (
)}
{displayType === "single-line" && (
{event.title} {!event.options?.hideTime && (

{dayjs(event.start).format("HH:mm")} - {dayjs(event.end).format("HH:mm")}

)}
)} {displayType !== "single-line" && (

{event.title}

)} {displayType !== "single-line" && !event.options?.hideTime && (

{dayjs(event.start).format("HH:mm")} - {dayjs(event.end).format("HH:mm")}

)} {displayType === "full" && event.description && (

{event.description}

)}
); }