[#446] removed direct state update (#468)

This commit is contained in:
Camille Moussu
2026-01-21 15:17:49 +01:00
committed by GitHub
parent 23d50f250d
commit 00742119be
38 changed files with 119 additions and 1366 deletions
@@ -1,10 +1,8 @@
import { AppDispatch } from "@/app/store";
import { User } from "@/components/Attendees/PeopleSearch";
import { formatLocalDateTime } from "@/components/Event/utils/dateTimeFormatters";
import { refreshCalendars } from "@/components/Event/utils/eventUtils";
import { updateEventLocal } from "@/features/Calendars/CalendarSlice";
import { Calendar } from "@/features/Calendars/CalendarTypes";
import {
getCalendarDetailAsync,
getEventAsync,
putEventAsync,
updateEventInstanceAsync,
@@ -14,21 +12,15 @@ import { getEvent } from "@/features/Events/EventApi";
import { CalendarEvent } from "@/features/Events/EventsTypes";
import { userAttendee } from "@/features/User/models/attendee";
import { createAttendee } from "@/features/User/models/attendee.mapper";
import {
formatDateToYYYYMMDDTHHMMSS,
getDeltaInMilliseconds,
} from "@/utils/dateUtils";
import { CalendarApi, DateSelectArg } from "@fullcalendar/core";
import { updateTempCalendar } from "../utils/calendarUtils";
import { getDeltaInMilliseconds } from "@/utils/dateUtils";
import { CalendarApi, DateSelectArg, EventDropArg } from "@fullcalendar/core";
import { EventResizeDoneArg } from "@fullcalendar/interaction";
export interface EventHandlersProps {
setSelectedRange: (range: DateSelectArg | null) => void;
setAnchorEl: (el: HTMLElement | null) => void;
calendarRef: React.RefObject<CalendarApi | null>;
selectedCalendars: string[];
tempcalendars: Record<string, Calendar>;
calendarRange: { start: Date; end: Date };
dispatch: any;
dispatch: AppDispatch;
setOpenEventDisplay: (open: boolean) => void;
setEventDisplayedId: (id: string) => void;
setEventDisplayedCalId: (id: string) => void;
@@ -47,9 +39,6 @@ export const createEventHandlers = (props: EventHandlersProps) => {
setSelectedRange,
setAnchorEl,
calendarRef,
selectedCalendars,
tempcalendars,
calendarRange,
dispatch,
setOpenEventDisplay,
setEventDisplayedId,
@@ -88,35 +77,10 @@ export const createEventHandlers = (props: EventHandlersProps) => {
setAnchorEl(document.body);
};
const handleClosePopover = (refresh?: boolean) => {
const handleClosePopover = () => {
calendarRef.current?.unselect();
setAnchorEl(null);
setSelectedRange(null);
if (refresh) {
selectedCalendars.forEach((calId) =>
dispatch(
getCalendarDetailAsync({
calId,
match: {
start: formatDateToYYYYMMDDTHHMMSS(calendarRange.start),
end: formatDateToYYYYMMDDTHHMMSS(calendarRange.end),
},
})
)
);
Object.keys(tempcalendars).forEach((calId) =>
dispatch(
getCalendarDetailAsync({
calId,
match: {
start: formatDateToYYYYMMDDTHHMMSS(calendarRange.start),
end: formatDateToYYYYMMDDTHHMMSS(calendarRange.end),
},
calType: "temp",
})
)
);
}
};
const handleCloseEventDisplay = () => {
@@ -151,11 +115,11 @@ export const createEventHandlers = (props: EventHandlersProps) => {
}
};
const handleEventAllow = (dropInfo: any, draggedEvent: any) => {
const handleEventAllow = () => {
return true;
};
const handleEventDrop = async (arg: any) => {
const handleEventDrop = async (arg: EventDropArg) => {
if (!arg.event || !arg.event._def || !arg.event._def.extendedProps) {
return;
}
@@ -182,7 +146,6 @@ export const createEventHandlers = (props: EventHandlersProps) => {
} as CalendarEvent,
true
);
if (isRecurring) {
setSelectedEvent(event);
setOpenEditModePopup("edit");
@@ -192,9 +155,6 @@ export const createEventHandlers = (props: EventHandlersProps) => {
await dispatch(
updateEventInstanceAsync({ cal: calendar, event: newEvent })
);
dispatch(
updateEventLocal({ calId: newEvent.calId, event: newEvent })
);
} else if (typeOfAction === "all") {
const master = await getEvent(newEvent, true);
await dispatch(
@@ -208,30 +168,17 @@ export const createEventHandlers = (props: EventHandlersProps) => {
},
})
);
await refreshCalendars(
dispatch,
Object.values(calendars),
calendarRange
);
await updateTempCalendar(
tempcalendars,
event,
dispatch,
calendarRange
);
}
}
);
} else {
dispatch(updateEventLocal({ calId: newEvent.calId, event: newEvent }));
await dispatch(
putEventAsync({ cal: calendars[newEvent.calId], newEvent })
);
}
await updateTempCalendar(tempcalendars, event, dispatch, calendarRange);
};
const handleEventResize = async (arg: any) => {
const handleEventResize = async (arg: EventResizeDoneArg) => {
if (!arg.event || !arg.event._def || !arg.event._def.extendedProps) {
return;
}
@@ -261,7 +208,6 @@ export const createEventHandlers = (props: EventHandlersProps) => {
} as CalendarEvent,
true
);
if (isRecurring) {
setSelectedEvent(event);
setOpenEditModePopup("edit");
@@ -271,9 +217,6 @@ export const createEventHandlers = (props: EventHandlersProps) => {
await dispatch(
updateEventInstanceAsync({ cal: calendar, event: newEvent })
);
dispatch(
updateEventLocal({ calId: newEvent.calId, event: newEvent })
);
} else if (typeOfAction === "all") {
const master = await getEvent(newEvent, true);
@@ -288,17 +231,6 @@ export const createEventHandlers = (props: EventHandlersProps) => {
},
})
);
await refreshCalendars(
dispatch,
Object.values(calendars),
calendarRange
);
await updateTempCalendar(
tempcalendars,
event,
dispatch,
calendarRange
);
}
}
);
@@ -307,7 +239,6 @@ export const createEventHandlers = (props: EventHandlersProps) => {
putEventAsync({ cal: calendars[newEvent.calId], newEvent })
);
}
await updateTempCalendar(tempcalendars, event, dispatch, calendarRange);
};
return {