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 = {
15 uid: { value: '123' },
17 value: { year: 1970, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
20 value: { year: 1970, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
23 value: { year: 1970, month: 1, day: 1, hours: 0, minutes: 0, seconds: 0, isUTC: true },
26 const useReadEvent = (
27 targetEventData: CalendarViewEventData,
29 calendarSettings?: CalendarSettings
30 ): EventModelReadView => {
31 return useMemo(() => {
33 { veventComponent = DEFAULT_VEVENT, hasDefaultNotifications, verificationStatus, selfAddressData },
34 { IsProtonProtonInvite },
35 ] = targetEventData.eventReadResult?.result || [
37 veventComponent: DEFAULT_VEVENT,
38 hasDefaultNotifications: true,
39 verificationStatus: EVENT_VERIFICATION_STATUS.NOT_VERIFIED,
40 selfAddressData: { isOrganizer: false, isAttendee: false },
42 { IsProtonProtonInvite: 0 },
45 const isAllDay = getIsAllDay(veventComponent);
46 const model = propertiesToModel({
48 hasDefaultNotifications,
52 isProtonProtonInvite: !!IsProtonProtonInvite,
56 hasDefaultNotifications && calendarSettings
57 ? apiNotificationsToModel({ notifications: null, isAllDay, calendarSettings })
58 : propertiesToNotificationModel(veventComponent, isAllDay);
65 }, [targetEventData, tzid, calendarSettings]);
68 export default useReadEvent;