Merge branch 'IDTEAM-1.26.0' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / calendar / alarms / notificationsToModel.ts
blob0030a9582d05740de530eaa8f1f879b0954bb16d
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'),
12         ...triggerToModel({
13             isAllDay,
14             type: Type,
15             trigger: fromTriggerString(Trigger),
16         }),
17     }));
18     // Filter out future alarms
19     return filterFutureNotifications(modelNotifications);
22 export const apiNotificationsToModel = ({
23     notifications: apiNotifications,
24     isAllDay,
25     calendarSettings,
26 }: {
27     notifications: Nullable<CalendarNotificationSettings[]>;
28     isAllDay: boolean;
29     calendarSettings: CalendarSettings;
30 }) => {
31     const { DefaultPartDayNotifications, DefaultFullDayNotifications } = calendarSettings;
32     const defaultNotifications = isAllDay ? DefaultFullDayNotifications : DefaultPartDayNotifications;
34     return notificationsToModel(apiNotifications || defaultNotifications, isAllDay);