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:
+13
-7
@@ -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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user