1 import { useMemo } from 'react';
3 import { useUser } from '@proton/account/user/hooks';
4 import { Icon } from '@proton/components';
5 import { MINUTE } from '@proton/shared/lib/constants';
6 import clsx from '@proton/utils/clsx';
8 import type { CalendarViewEvent, CalendarViewEventTemporaryEvent } from '../../containers/calendar/interface';
9 import { getEventStyle } from '../../helpers/color';
10 import { getEventStatusTraits } from '../../helpers/event';
11 import type { PartDayEventProps } from './PartDayEvent';
12 import { PartDayEventView } from './PartDayEvent';
13 import { getEventErrorMessage, getEventLoadingMessage } from './error';
14 import getEventInformation from './getEventInformation';
15 import useReadEvent from './useReadEvent';
17 interface PartDayRegularEventProps extends PartDayEventProps {
18 event: CalendarViewEvent | CalendarViewEventTemporaryEvent;
21 const PartDayRegularEvent = ({
31 }: PartDayRegularEventProps) => {
32 const [{ hasPaidMail }] = useUser();
33 const { start, end, data: targetEventData } = event;
34 const model = useReadEvent(targetEventData, tzid);
36 const { isEventReadLoading, color, eventReadError, eventTitleSafe } = getEventInformation(
41 const { isUnanswered, isCancelled } = getEventStatusTraits(model);
43 const eventStyle = useMemo(() => {
44 return getEventStyle(color, style);
47 const titleString = (() => {
51 if (isEventReadLoading) {
54 return eventTitleSafe;
57 const expandableTitleString = (() => {
59 return getEventErrorMessage(eventReadError);
61 if (isEventReadLoading) {
62 return getEventLoadingMessage();
67 const timeString = useMemo(() => {
68 const timeStart = formatTime(start);
69 const timeEnd = formatTime(end);
70 return `${timeStart} - ${timeEnd}`;
72 const shouldHideTime = isEventReadLoading || (eventPartDuration < 50 * MINUTE && titleString);
78 isLoaded={!isEventReadLoading}
80 isSelected={isSelected}
81 isUnanswered={isUnanswered}
82 isCancelled={isCancelled}
84 title={expandableTitleString}
85 eventPartDuration={eventPartDuration}
88 <div className="flex flex-nowrap items-center">
89 <Icon name="lock-filled" className="calendar-eventcell-lock-icon" />
90 <span className="flex-1 text-ellipsis"> </span>
94 <div data-testid="calendar-day-week-view:part-day-event" className="calendar-eventcell-title">
97 <div className={clsx(['text-ellipsis calendar-eventcell-timestring', shouldHideTime && 'sr-only'])}>
106 export default PartDayRegularEvent;