Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / eventModal / eventForm / propertiesToModel.ts
blob035d761694db98343f5a0e6b228461814be6b2f3
1 import { getVideoConferencingData } from '@proton/calendar';
2 import { removeZoomInfoFromDescription } from '@proton/calendar/components/videoConferencing/zoom/zoomHelpers';
3 import { EVENT_VERIFICATION_STATUS, MAX_CHARS_API } from '@proton/shared/lib/calendar/constants';
4 import { getDtendProperty } from '@proton/shared/lib/calendar/vcalConverter';
5 import { getVeventStatus } from '@proton/shared/lib/calendar/vcalHelper';
6 import type { EventModelView, SelfAddressData, VcalVeventComponent } from '@proton/shared/lib/interfaces/calendar';
7 import truncate from '@proton/utils/truncate';
9 import { propertiesToAttendeeModel } from './propertiesToAttendeeModel';
10 import propertiesToDateTimeModel from './propertiesToDateTimeModel';
11 import { propertiesToFrequencyModel } from './propertiesToFrequencyModel';
12 import { propertiesToOrganizerModel } from './propertiesToOrganizerModel';
14 const DEFAULT_TIME = {
15     value: { year: 1970, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
16     parameters: { tzid: 'UTC' },
19 export const propertiesToModel = ({
20     veventComponent,
21     hasDefaultNotifications,
22     verificationStatus = EVENT_VERIFICATION_STATUS.NOT_VERIFIED,
23     selfAddressData,
24     isAllDay,
25     isProtonProtonInvite,
26     tzid,
27 }: {
28     veventComponent: VcalVeventComponent;
29     hasDefaultNotifications: boolean;
30     verificationStatus?: EVENT_VERIFICATION_STATUS;
31     selfAddressData?: SelfAddressData;
32     isAllDay: boolean;
33     isProtonProtonInvite: boolean;
34     tzid: string;
35 }): EventModelView => {
36     const {
37         uid,
38         location,
39         description,
40         summary,
41         dtstart = DEFAULT_TIME,
42         rrule,
43         attendee,
44         organizer,
45         color,
46         ...rest
47     } = veventComponent;
49     const { start, end } = propertiesToDateTimeModel(dtstart, getDtendProperty(veventComponent), isAllDay, tzid);
50     const { selfAttendeeIndex, selfAddress } = selfAddressData || {};
51     const { meetingId, meetingUrl, password, meetingHost } = getVideoConferencingData(veventComponent);
53     const cleanDescription = removeZoomInfoFromDescription(description?.value ?? '');
55     return {
56         uid: uid ? uid.value : undefined,
57         frequencyModel: propertiesToFrequencyModel(rrule, start),
58         title: truncate((summary?.value ?? '').trim(), MAX_CHARS_API.TITLE),
59         location: truncate((location?.value ?? '').trim(), MAX_CHARS_API.LOCATION),
60         description: truncate(cleanDescription.trim(), MAX_CHARS_API.EVENT_DESCRIPTION),
61         color: color?.value,
62         attendees: propertiesToAttendeeModel(attendee),
63         organizer: propertiesToOrganizerModel(organizer),
64         isProtonProtonInvite,
65         status: getVeventStatus(veventComponent),
66         verificationStatus,
67         isOrganizer: !!selfAddressData?.isOrganizer,
68         isAttendee: !!selfAddressData?.isAttendee,
69         hasDefaultNotifications,
70         selfAttendeeIndex,
71         selfAddress,
72         start,
73         end,
74         conferenceId: meetingId,
75         conferenceUrl: meetingUrl,
76         conferencePassword: password,
77         conferenceHost: meetingHost,
78         rest,
79     };