1 import type { Dispatch, SetStateAction } from 'react';
3 import { getAppHref } from '../apps/helper';
4 import { getLinkToCalendarEvent } from '../calendar/helper';
5 import type { APP_NAMES } from '../constants';
6 import { APPS } from '../constants';
7 import { addParentAppToUrl, postMessageToIframe } from './helpers';
8 import type { DrawerApp, IframeSrcMap } from './interfaces';
9 import { DRAWER_EVENTS } from './interfaces';
11 const { PROTONCALENDAR: calendarApp } = APPS;
13 interface OpenCalendarEventProps {
14 currentApp: APP_NAMES;
15 setAppInView: Dispatch<SetStateAction<DrawerApp | undefined>>;
16 iframeSrcMap: IframeSrcMap;
17 setIframeSrcMap: Dispatch<SetStateAction<IframeSrcMap>>;
21 recurrenceID?: number;
24 export const openCalendarEventInDrawer = ({
33 }: OpenCalendarEventProps) => {
34 if (!iframeSrcMap[calendarApp]) {
35 const linkTo = getLinkToCalendarEvent({ calendarID, eventID, recurrenceID });
36 const appHref = getAppHref(linkTo, calendarApp, localID);
38 setAppInView(calendarApp);
39 setIframeSrcMap((map) => ({
41 [calendarApp]: addParentAppToUrl(appHref, currentApp, false),
46 type: DRAWER_EVENTS.CALENDAR_OPEN_EVENT,
47 payload: { calendarID, eventID, recurrenceID },
53 setAppInView(calendarApp);