Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / applications / calendar / src / app / components / events / useReadEvent.ts
blob29298412523a3be23a38131dfb971a79014284dc
1 import { useMemo } from 'react';
3 import { apiNotificationsToModel } from '@proton/shared/lib/calendar/alarms/notificationsToModel';
4 import { EVENT_VERIFICATION_STATUS } from '@proton/shared/lib/calendar/constants';
5 import { getIsAllDay } from '@proton/shared/lib/calendar/veventHelper';
6 import type { CalendarSettings, EventModelReadView } from '@proton/shared/lib/interfaces/calendar';
7 import type { VcalVeventComponent } from '@proton/shared/lib/interfaces/calendar/VcalModel';
9 import type { CalendarViewEventData } from '../../containers/calendar/interface';
10 import { propertiesToModel } from '../eventModal/eventForm/propertiesToModel';
11 import { propertiesToNotificationModel } from '../eventModal/eventForm/propertiesToNotificationModel';
13 const DEFAULT_VEVENT: VcalVeventComponent = {
14     component: 'vevent',
15     uid: { value: '123' },
16     dtstart: {
17         value: { year: 1970, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
18     },
19     dtend: {
20         value: { year: 1970, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
21     },
22     dtstamp: {
23         value: { year: 1970, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
24     },
26 const useReadEvent = (
27     targetEventData: CalendarViewEventData,
28     tzid: string,
29     calendarSettings?: CalendarSettings
30 ): EventModelReadView => {
31     return useMemo(() => {
32         const [
33             { veventComponent = DEFAULT_VEVENT, hasDefaultNotifications, verificationStatus, selfAddressData },
34             { IsProtonProtonInvite },
35         ] = targetEventData.eventReadResult?.result || [
36             {
37                 veventComponent: DEFAULT_VEVENT,
38                 hasDefaultNotifications: true,
39                 verificationStatus: EVENT_VERIFICATION_STATUS.NOT_VERIFIED,
40                 selfAddressData: { isOrganizer: false, isAttendee: false },
41             },
42             { IsProtonProtonInvite: 0 },
43         ];
45         const isAllDay = getIsAllDay(veventComponent);
46         const model = propertiesToModel({
47             veventComponent,
48             hasDefaultNotifications,
49             verificationStatus,
50             selfAddressData,
51             isAllDay,
52             isProtonProtonInvite: !!IsProtonProtonInvite,
53             tzid,
54         });
55         const notifications =
56             hasDefaultNotifications && calendarSettings
57                 ? apiNotificationsToModel({ notifications: null, isAllDay, calendarSettings })
58                 : propertiesToNotificationModel(veventComponent, isAllDay);
60         return {
61             ...model,
62             notifications,
63             isAllDay,
64         };
65     }, [targetEventData, tzid, calendarSettings]);
68 export default useReadEvent;