1 import { getAllMembers, getCalendarInvitations, getPublicLinks } from '@proton/shared/lib/api/calendars';
2 import { getApiWithAbort } from '@proton/shared/lib/api/helpers/customConfig';
3 import { filterOutDeclinedInvitations } from '@proton/shared/lib/calendar/sharing/shareProton/shareProton';
5 import type { Api } from '../../interfaces';
8 CalendarWithOwnMembers,
9 GetAllMembersApiResponse,
10 GetCalendarInvitationsResponse,
11 } from '../../interfaces/calendar';
12 import { getIsOwnedCalendar } from '../calendar';
14 const getHasSharedCalendars = async ({
19 calendars: CalendarWithOwnMembers[];
21 catchErrors?: boolean;
23 const { signal, abort } = new AbortController();
24 const apiWithAbort = getApiWithAbort(api, signal);
26 let hasSharedCalendars = false;
30 .filter((calendar) => getIsOwnedCalendar(calendar))
31 .map(async ({ ID }) => {
33 const [{ CalendarUrls: links }, { Members }, { Invitations }] = await Promise.all([
34 apiWithAbort<CalendarUrlsResponse>(getPublicLinks(ID)),
35 apiWithAbort<GetAllMembersApiResponse>(getAllMembers(ID)),
36 apiWithAbort<GetCalendarInvitationsResponse>(getCalendarInvitations(ID)),
39 const pendingOrAcceptedInvitations = filterOutDeclinedInvitations(Invitations);
40 if (links.length || Members.length > 1 || pendingOrAcceptedInvitations.length) {
41 hasSharedCalendars = true;
47 e instanceof Error ? e : new Error('Unknown error getting calendar links or members');
55 return hasSharedCalendars;
58 export default getHasSharedCalendars;