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 = ({
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 }));
29 extra.eventManager.stop();
31 updateMember(calendarID, memberID, {
32 Display: display ? CALENDAR_DISPLAY.VISIBLE : CALENDAR_DISPLAY.HIDDEN,
36 dispatch(calendarsActions.updateCalendarVisibility({ calendarID, memberID, display: !display }));
38 extra.eventManager.start();
43 export const toggleZoomSettings = ({
47 }): ThunkAction<Promise<void>, OrganizationState, ProtonThunkArguments, UnknownAction> => {
48 return async (dispatch, _, extra) => {
50 extra.eventManager.stop();
52 organizationActions.updateOrganizationSettings({
53 value: { VideoConferencingEnabled: checked },
56 await extra.api(updateOrganizationSettings({ VideoConferencingEnabled: checked }));
59 extra.eventManager.start();