1 import { useCallback } from 'react';
3 import { useGetAddressKeys } from '@proton/account/addressKeys/hooks';
4 import { useGetAddresses } from '@proton/account/addresses/hooks';
5 import { useGetCalendarBootstrap } from '@proton/calendar/calendarBootstrap/hooks';
6 import { useGetDecryptedPassphraseAndCalendarKeys } from '@proton/calendar/calendarBootstrap/keys';
7 import { getMemberAndAddress } from '@proton/shared/lib/calendar/members';
8 import type { GetCalendarInfo } from '@proton/shared/lib/interfaces/hooks/GetCalendarInfo';
10 export const useGetCalendarInfo = (): GetCalendarInfo => {
11 const getCalendarBootstrap = useGetCalendarBootstrap();
12 const getAddresses = useGetAddresses();
13 const getDecryptedPassphraseAndCalendarKeys = useGetDecryptedPassphraseAndCalendarKeys();
14 const getAddressKeys = useGetAddressKeys();
17 async (calendarID: string) => {
18 const [{ Members, CalendarSettings: calendarSettings }, Addresses] = await Promise.all([
19 getCalendarBootstrap(calendarID),
23 const [{ ID: memberID }, { ID: addressID }] = getMemberAndAddress(Addresses, Members);
25 const [{ decryptedCalendarKeys, decryptedPassphrase, passphraseID }, addressKeys] = await Promise.all([
26 getDecryptedPassphraseAndCalendarKeys(calendarID),
27 getAddressKeys(addressID),
34 calendarKeys: decryptedCalendarKeys,
36 passphrase: decryptedPassphrase,
40 [getCalendarBootstrap, getAddresses, getDecryptedPassphraseAndCalendarKeys, getAddressKeys]
44 export default useGetCalendarInfo;