Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / i18n.tsx
blobe5a7c15f7dfc46e343843b15b869727a9146f6ff
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`;
14     }
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`;
24     }
25     if (type === INVITE_ACTION_TYPES.SEND_INVITATION) {
26         if (hasAddedAttendees && hasRemovedAttendees) {
27             return c('Success').t`Participants notified and changes saved`;
28         }
29         if (hasAddedAttendees) {
30             return c('Success').t`Invitation sent and participants added`;
31         }
32         if (hasRemovedAttendees) {
33             return c('Success').t`Cancellation sent and participants removed`;
34         }
35         return c('Success').t`Participants notified and event updated`;
36     }
37     if (type === INVITE_ACTION_TYPES.SEND_UPDATE) {
38         return c('Success').t`Participants notified and event updated`;
39     }
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`;
46     }
47     if (type === INVITE_ACTION_TYPES.DECLINE_INVITATION && sendCancellationNotice) {
48         return c('Success').t`Answer sent and event deleted`;
49     }
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`;
56     }
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);
66     }
67     if (saveType === RECURRING_TYPES.FUTURE) {
68         return c('Success').t`Future events updated`;
69     }
70     if (inviteType === INVITE_ACTION_TYPES.CHANGE_PARTSTAT) {
71         return c('Success').t`Participation status updated for all events`;
72     }
73     if (inviteType === INVITE_ACTION_TYPES.SEND_INVITATION) {
74         if (hasAddedAttendees && hasRemovedAttendees) {
75             return c('Success').t`Participants notified and all events updated`;
76         }
77         if (hasAddedAttendees) {
78             return c('Success').t`Invitation sent and participants added to all events`;
79         }
80         if (hasRemovedAttendees) {
81             return c('Success').t`Cancellation sent and participants removed from all events`;
82         }
83         // should never fall here
84         return c('Success').t`Invitation sent and all events updated`;
85     }
86     if (inviteType === INVITE_ACTION_TYPES.SEND_UPDATE) {
87         return c('Success').t`Participants notified and all events updated`;
88     }
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);
96     }
97     if (deleteType === RECURRING_TYPES.FUTURE) {
98         return c('Success').t`Future events deleted`;
99     }
100     if (type === INVITE_ACTION_TYPES.CANCEL_INVITATION) {
101         return c('Success').t`Cancellation sent and all events deleted`;
102     }
103     if (type === INVITE_ACTION_TYPES.DECLINE_INVITATION && sendCancellationNotice) {
104         return c('Success').t`Answer sent and all events deleted`;
105     }
106     return c('Success').t`All events deleted`;
109 export const getSingleEventText = (
110     oldEventData: EventOldData | undefined,
111     newEventData: EventNewData,
112     inviteActions: InviteActions
113 ) => {
114     const isCreate = !oldEventData?.eventData;
115     const isRecurring = newEventData.veventComponent.rrule;
117     if (isCreate && isRecurring) {
118         const twoOccurrences = getOccurrences({
119             component: newEventData.veventComponent,
120             maxCount: 2,
121         });
122         if (twoOccurrences.length === 1) {
123             return getEventCreatedText(inviteActions);
124         }
125         return getRecurringEventCreatedText(inviteActions);
126     }
127     if (isCreate) {
128         return getEventCreatedText(inviteActions);
129     }
130     return getEventUpdatedText(inviteActions);