diff --git a/__test__/components/Calendar.test.tsx b/__test__/components/Calendar.test.tsx
index 8417c68..50abad8 100644
--- a/__test__/components/Calendar.test.tsx
+++ b/__test__/components/Calendar.test.tsx
@@ -250,4 +250,21 @@ describe("calendar Availability search", () => {
expect(spy).not.toHaveBeenCalledWith();
});
+
+ it("BUGFIX: can untoggle all personnal calendars", () => {
+ renderWithProviders(, {
+ user: preloadedState.user,
+ calendars: {
+ list: { "user1/cal1": preloadedState.calendars.list["user1/cal1"] },
+ pending: false,
+ },
+ });
+
+ const checkbox = screen.getByLabelText("Calendar personnal");
+ expect(checkbox).toBeChecked();
+
+ fireEvent.click(checkbox); // toggle off
+
+ expect(checkbox).not.toBeChecked();
+ });
});
diff --git a/src/components/Calendar/Calendar.tsx b/src/components/Calendar/Calendar.tsx
index 795e538..ea21eb3 100644
--- a/src/components/Calendar/Calendar.tsx
+++ b/src/components/Calendar/Calendar.tsx
@@ -100,18 +100,17 @@ export default function CalendarApp({
const fetchedRangesRef = useRef>({});
// Auto-select personal calendars when first loaded
+ const initialLoadRef = useRef(true);
+
useEffect(() => {
- if (
- Object.keys(calendars).length > 0 &&
- userId &&
- selectedCalendars.length === 0
- ) {
+ if (initialLoadRef.current && Object.keys(calendars).length > 0 && userId) {
const personalCalendarIds = Object.keys(calendars).filter(
(id) => id.split("/")[0] === userId
);
setSelectedCalendars(personalCalendarIds);
+ initialLoadRef.current = false;
}
- }, [calendars, userId, selectedCalendars.length]);
+ }, [calendars, userId]);
const calendarRange = getCalendarRange(selectedDate);
diff --git a/src/components/Calendar/utils/calendarUtils.ts b/src/components/Calendar/utils/calendarUtils.ts
index 4852fb4..85ae9d8 100644
--- a/src/components/Calendar/utils/calendarUtils.ts
+++ b/src/components/Calendar/utils/calendarUtils.ts
@@ -94,7 +94,7 @@ export const updateCalsDetails = (
});
if (rangeKey !== previousRangeKey) {
- selectedCalendars.forEach((id) => {
+ selectedCalendars?.forEach((id) => {
dispatch(
getCalendarDetailAsync({
calId: id,