Use source loader for email sprite icons
[ProtonMail-WebClient.git] / packages / calendar / calendars / actions.ts
blob2712a478bab92d1a6ae1fdd8a25323be62aba046
1 import { type UnknownAction } from '@reduxjs/toolkit';
2 import type { ThunkAction } from 'redux-thunk';
4 import type { AddressesState, OrganizationState } from '@proton/account';
5 import { addressesThunk, organizationActions } from '@proton/account';
6 import type { ProtonThunkArguments } from '@proton/redux-shared-store-types';
7 import { updateMember } from '@proton/shared/lib/api/calendars';
8 import { updateOrganizationSettings } from '@proton/shared/lib/api/organization';
9 import { CALENDAR_DISPLAY } from '@proton/shared/lib/calendar/constants';
10 import { getMemberAndAddress } from '@proton/shared/lib/calendar/members';
12 import { type CalendarsState, calendarsActions, calendarsThunk } from './index';
14 export const changeCalendarVisiblity = ({
15     calendarID,
16     display,
17 }: {
18     calendarID: string;
19     display: boolean;
20 }): ThunkAction<Promise<void>, CalendarsState & AddressesState, ProtonThunkArguments, UnknownAction> => {
21     return async (dispatch, _, extra) => {
22         const [calendars, addresses] = await Promise.all([dispatch(calendarsThunk()), dispatch(addressesThunk())]);
23         const members = calendars.find(({ ID }) => ID === calendarID)?.Members || [];
24         const [{ ID: memberID }] = getMemberAndAddress(addresses, members);
26         dispatch(calendarsActions.updateCalendarVisibility({ calendarID, memberID, display }));
28         try {
29             extra.eventManager.stop();
30             await extra.api(
31                 updateMember(calendarID, memberID, {
32                     Display: display ? CALENDAR_DISPLAY.VISIBLE : CALENDAR_DISPLAY.HIDDEN,
33                 })
34             );
35         } catch (error) {
36             dispatch(calendarsActions.updateCalendarVisibility({ calendarID, memberID, display: !display }));
37         } finally {
38             extra.eventManager.start();
39         }
40     };
43 export const toggleZoomSettings = ({
44     checked,
45 }: {
46     checked: boolean;
47 }): ThunkAction<Promise<void>, OrganizationState, ProtonThunkArguments, UnknownAction> => {
48     return async (dispatch, _, extra) => {
49         try {
50             extra.eventManager.stop();
51             dispatch(
52                 organizationActions.updateOrganizationSettings({
53                     value: { VideoConferencingEnabled: checked },
54                 })
55             );
56             await extra.api(updateOrganizationSettings({ VideoConferencingEnabled: checked }));
57         } catch (error) {
58         } finally {
59             extra.eventManager.start();
60         }
61     };