From 9e7fa036ad3238d73c46ac29739868b1ec096b43 Mon Sep 17 00:00:00 2001 From: andrei Date: Mon, 2 Jun 2025 16:08:36 +0500 Subject: [PATCH] =?UTF-8?q?refactor:=20PatientsPage:=20=D0=9F=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D1=81=20PatientFormModal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Перенесен PatientFormModal в Dummies. Убрана логика модалки из usePatients. --- .../Pages/PatientsPage/PatientsPage.jsx | 8 +--- .../Pages/PatientsPage/usePatients.js | 45 ++----------------- 2 files changed, 5 insertions(+), 48 deletions(-) diff --git a/web-app/src/Components/Pages/PatientsPage/PatientsPage.jsx b/web-app/src/Components/Pages/PatientsPage/PatientsPage.jsx index f26922f..94c353f 100644 --- a/web-app/src/Components/Pages/PatientsPage/PatientsPage.jsx +++ b/web-app/src/Components/Pages/PatientsPage/PatientsPage.jsx @@ -19,7 +19,7 @@ import { TeamOutlined } from "@ant-design/icons"; import PatientListCard from "../../Dummies/PatientListCard.jsx"; -import PatientFormModal from "./Components/PatientFormModal/PatientFormModal.jsx"; +import PatientFormModal from "../../Dummies/PatientFormModal/PatientFormModal.jsx"; import SelectViewMode from "../../Widgets/SelectViewMode.jsx"; import LoadingIndicator from "../../Widgets/LoadingIndicator.jsx"; import usePatients from "./usePatients.js"; @@ -186,11 +186,7 @@ const PatientsPage = () => { tooltip="Добавить пациента" /> - + ); }; diff --git a/web-app/src/Components/Pages/PatientsPage/usePatients.js b/web-app/src/Components/Pages/PatientsPage/usePatients.js index 78fe3e2..515f45f 100644 --- a/web-app/src/Components/Pages/PatientsPage/usePatients.js +++ b/web-app/src/Components/Pages/PatientsPage/usePatients.js @@ -1,24 +1,14 @@ -import { useDispatch, useSelector } from "react-redux"; -import { notification } from "antd"; +import {notification} from "antd"; import { - useAddPatientMutation, useDeletePatientMutation, useGetPatientsQuery, - useUpdatePatientMutation } from "../../../Api/patientsApi.js"; -import {closeModal} from "../../../Redux/Slices/patientsSlice.js"; const usePatients = () => { - const dispatch = useDispatch(); - const { - selectedPatient, - } = useSelector(state => state.patientsUI); - - const { data: patients = [], isLoading, isError } = useGetPatientsQuery(undefined, { + const {data: patients = [], isLoading, isError} = useGetPatientsQuery(undefined, { pollingInterval: 20000, }); - const [addPatient] = useAddPatientMutation(); - const [updatePatient] = useUpdatePatientMutation(); + const [deletePatient] = useDeletePatientMutation(); const handleDeletePatient = async (patientId) => { @@ -38,40 +28,11 @@ const usePatients = () => { } }; - const handleModalSubmit = async (patientData) => { - dispatch(closeModal()); - - try { - if (selectedPatient) { - await updatePatient({ id: selectedPatient.id, ...patientData }).unwrap(); - notification.success({ - message: "Пациент обновлён", - description: `Данные пациента ${patientData.first_name} ${patientData.last_name} успешно обновлены.`, - placement: "topRight", - }); - } else { - await addPatient(patientData).unwrap(); - notification.success({ - message: "Пациент добавлен", - description: `Пациент ${patientData.first_name} ${patientData.last_name} успешно добавлен.`, - placement: "topRight", - }); - } - } catch (error) { - notification.error({ - message: "Ошибка", - description: error.data?.message || "Произошла ошибка при сохранении", - placement: "topRight", - }); - } - }; - return { patients, isLoading, isError, handleDeletePatient, - handleModalSubmit, }; };