From 4d16d1913208a919fa72769e81989b0f7d614482 Mon Sep 17 00:00:00 2001 From: Camille Moussu <66134347+Eriikah@users.noreply.github.com> Date: Tue, 3 Mar 2026 21:12:45 +0100 Subject: [PATCH] [#596] displays all calendar from user in search even if one of them is present in the list of shared/delegated calendars (#604) Co-authored-by: Camille Moussu --- __test__/components/Calendar.test.tsx | 30 ------------ src/components/Calendar/Calendar.tsx | 2 - .../Calendar/TempCalendarsInput.tsx | 46 ++----------------- 3 files changed, 3 insertions(+), 75 deletions(-) diff --git a/__test__/components/Calendar.test.tsx b/__test__/components/Calendar.test.tsx index 1e7a38e..eed8155 100644 --- a/__test__/components/Calendar.test.tsx +++ b/__test__/components/Calendar.test.tsx @@ -290,36 +290,6 @@ describe("calendar Availability search", () => { expect(spy).toHaveBeenCalled(); }); - it("does not import temp calendars if user already has a calendar but toggles the shared one", async () => { - mockedSearchUsers.mockResolvedValueOnce([ - { - email: "alice@example.com", - displayName: "Alice", - avatarUrl: "image.png", - openpaasId: "1234567890", - }, - ]); - const spy = jest - .spyOn(servicesModule, "getTempCalendarsListAsync") - .mockImplementation((payload) => { - return () => Promise.resolve(payload) as any; - }); - await act(async () => - renderWithProviders(, preloadedState) - ); - - const input = screen.getByPlaceholderText( - "peopleSearch.availabilityPlaceholder" - ); - await act(async () => userEvent.type(input, "Alice")); - - const option = await screen.findByText("Alice"); - await act(async () => { - fireEvent.click(option); - }); - expect(spy).not.toHaveBeenCalled(); - }); - it("open window with attendees filled after temp search on create event button click", async () => { const spy = jest .spyOn(servicesModule, "getTempCalendarsListAsync") diff --git a/src/components/Calendar/Calendar.tsx b/src/components/Calendar/Calendar.tsx index 3610d7f..beb268d 100644 --- a/src/components/Calendar/Calendar.tsx +++ b/src/components/Calendar/Calendar.tsx @@ -646,8 +646,6 @@ export default function CalendarApp({ handleToggleEventPreview={() => { eventHandlers.handleDateSelect(null as unknown as DateSelectArg); }} - selectedCalendars={selectedCalendars} - setSelectedCalendars={setSelectedCalendars} />
diff --git a/src/components/Calendar/TempCalendarsInput.tsx b/src/components/Calendar/TempCalendarsInput.tsx index f69cb34..d483cbd 100644 --- a/src/components/Calendar/TempCalendarsInput.tsx +++ b/src/components/Calendar/TempCalendarsInput.tsx @@ -15,19 +15,14 @@ export function TempCalendarsInput({ tempUsers, setTempUsers, handleToggleEventPreview, - selectedCalendars, - setSelectedCalendars, }: { tempUsers: User[]; setTempUsers: (users: User[]) => void; handleToggleEventPreview: () => void; - selectedCalendars: string[]; - setSelectedCalendars: React.Dispatch>; }) { const dispatch = useAppDispatch(); const tempcalendars = useAppSelector((state) => state.calendars.templist) ?? {}; - const calendars = useAppSelector((state) => state.calendars.list); const theme = useTheme(); const { t } = useI18n(); @@ -48,14 +43,9 @@ export function TempCalendarsInput({ prevUsersRef.current = users; - const { calendarsToImport, calendarsToToggle } = getCalendarsFromUsersDelta( - addedUsers, - buildEmailToCalendarMap(calendars), - selectedCalendars - ); - - if (calendarsToImport.length > 0) { - for (const user of calendarsToImport) { + if (addedUsers.length > 0) { + dispatch(setView("calendar")); + for (const user of addedUsers) { const controller = new AbortController(); requestControllers.set(user.email, controller); @@ -70,19 +60,12 @@ export function TempCalendarsInput({ light: lightColor, dark: getAccessiblePair(lightColor, theme), }; - dispatch(setView("calendar")); dispatch( getTempCalendarsListAsync(user, { signal: controller.signal }) ); } } - if (calendarsToToggle.length > 0) { - setSelectedCalendars((prev: string[]) => [ - ...new Set([...prev, ...calendarsToToggle]), - ]); - } - for (const user of removedUsers) { const controller = requestControllers.get(user.email); if (controller) { @@ -108,29 +91,6 @@ export function TempCalendarsInput({ ); } -function getCalendarsFromUsersDelta( - addedUsers: User[], - emailToCalendarId: Map, - selectedCalendars: string[] -) { - const selectedSet = new Set(selectedCalendars); - - const calendarsToImport: User[] = []; - const calendarsToToggle: string[] = []; - - for (const user of addedUsers) { - const calIds = emailToCalendarId.get(user.email) ?? []; - - if (!calIds || calIds.every((calId) => !selectedSet.has(calId))) { - calendarsToImport.push(user); - } else { - // calIds.forEach((calId) => calendarsToToggle.push(calId)); - } - } - - return { calendarsToImport, calendarsToToggle }; -} - function buildEmailToCalendarMap(calRecord: Record) { const map = new Map(); for (const [id, cal] of Object.entries(calRecord)) {