1 import { ICAL_ATTENDEE_STATUS, ICAL_EVENT_STATUS } from '@proton/shared/lib/calendar/constants';
2 import { getIsAddressActive } from '@proton/shared/lib/helpers/address';
3 import type { Address } from '@proton/shared/lib/interfaces';
4 import type { EventModelReadView } from '@proton/shared/lib/interfaces/calendar';
6 import { getParticipantsError } from '../components/eventModal/helpers';
8 export const generateEventUniqueId = (calendarID: string, eventID: string) => `${calendarID}.${eventID}`;
9 export const getCalendarIDFromUniqueId = (itemID: string) => itemID.split('.')[0];
10 export const getEventIDFromUniqueId = (itemID: string) => itemID.split('.')[1];
12 export const getEventStatusTraits = (model: EventModelReadView) => {
13 const { status: eventStatus, selfAttendeeIndex } = model;
15 const noOneIsAttending =
16 model.attendees.length > 0 &&
17 model.attendees.every((attendee) => attendee.partstat === ICAL_ATTENDEE_STATUS.DECLINED);
19 if (model.isAttendee && eventStatus === ICAL_EVENT_STATUS.CONFIRMED) {
20 const selfAttendee = selfAttendeeIndex !== undefined ? model.attendees[selfAttendeeIndex] : undefined;
22 const { partstat } = selfAttendee;
24 isUnanswered: partstat === ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
25 isTentative: partstat === ICAL_ATTENDEE_STATUS.TENTATIVE,
26 isCancelled: partstat === ICAL_ATTENDEE_STATUS.DECLINED || noOneIsAttending,
31 isTentative: eventStatus === ICAL_EVENT_STATUS.TENTATIVE,
32 isCancelled: eventStatus === ICAL_EVENT_STATUS.CANCELLED || noOneIsAttending,
36 export const getCanEditEvent = ({
40 isUnknownCalendar: boolean;
41 isCalendarDisabled: boolean;
43 if (isUnknownCalendar) {
46 if (isCalendarDisabled) {
52 export const getCanDeleteEvent = ({
57 isOwnedCalendar: boolean;
58 isCalendarWritable: boolean;
59 isInvitation: boolean;
61 if (!isCalendarWritable) {
64 if (!isOwnedCalendar) {
70 export const getCanDuplicateEvent = ({
77 isUnknownCalendar: boolean;
78 isSubscribedCalendar: boolean;
79 isOwnedCalendar: boolean;
81 isInvitation: boolean;
83 if (isUnknownCalendar) {
86 if (isSubscribedCalendar) {
89 if (isOwnedCalendar) {
90 return isInvitation ? isOrganizer : true;
95 export const getCanChangeCalendarOfEvent = ({
104 isCreateEvent: boolean;
105 isOwnedCalendar: boolean;
106 isCalendarWritable: boolean;
107 isSingleEdit: boolean;
108 isInvitation: boolean;
110 isOrganizer: boolean;
115 if (!isCalendarWritable) {
119 if (!isOwnedCalendar) {
123 return !isSingleEdit;
128 // we should never fall here, but just in case
134 export const getCannotSaveEvent = ({
138 canEditSharedEventData = true,
141 isOwnedCalendar: boolean;
142 isOrganizer: boolean;
143 numberOfAttendees: number;
144 canEditSharedEventData?: boolean;
145 maxAttendees?: number;
147 if (!canEditSharedEventData) {
148 // user is editing only notifications
152 return !!getParticipantsError({ isOwnedCalendar, numberOfAttendees, maxAttendees });
157 export const getCanEditSharedEventData = ({
165 isOwnedCalendar: boolean;
166 isCalendarWritable: boolean;
167 isOrganizer: boolean;
169 isInvitation: boolean;
170 selfAddress?: Address;
172 if (!isCalendarWritable) {
176 if (isOwnedCalendar) {
181 return selfAddress ? getIsAddressActive(selfAddress) : false;
190 export const getCanReplyToEvent = ({
196 isOwnedCalendar: boolean;
197 isCalendarWritable: boolean;
199 isCancelled: boolean;
201 return isOwnedCalendar && isCalendarWritable && isAttendee && !isCancelled;
204 export const getIsAvailableCalendar = ({
209 isOwnedCalendar: boolean;
210 isCalendarWritable: boolean;
211 isInvitation: boolean;
213 if (!isCalendarWritable) {
217 return isOwnedCalendar;