diff --git a/txclient/src/app/admin/(organization-profile)/org/profile/[id]/appointments/[appdate]/page.tsx b/txclient/src/app/admin/(organization-profile)/org/profile/[id]/appointments/[appdate]/page.tsx index 18c95c1..a659551 100644 --- a/txclient/src/app/admin/(organization-profile)/org/profile/[id]/appointments/[appdate]/page.tsx +++ b/txclient/src/app/admin/(organization-profile)/org/profile/[id]/appointments/[appdate]/page.tsx @@ -204,6 +204,9 @@ export default function OrganizationProfile() { const [currentDate, setCurrentDate] = useState(appointmentDate); + const currentDateRef = useRef(currentDate); + currentDateRef.current = currentDate; + const [calendarEventsCount, setCalendarEventsCount] = useState(0); const [calendarFrom, setCalendarFrom] = useState(8); const [calendarTo, setCalendarTo] = useState(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 + ); } }; diff --git a/txclient/src/app/components/TimePicker/TimePicker.tsx b/txclient/src/app/components/TimePicker/TimePicker.tsx index d103db7..ecdc4a3 100644 --- a/txclient/src/app/components/TimePicker/TimePicker.tsx +++ b/txclient/src/app/components/TimePicker/TimePicker.tsx @@ -40,6 +40,11 @@ export default function TimePicker(): React.ReactElement { sx={{ borderRadius: "8px" }} className={style.timePicker} onClose={() => timePickerState.hide()} + onChange={(newValue: dayjs.Dayjs | null) => { + if (newValue) { + timePickerState.setValue(newValue); + } + }} onAccept={(newValue: dayjs.Dayjs | null) => { if (newValue) { timePickerState.setValue(newValue);