1 import type { CSSProperties, Ref } from 'react';
2 import { useMemo } from 'react';
4 import { Icon, useContactEmailsCache } from '@proton/components';
5 import { getContactDisplayNameEmail } from '@proton/shared/lib/contacts/contactEmail';
6 import { canonicalizeEmail } from '@proton/shared/lib/helpers/email';
7 import clsx from '@proton/utils/clsx';
9 import type { CalendarViewBusyEvent } from '../../containers/calendar/interface';
10 import { getEventStyle } from '../../helpers/color';
11 import { useCalendarSelector } from '../../store/hooks';
15 formatTime: (date: Date) => string;
17 event: CalendarViewBusyEvent;
19 isOutsideStart: boolean;
20 isOutsideEnd: boolean;
21 eventRef?: Ref<HTMLDivElement>;
23 const FullDayBusyEvent = ({
26 className = 'calendar-dayeventcell h-custom w-custom top-custom left-custom absolute text-left',
33 const { start, isAllDay, isAllPartDay, color } = event;
34 const canonicalizedEmail = canonicalizeEmail(event.email);
36 const { contactEmailsMap } = useContactEmailsCache();
37 const { Name: contactName } = contactEmailsMap[canonicalizedEmail] || {};
38 const { nameEmail } = getContactDisplayNameEmail({ name: contactName, email: event.email });
40 const isHighlighted = useCalendarSelector(
41 (state) => state.calendarBusySlots.attendeeHighlight === canonicalizedEmail
44 const eventStyle = useMemo(() => {
45 return getEventStyle(color);
48 const startTimeString = useMemo(() => {
49 if (start && (!isAllDay || isAllPartDay)) {
50 return formatTime(start);
52 }, [start, isAllPartDay, isAllDay, formatTime]);
57 className={clsx([className, isOutsideStart && 'isOutsideStart', isOutsideEnd && 'isOutsideEnd'])}
58 data-ignore-create="1"
63 'isLoaded calendar-dayeventcell-inner text-left flex',
64 !isAllDay && 'isNotAllDay',
65 isBeforeNow && 'isPast',
71 boxShadow: `0 0 0 2px ${color}`,
77 <div className="flex flex-nowrap flex-1 items-center">
79 <Icon className="mr-2 shrink-0 calendar-dayeventcell-circle" size={4} name="circle-filled" />
82 {isOutsideStart ? <Icon name="chevron-left" size={3} className="shrink-0" /> : null}
84 <span data-testid="calendar-view:all-day-event" className="flex-1 text-ellipsis">
85 {startTimeString && <span className="calendar-dayeventcell-time">{startTimeString}</span>}
86 <span className="calendar-dayeventcell-title">{nameEmail}</span>
89 {isOutsideEnd ? <Icon name="chevron-right" size={3} className="shrink-0" /> : null}
96 export default FullDayBusyEvent;