1 import { FREQUENCY, ICAL_ATTENDEE_STATUS, ICAL_EVENT_STATUS } from '@proton/shared/lib/calendar/constants';
2 import { getDisplayTitle } from '@proton/shared/lib/calendar/helper';
3 import { getIsAddressActive } from '@proton/shared/lib/helpers/address';
4 import type { EventModelReadView } from '@proton/shared/lib/interfaces/calendar';
6 import getIsTemporaryViewEvent from '../../containers/calendar/getIsTemporaryViewEvent';
7 import type { CalendarViewEvent, CalendarViewEventTemporaryEvent } from '../../containers/calendar/interface';
9 const getEventInformation = (calendarViewEvent: CalendarViewEvent, model: EventModelReadView, hasPaidMail: boolean) => {
10 const { calendarData, eventReadResult, eventData } = calendarViewEvent.data;
12 const isTemporaryEvent = getIsTemporaryViewEvent(calendarViewEvent);
13 const tmpData = isTemporaryEvent ? (calendarViewEvent as CalendarViewEventTemporaryEvent).tmpData : undefined;
14 const isEventReadLoading = !isTemporaryEvent && !eventReadResult;
16 const calendarColor = tmpData?.calendar.color || calendarData.Color;
17 const eventColor = hasPaidMail ? tmpData?.color || eventData?.Color : undefined;
18 const color = eventColor || calendarColor;
19 const eventTitleSafe = getDisplayTitle(tmpData?.title || model.title);
20 const isCancelled = model.status === ICAL_EVENT_STATUS.CANCELLED;
21 const isRecurring = model.frequencyModel.type !== FREQUENCY.ONCE;
22 const isSingleEdit = !!eventReadResult?.result?.[0]?.veventComponent?.['recurrence-id'];
23 const { selfAddress, selfAttendeeIndex } = model;
24 const selfAttendee = selfAttendeeIndex !== undefined ? model.attendees[selfAttendeeIndex] : undefined;
25 const isUnanswered = selfAttendee?.partstat === ICAL_ATTENDEE_STATUS.NEEDS_ACTION;
32 eventReadError: eventReadResult?.error,
34 verificationStatus: eventReadResult?.result?.[0]?.verificationStatus,
35 isInvitation: !!model.organizer,
40 userPartstat: selfAttendee?.partstat || ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
41 isSelfAddressActive: selfAddress ? getIsAddressActive(selfAddress) : true,
45 export default getEventInformation;