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 [currentDate, setCurrentDate] = useState<dayjs.Dayjs>(appointmentDate);
const currentDateRef = useRef(currentDate);
currentDateRef.current = currentDate;
const [calendarEventsCount, setCalendarEventsCount] = useState<number>(0); const [calendarEventsCount, setCalendarEventsCount] = useState<number>(0);
const [calendarFrom, setCalendarFrom] = useState<number>(8); const [calendarFrom, setCalendarFrom] = useState<number>(8);
const [calendarTo, setCalendarTo] = useState<number>(23); const [calendarTo, setCalendarTo] = useState<number>(23);
@@ -421,32 +424,35 @@ export default function OrganizationProfile() {
const handleMoveAppointment = async (newDay: dayjs.Dayjs) => { const handleMoveAppointment = async (newDay: dayjs.Dayjs) => {
if (!copiedAppointment || !copiedAppointment.appointmentId) return; const moveAppointment = useClipboardStore.getState().copiedAppointment;
if (!moveAppointment || !moveAppointment.appointmentId) return;
timePicker.hide(); timePicker.hide();
eventHandler.setEventType(EVENT_TYPES.LOADING); eventHandler.setEventType(EVENT_TYPES.LOADING);
const newStart = dayjs(currentDate).hour(newDay.hour()).minute(newDay.minute()).second(0).millisecond(0).toISOString(); const newStart = currentDateRef.current.hour(newDay.hour()).minute(newDay.minute()).second(0).millisecond(0).toISOString();
const oldStart = dayjs(copiedAppointment.startTime); const oldStart = dayjs(moveAppointment.startTime);
const oldEnd = dayjs(copiedAppointment.endTime); const oldEnd = dayjs(moveAppointment.endTime);
const durationMin = oldEnd.diff(oldStart, 'minute'); const durationMin = oldEnd.diff(oldStart, 'minute');
const newEnd = dayjs(newStart).add(durationMin, 'minute').toISOString(); const newEnd = dayjs(newStart).add(durationMin, 'minute').toISOString();
try { try {
await ApiRequest.post("/appointments/move-appointment-force", { await ApiRequest.post("/appointments/move-appointment-force", {
id: copiedAppointment.appointmentId, id: moveAppointment.appointmentId,
companyId: id, companyId: id,
newStart: newStart, newStart: newStart,
newEnd: newEnd, newEnd: newEnd,
sessionUser: SessionInfo.userId, sessionUser: SessionInfo.userId,
}); });
alert.showSuccess("Turno movido con éxito"); alert.showSuccess("Turno movido con éxito");
setCopiedAppointment(null); useClipboardStore.getState().setCopiedAppointment(null);
loadCalendarData(); loadCalendarData();
} catch (error: unknown) { } catch (error: unknown) {
console.error(error); console.error(error);
alert.showError("Error al mover el turno"); alert.showError("Error al mover el turno");
} finally { } finally {
eventHandler.setEventType(copiedAppointment ? EVENT_TYPES.SLEEP : EVENT_TYPES.NEED_ADD); eventHandler.setEventType(
useClipboardStore.getState().copiedAppointment ? EVENT_TYPES.SLEEP : EVENT_TYPES.NEED_ADD
);
} }
}; };
@@ -40,6 +40,11 @@ export default function TimePicker(): React.ReactElement {
sx={{ borderRadius: "8px" }} sx={{ borderRadius: "8px" }}
className={style.timePicker} className={style.timePicker}
onClose={() => timePickerState.hide()} onClose={() => timePickerState.hide()}
onChange={(newValue: dayjs.Dayjs | null) => {
if (newValue) {
timePickerState.setValue(newValue);
}
}}
onAccept={(newValue: dayjs.Dayjs | null) => { onAccept={(newValue: dayjs.Dayjs | null) => {
if (newValue) { if (newValue) {
timePickerState.setValue(newValue); timePickerState.setValue(newValue);