1 import generateUID from '@proton/utils/generateUID';
3 import type { Nullable } from '../../interfaces';
4 import type { CalendarNotificationSettings, CalendarSettings } from '../../interfaces/calendar';
5 import { filterFutureNotifications } from '../alarms';
6 import { fromTriggerString } from '../vcal';
7 import { triggerToModel } from './notificationModel';
9 export const notificationsToModel = (notifications: CalendarNotificationSettings[] = [], isAllDay: boolean) => {
10 const modelNotifications = notifications.map(({ Type, Trigger }) => ({
11 id: generateUID('notification'),
15 trigger: fromTriggerString(Trigger),
18 // Filter out future alarms
19 return filterFutureNotifications(modelNotifications);
22 export const apiNotificationsToModel = ({
23 notifications: apiNotifications,
27 notifications: Nullable<CalendarNotificationSettings[]>;
29 calendarSettings: CalendarSettings;
31 const { DefaultPartDayNotifications, DefaultFullDayNotifications } = calendarSettings;
32 const defaultNotifications = isAllDay ? DefaultFullDayNotifications : DefaultPartDayNotifications;
34 return notificationsToModel(apiNotifications || defaultNotifications, isAllDay);