feat: agregar referencia actual de fecha en el manejo de citas y mejorar la lógica de movimiento de citas

This commit is contained in:
2026-08-29 11:43:56 -03:00
parent 95b3e3698b
commit 48ed64eb87
2 changed files with 18 additions and 7 deletions
@@ -204,6 +204,9 @@ export default function OrganizationProfile() {
const [currentDate, setCurrentDate] = useState<dayjs.Dayjs>(appointmentDate);
const currentDateRef = useRef(currentDate);
currentDateRef.current = currentDate;
const [calendarEventsCount, setCalendarEventsCount] = useState<number>(0);
const [calendarFrom, setCalendarFrom] = useState<number>(8);
const [calendarTo, setCalendarTo] = useState<number>(23);
@@ -421,32 +424,35 @@ export default function OrganizationProfile() {
const handleMoveAppointment = async (newDay: dayjs.Dayjs) => {
if (!copiedAppointment || !copiedAppointment.appointmentId) return;
const moveAppointment = useClipboardStore.getState().copiedAppointment;
if (!moveAppointment || !moveAppointment.appointmentId) return;
timePicker.hide();
eventHandler.setEventType(EVENT_TYPES.LOADING);
const newStart = dayjs(currentDate).hour(newDay.hour()).minute(newDay.minute()).second(0).millisecond(0).toISOString();
const oldStart = dayjs(copiedAppointment.startTime);
const oldEnd = dayjs(copiedAppointment.endTime);
const newStart = currentDateRef.current.hour(newDay.hour()).minute(newDay.minute()).second(0).millisecond(0).toISOString();
const oldStart = dayjs(moveAppointment.startTime);
const oldEnd = dayjs(moveAppointment.endTime);
const durationMin = oldEnd.diff(oldStart, 'minute');
const newEnd = dayjs(newStart).add(durationMin, 'minute').toISOString();
try {
await ApiRequest.post("/appointments/move-appointment-force", {
id: copiedAppointment.appointmentId,
id: moveAppointment.appointmentId,
companyId: id,
newStart: newStart,
newEnd: newEnd,
sessionUser: SessionInfo.userId,
});
alert.showSuccess("Turno movido con éxito");
setCopiedAppointment(null);
useClipboardStore.getState().setCopiedAppointment(null);
loadCalendarData();
} catch (error: unknown) {
console.error(error);
alert.showError("Error al mover el turno");
} finally {
eventHandler.setEventType(copiedAppointment ? EVENT_TYPES.SLEEP : EVENT_TYPES.NEED_ADD);
eventHandler.setEventType(
useClipboardStore.getState().copiedAppointment ? EVENT_TYPES.SLEEP : EVENT_TYPES.NEED_ADD
);
}
};