134 lines
4.1 KiB
JavaScript
134 lines
4.1 KiB
JavaScript
import {useGetAppointmentsQuery} from "../../../Api/appointmentsApi.js";
|
|
import {useGetScheduledAppointmentsQuery} from "../../../Api/scheduledAppointmentsApi.js";
|
|
import {useGetAllPatientsQuery} from "../../../Api/patientsApi.js";
|
|
import {notification} from "antd";
|
|
import {useEffect} from "react";
|
|
import {useDispatch, useSelector} from "react-redux";
|
|
import {
|
|
setSelectedAppointment,
|
|
setSelectedScheduledAppointment,
|
|
openModal as openAppointmentsListModal,
|
|
openScheduledModal,
|
|
} from "../../../Redux/Slices/appointmentsSlice.js";
|
|
import {
|
|
openModal as openPatientModal,
|
|
} from "../../../Redux/Slices/patientsSlice.js";
|
|
import dayjs from "dayjs";
|
|
import isBetween from "dayjs/plugin/isBetween";
|
|
import {useGetAppointmentTypesQuery} from "../../../Api/appointmentTypesApi.js";
|
|
|
|
dayjs.extend(isBetween);
|
|
|
|
const useHomePage = () => {
|
|
const dispatch = useDispatch();
|
|
|
|
const {
|
|
userData
|
|
} = useSelector((state) => state.auth);
|
|
|
|
const {
|
|
data: appointments = [],
|
|
isLoading: isLoadingAppointments,
|
|
isError: isErrorAppointments,
|
|
} = useGetAppointmentsQuery((userData.id), {
|
|
pollingInterval: 20000,
|
|
});
|
|
|
|
const {
|
|
data: scheduledAppointments = [],
|
|
isLoading: isLoadingScheduledAppointments,
|
|
isError: isErrorScheduledAppointments,
|
|
} = useGetScheduledAppointmentsQuery((userData.id), {
|
|
pollingInterval: 20000,
|
|
});
|
|
|
|
const {
|
|
data: patients = [],
|
|
isLoading: isLoadingPatients,
|
|
isError: isErrorPatients,
|
|
} = useGetAllPatientsQuery(undefined, {
|
|
pollingInterval: 20000,
|
|
});
|
|
|
|
const {
|
|
data: appointmentTypes = [],
|
|
isLoading: isLoadingAppointmentTypes,
|
|
isError: isErrorAppointmentTypes,
|
|
} = useGetAppointmentTypesQuery(undefined, {
|
|
pollingInterval: 20000,
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (isErrorAppointments) {
|
|
notification.error({
|
|
message: "Ошибка",
|
|
description: "Ошибка загрузки приемов.",
|
|
placement: "topRight",
|
|
});
|
|
}
|
|
if (isErrorScheduledAppointments) {
|
|
notification.error({
|
|
message: "Ошибка",
|
|
description: "Ошибка загрузки запланированных приемов.",
|
|
placement: "topRight",
|
|
});
|
|
}
|
|
if (isErrorPatients) {
|
|
notification.error({
|
|
message: "Ошибка",
|
|
description: "Ошибка загрузки пациентов.",
|
|
placement: "topRight",
|
|
});
|
|
}
|
|
if (isErrorAppointmentTypes) {
|
|
notification.error({
|
|
message: "Ошибка",
|
|
description: "Ошибка загрузки типов приемов.",
|
|
placement: "topRight",
|
|
});
|
|
}
|
|
}, [isErrorAppointments, isErrorScheduledAppointments, isErrorPatients, isErrorAppointmentTypes]);
|
|
|
|
const handleEventClick = (event) => {
|
|
if (event.appointment_datetime) {
|
|
dispatch(setSelectedAppointment(event));
|
|
} else {
|
|
dispatch(setSelectedScheduledAppointment(event));
|
|
}
|
|
};
|
|
|
|
const handleCreateAppointment = () => {
|
|
dispatch(openAppointmentsListModal());
|
|
};
|
|
|
|
const handleCreateScheduledAppointment = () => {
|
|
dispatch(openScheduledModal());
|
|
};
|
|
|
|
const handleCreatePatient = () => {
|
|
dispatch(openPatientModal());
|
|
};
|
|
|
|
return {
|
|
patients,
|
|
appointments,
|
|
scheduledAppointments,
|
|
appointmentTypes,
|
|
isLoading:
|
|
isLoadingAppointments ||
|
|
isLoadingScheduledAppointments ||
|
|
isLoadingPatients ||
|
|
isLoadingAppointmentTypes,
|
|
isError:
|
|
isErrorAppointments ||
|
|
isErrorScheduledAppointments ||
|
|
isErrorPatients ||
|
|
isErrorAppointmentTypes,
|
|
handleEventClick,
|
|
handleCreateAppointment,
|
|
handleCreateScheduledAppointment,
|
|
handleCreatePatient,
|
|
};
|
|
};
|
|
|
|
export default useHomePage; |