починил переключение месяцев в календаре

This commit is contained in:
Андрей Дувакин 2025-06-01 22:52:16 +05:00
parent a9c5f87104
commit 2ad1711d15
4 changed files with 50 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import { Calendar } from "antd"; import { Calendar } from "antd";
import 'dayjs/locale/ru'; import "dayjs/locale/ru";
import CalendarCell from "../../../../Widgets/CalendarCell.jsx"; import CalendarCell from "../../../../Widgets/CalendarCell.jsx";
import useAppointments from "../../useAppointments.js"; import useAppointments from "../../useAppointments.js";
import useAppointmentCalendarUI from "./useAppointmentCalendarUI.js"; import useAppointmentCalendarUI from "./useAppointmentCalendarUI.js";
@ -45,6 +45,7 @@ const AppointmentsCalendarTab = () => {
fullscreen={appointmentsCalendarUI.fullScreenCalendar} fullscreen={appointmentsCalendarUI.fullScreenCalendar}
value={appointmentsCalendarUI.selectedDate} value={appointmentsCalendarUI.selectedDate}
onSelect={appointmentsCalendarUI.onSelect} onSelect={appointmentsCalendarUI.onSelect}
onPanelChange={appointmentsCalendarUI.onPanelChange}
cellRender={dateCellRender} cellRender={dateCellRender}
/> />
<AppointmentsListModal /> <AppointmentsListModal />

View File

@ -7,17 +7,18 @@ import {
openAppointmentsListModal, openAppointmentsListModal,
setSelectedAppointment, setSelectedAppointment,
setSelectedScheduledAppointment, setSelectedScheduledAppointment,
setSelectedDate,
} from "../../../../../Redux/Slices/appointmentsSlice.js"; } from "../../../../../Redux/Slices/appointmentsSlice.js";
dayjs.extend(utc); dayjs.extend(utc);
dayjs.extend(timezone); dayjs.extend(timezone);
dayjs.tz.setDefault('Europe/Moscow'); dayjs.tz.setDefault("Europe/Moscow");
const { useBreakpoint } = Grid; const { useBreakpoint } = Grid;
const useAppointmentCalendarUI = (appointments, scheduledAppointments) => { const useAppointmentCalendarUI = (appointments, scheduledAppointments) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const selectedDate = dayjs.tz(useSelector((state) => state.appointmentsUI.selectedDate), 'Europe/Moscow'); const selectedDate = dayjs.tz(useSelector((state) => state.appointmentsUI.selectedDate), "Europe/Moscow");
const screens = useBreakpoint(); const screens = useBreakpoint();
const fullScreenCalendar = !screens.xs; const fullScreenCalendar = !screens.xs;
@ -25,14 +26,19 @@ const useAppointmentCalendarUI = (appointments, scheduledAppointments) => {
const calendarContainerStyle = { padding: 20 }; const calendarContainerStyle = { padding: 20 };
const onSelect = (date) => { const onSelect = (date) => {
const selectedDateStr = date.format('YYYY-MM-DD'); const selectedDateStr = date.format("YYYY-MM-DD");
const appointmentsForDate = appointments.filter((app) => const appointmentsForDate = appointments.filter((app) =>
dayjs(app.appointment_datetime).format('YYYY-MM-DD') === selectedDateStr dayjs(app.appointment_datetime).format("YYYY-MM-DD") === selectedDateStr
); );
const scheduledForDate = scheduledAppointments.filter((app) => const scheduledForDate = scheduledAppointments.filter((app) =>
dayjs(app.scheduled_datetime).format('YYYY-MM-DD') === selectedDateStr dayjs(app.scheduled_datetime).format("YYYY-MM-DD") === selectedDateStr
); );
dispatch(openAppointmentsListModal([...appointmentsForDate, ...scheduledForDate])); dispatch(openAppointmentsListModal([...appointmentsForDate, ...scheduledForDate]));
dispatch(setSelectedDate(date.toISOString()));
};
const onPanelChange = (date) => {
dispatch(setSelectedDate(date.startOf("month").toISOString()));
}; };
const onOpenAppointmentModal = (appointment) => { const onOpenAppointmentModal = (appointment) => {
@ -44,9 +50,9 @@ const useAppointmentCalendarUI = (appointments, scheduledAppointments) => {
}; };
const getAppointmentsByListAndDate = (list, value, isScheduled = false) => { const getAppointmentsByListAndDate = (list, value, isScheduled = false) => {
const date = value.format('YYYY-MM-DD'); const date = value.format("YYYY-MM-DD");
return list.filter((app) => return list.filter((app) =>
dayjs(isScheduled ? app.scheduled_datetime : app.appointment_datetime).format('YYYY-MM-DD') === date dayjs(isScheduled ? app.scheduled_datetime : app.appointment_datetime).format("YYYY-MM-DD") === date
); );
}; };
@ -55,6 +61,7 @@ const useAppointmentCalendarUI = (appointments, scheduledAppointments) => {
fullScreenCalendar, fullScreenCalendar,
calendarContainerStyle, calendarContainerStyle,
onSelect, onSelect,
onPanelChange,
getAppointmentsByListAndDate, getAppointmentsByListAndDate,
onOpenAppointmentModal, onOpenAppointmentModal,
}; };

View File

@ -1,11 +1,11 @@
import { useEffect, useRef, useState } from "react"; import {useEffect, useRef, useState} from "react";
import { Badge, Col, Tag, Tooltip } from "antd"; import {Badge, Col, Tag, Tooltip} from "antd";
import dayjs from "dayjs"; import dayjs from "dayjs";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { AppointmentPropType } from "../../Types/appointmentPropType.js"; import {AppointmentPropType} from "../../Types/appointmentPropType.js";
import { ScheduledAppointmentPropType } from "../../Types/scheduledAppointmentPropType.js"; import {ScheduledAppointmentPropType} from "../../Types/scheduledAppointmentPropType.js";
const CalendarCell = ({ allAppointments, onCellClick, onItemClick }) => { const CalendarCell = ({allAppointments, onCellClick, onItemClick}) => {
const containerRef = useRef(null); const containerRef = useRef(null);
const [isCompressed, setIsCompressed] = useState(false); const [isCompressed, setIsCompressed] = useState(false);
const COMPRESSION_THRESHOLD = 70; const COMPRESSION_THRESHOLD = 70;
@ -33,9 +33,9 @@ const CalendarCell = ({ allAppointments, onCellClick, onItemClick }) => {
}} }}
> >
{!isCompressed && ( {!isCompressed && (
<ul style={{ padding: 0, margin: 0 }}> <ul style={{padding: 0, margin: 0}}>
{allAppointments.map((app) => ( {allAppointments.map((app) => (
<Col key={app.id} style={{ overflowX: "hidden" }}> <Col key={app.id} style={{overflowX: "hidden"}}>
<Tooltip <Tooltip
title={`${ title={`${
app.appointment_datetime ? "Прошедший прием" : "Запланированный прием" app.appointment_datetime ? "Прошедший прием" : "Запланированный прием"
@ -47,13 +47,31 @@ const CalendarCell = ({ allAppointments, onCellClick, onItemClick }) => {
e.stopPropagation(); e.stopPropagation();
onItemClick(app); onItemClick(app);
}} }}
style={{ margin: "2px 2px 0 0", cursor: "pointer", width: "95%", minHeight: 30 }} style={{
margin: "2px 2px 0 0",
cursor: "pointer",
width: "95%",
minHeight: 30,
display: "flex",
alignItems: "center",
overflow: "hidden",
}}
> >
<Badge <Badge
status={app.appointment_datetime ? "success" : "processing"} status={app.appointment_datetime ? "success" : "processing"}
text={ text={
dayjs(app.appointment_datetime || app.scheduled_datetime).format("HH:mm") + <span
` ${app.patient?.last_name || ""} ${app.patient?.first_name || ""}` style={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
display: "inline-block",
width: "100%",
}}
>
{dayjs(app.appointment_datetime || app.scheduled_datetime).format("HH:mm") +
` ${app.patient?.last_name || ""} ${app.patient?.first_name || ""}`}
</span>
} }
/> />
</Tag> </Tag>

View File

@ -1,6 +1,8 @@
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
import dayjs from "dayjs";
const initialState = { const initialState = {
selectedDate: dayjs().toISOString(),
modalVisible: false, modalVisible: false,
collapsed: true, collapsed: true,
siderWidth: 300, siderWidth: 300,
@ -17,6 +19,9 @@ const appointmentsSlice = createSlice({
name: 'appointmentsUI', name: 'appointmentsUI',
initialState, initialState,
reducers: { reducers: {
setSelectedDate(state, action) {
state.selectedDate = action.payload;
},
openModal(state) { openModal(state) {
state.modalVisible = true; state.modalVisible = true;
}, },
@ -60,6 +65,7 @@ const appointmentsSlice = createSlice({
}); });
export const { export const {
setSelectedDate,
openModal, openModal,
closeModal, closeModal,
toggleSider, toggleSider,