Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / events / getEventInformation.ts
blob09f35c33f8ca9ce33b4090ea455836439ca7aa31
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;
27     return {
28         isTemporaryEvent,
29         isEventReadLoading,
30         tmpData,
31         color,
32         eventReadError: eventReadResult?.error,
33         eventTitleSafe,
34         verificationStatus: eventReadResult?.result?.[0]?.verificationStatus,
35         isInvitation: !!model.organizer,
36         isCancelled,
37         isUnanswered,
38         isRecurring,
39         isSingleEdit,
40         userPartstat: selfAttendee?.partstat || ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
41         isSelfAddressActive: selfAddress ? getIsAddressActive(selfAddress) : true,
42     };
45 export default getEventInformation;