refactor: PatientsPage: Перенос PatientFormModal
Перенесен PatientFormModal в Dummies. Убрана логика модалки из usePatients.
This commit is contained in:
parent
4648f638a3
commit
9e7fa036ad
@ -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="Добавить пациента"
|
||||
/>
|
||||
|
||||
<PatientFormModal
|
||||
visible={patientsUI.isModalVisible}
|
||||
onCancel={patientsUI.handleCloseModal}
|
||||
onSubmit={patientsData.handleModalSubmit}
|
||||
/>
|
||||
<PatientFormModal/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user