1 import { c } from 'ttag';
3 import { RECURRING_TYPES } from '@proton/shared/lib/calendar/constants';
4 import { getOccurrences } from '@proton/shared/lib/calendar/recurrence/recurring';
6 import type { EventNewData, EventOldData } from '../../../interfaces/EventData';
7 import type { InviteActions } from '../../../interfaces/Invite';
8 import { INVITE_ACTION_TYPES } from '../../../interfaces/Invite';
10 export const getEventCreatedText = (inviteActions: InviteActions) => {
11 const { type } = inviteActions;
12 if (type === INVITE_ACTION_TYPES.SEND_INVITATION) {
13 return c('Success').t`Invitation sent and event created`;
15 return c('Success').t`Event created`;
18 export const getEventUpdatedText = (inviteActions: InviteActions) => {
19 const { type, addedAttendees, removedAttendees } = inviteActions;
20 const hasAddedAttendees = !!addedAttendees?.length;
21 const hasRemovedAttendees = !!removedAttendees?.length;
22 if (type === INVITE_ACTION_TYPES.CHANGE_PARTSTAT) {
23 return c('Success').t`Participation status updated`;
25 if (type === INVITE_ACTION_TYPES.SEND_INVITATION) {
26 if (hasAddedAttendees && hasRemovedAttendees) {
27 return c('Success').t`Participants notified and changes saved`;
29 if (hasAddedAttendees) {
30 return c('Success').t`Invitation sent and participants added`;
32 if (hasRemovedAttendees) {
33 return c('Success').t`Cancellation sent and participants removed`;
35 return c('Success').t`Participants notified and event updated`;
37 if (type === INVITE_ACTION_TYPES.SEND_UPDATE) {
38 return c('Success').t`Participants notified and event updated`;
40 return c('Success').t`Event updated`;
43 export const getEventDeletedText = ({ type, sendCancellationNotice }: InviteActions) => {
44 if (type === INVITE_ACTION_TYPES.CANCEL_INVITATION) {
45 return c('Success').t`Cancellation sent and event deleted`;
47 if (type === INVITE_ACTION_TYPES.DECLINE_INVITATION && sendCancellationNotice) {
48 return c('Success').t`Answer sent and event deleted`;
50 return c('Success').t`Event deleted`;
53 export const getRecurringEventCreatedText = (inviteActions: InviteActions) => {
54 if (inviteActions.type === INVITE_ACTION_TYPES.SEND_INVITATION) {
55 return c('Success').t`Invitation sent and events created`;
57 return c('Success').t`Events created`;
60 export const getRecurringEventUpdatedText = (saveType: RECURRING_TYPES, inviteActions: InviteActions) => {
61 const { type: inviteType, addedAttendees, removedAttendees } = inviteActions;
62 const hasAddedAttendees = !!addedAttendees?.length;
63 const hasRemovedAttendees = !!removedAttendees?.length;
64 if (saveType === RECURRING_TYPES.SINGLE) {
65 return getEventUpdatedText(inviteActions);
67 if (saveType === RECURRING_TYPES.FUTURE) {
68 return c('Success').t`Future events updated`;
70 if (inviteType === INVITE_ACTION_TYPES.CHANGE_PARTSTAT) {
71 return c('Success').t`Participation status updated for all events`;
73 if (inviteType === INVITE_ACTION_TYPES.SEND_INVITATION) {
74 if (hasAddedAttendees && hasRemovedAttendees) {
75 return c('Success').t`Participants notified and all events updated`;
77 if (hasAddedAttendees) {
78 return c('Success').t`Invitation sent and participants added to all events`;
80 if (hasRemovedAttendees) {
81 return c('Success').t`Cancellation sent and participants removed from all events`;
83 // should never fall here
84 return c('Success').t`Invitation sent and all events updated`;
86 if (inviteType === INVITE_ACTION_TYPES.SEND_UPDATE) {
87 return c('Success').t`Participants notified and all events updated`;
89 return c('Success').t`All events updated`;
92 export const getRecurringEventDeletedText = (deleteType: RECURRING_TYPES, inviteActions: InviteActions) => {
93 const { type, sendCancellationNotice } = inviteActions;
94 if (deleteType === RECURRING_TYPES.SINGLE) {
95 return getEventDeletedText(inviteActions);
97 if (deleteType === RECURRING_TYPES.FUTURE) {
98 return c('Success').t`Future events deleted`;
100 if (type === INVITE_ACTION_TYPES.CANCEL_INVITATION) {
101 return c('Success').t`Cancellation sent and all events deleted`;
103 if (type === INVITE_ACTION_TYPES.DECLINE_INVITATION && sendCancellationNotice) {
104 return c('Success').t`Answer sent and all events deleted`;
106 return c('Success').t`All events deleted`;
109 export const getSingleEventText = (
110 oldEventData: EventOldData | undefined,
111 newEventData: EventNewData,
112 inviteActions: InviteActions
114 const isCreate = !oldEventData?.eventData;
115 const isRecurring = newEventData.veventComponent.rrule;
117 if (isCreate && isRecurring) {
118 const twoOccurrences = getOccurrences({
119 component: newEventData.veventComponent,
122 if (twoOccurrences.length === 1) {
123 return getEventCreatedText(inviteActions);
125 return getRecurringEventCreatedText(inviteActions);
128 return getEventCreatedText(inviteActions);
130 return getEventUpdatedText(inviteActions);