useLayoutEffect(() => {
if (pickedService.length > 0 && gender !== "") {
pickedService.forEach((service) => {
let event = calendarRef.current!.control.events.find(
service.extra.appointment_id ?? service.service.id_service
);
if (service.extra.toDelete === false) {
if (event !== null) {
let clientName = setIsEditingEventPosition(true);
calendarRef.current!.control.events.update({
id: service.extra.appointment_id ?? service.service.id_service,
text: service.service.id_service,
start: service.date!["start"],
end: service.date!["end"],
resource: service.resource?.id ?? 0,
cssClass: pickedService.some(
(service) => service.extra.appointment_id
) ? "draft_selected_event" : "draft_selected_event",
barHidden: true,
tag: {
marker: service.service.ec_color_light,
client: (!name ? "" : name) + " " + (surname ?? (surname || (watchFields.id_cus === undefined ? { m: "Uomo", f: "Donna", b: "Bimbo" }[gender] || "" : extractGenderFromID(watchFields.id_cus!)))),
service: service.service.name,
writtenNote: note,
note: note,
heart: service.extra.worker_lock !== "0",
clock: service.extra.time_lock !== "0",
},
});
} else {
setIsEditingEventPosition(true);
const event = new DayPilot.Event({
id: service.extra.appointment_id ?? service.service.id_service,
text: service.service.id_service,
start: service.date!["start"],
end: service.date!["end"],
resource: service.resource.id,
barHidden: true,
cssClass: "draft_selected_event",
tag: {
marker: service.service.ec_color_light,
service: service.service.name,
client: (!name ? "" : name) + " " + (surname ?? (surname || (watchFields.id_cus === undefined ? { m: "Uomo", f: "Donna", b: "Bimbo" }[gender] || "" : extractGenderFromID(watchFields.id_cus!)))),
writtenNote: note,
note: note,
heart: service.extra.worker_lock === "1",
clock: service.extra.time_lock === "1",
},
});
calendarRef.current?.control.events.add(event);
}
}
});
} else {
// Handle the else condition here if needed
}
}, [
pickedService,
gender,
deferredQueryName,
deferredQuerySurname,
deferredNote,
isEditListModalOpen,
]);
it works in previous version but not in this one, why?