сделал уведомления на действия пользователя
This commit is contained in:
parent
1c53632382
commit
1da1b70d5e
@ -1,5 +1,5 @@
|
|||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {Input, Select, List, FloatButton, Row, Col, Spin} from "antd";
|
import {Input, Select, List, FloatButton, Row, Col, Spin, notification} from "antd";
|
||||||
import {LoadingOutlined, PlusOutlined} from "@ant-design/icons";
|
import {LoadingOutlined, PlusOutlined} from "@ant-design/icons";
|
||||||
import {useAuth} from "../AuthContext.jsx";
|
import {useAuth} from "../AuthContext.jsx";
|
||||||
import getAllPatients from "../api/patients/GetAllPatients.jsx";
|
import getAllPatients from "../api/patients/GetAllPatients.jsx";
|
||||||
@ -7,7 +7,7 @@ import PatientListCard from "../components/PatientListCard.jsx";
|
|||||||
import PatientModal from "../components/PatientModal.jsx";
|
import PatientModal from "../components/PatientModal.jsx";
|
||||||
import updatePatient from "../api/patients/UpdatePatient.jsx";
|
import updatePatient from "../api/patients/UpdatePatient.jsx";
|
||||||
import addPatient from "../api/patients/AddPatient.jsx";
|
import addPatient from "../api/patients/AddPatient.jsx";
|
||||||
import deletePatient from "../api/patients/DeletePatient.jsx"; // Подключаем модальное окно
|
import deletePatient from "../api/patients/DeletePatient.jsx";
|
||||||
|
|
||||||
const {Option} = Select;
|
const {Option} = Select;
|
||||||
|
|
||||||
@ -32,7 +32,6 @@ const PatientsPage = () => {
|
|||||||
}
|
}
|
||||||
}, [user, isModalVisible]);
|
}, [user, isModalVisible]);
|
||||||
|
|
||||||
|
|
||||||
const fetchPatients = async () => {
|
const fetchPatients = async () => {
|
||||||
if (!user || !user.token) return;
|
if (!user || !user.token) return;
|
||||||
|
|
||||||
@ -41,10 +40,15 @@ const PatientsPage = () => {
|
|||||||
setPatients(data);
|
setPatients(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
|
notification.error({
|
||||||
|
message: "Ошибка загрузки данных",
|
||||||
|
description: "Проверьте подключение к сети.",
|
||||||
|
placement: "topRight",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
setLoading(false)
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,8 +76,18 @@ const PatientsPage = () => {
|
|||||||
try {
|
try {
|
||||||
await deletePatient(user.token, patient_id);
|
await deletePatient(user.token, patient_id);
|
||||||
await fetchPatients();
|
await fetchPatients();
|
||||||
|
notification.success({
|
||||||
|
message: "Пациент удалён",
|
||||||
|
description: "Пациент успешно удалён из базы.",
|
||||||
|
placement: "topRight",
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
|
notification.error({
|
||||||
|
message: "Ошибка удаления",
|
||||||
|
description: "Не удалось удалить пациента.",
|
||||||
|
placement: "topRight",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,37 +96,37 @@ const PatientsPage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleModalPatientSubmit = async (newPatient) => {
|
const handleModalPatientSubmit = async (newPatient) => {
|
||||||
|
try {
|
||||||
if (selectedPatient) {
|
if (selectedPatient) {
|
||||||
|
|
||||||
try {
|
|
||||||
await updatePatient(user.token, selectedPatient.id, newPatient);
|
await updatePatient(user.token, selectedPatient.id, newPatient);
|
||||||
} catch (error) {
|
notification.success({
|
||||||
if (error.response?.status === 401) {
|
message: "Пациент обновлён",
|
||||||
throw new Error("Ошибка авторизации: пользователь неяден или токен недействителен");
|
description: `Данные пациента ${newPatient.first_name} ${newPatient.last_name} успешно обновлены.`,
|
||||||
}
|
placement: "topRight",
|
||||||
throw new Error(error.message);
|
});
|
||||||
}
|
} else {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!selectedPatient) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
await addPatient(user.token, newPatient);
|
await addPatient(user.token, newPatient);
|
||||||
} catch (error) {
|
notification.success({
|
||||||
if (error.response?.status === 401) {
|
message: "Пациент добавлен",
|
||||||
throw new Error("Ошибка авторизации: пользователь неяден или токен недействителен");
|
description: `Пациент ${newPatient.first_name} ${newPatient.last_name} успешно добавлен.`,
|
||||||
|
placement: "topRight",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
throw new Error(error.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsModalVisible(false);
|
setIsModalVisible(false);
|
||||||
await fetchPatients();
|
await fetchPatients();
|
||||||
|
} catch (error) {
|
||||||
|
notification.error({
|
||||||
|
message: "Ошибка",
|
||||||
|
description: error.response?.status === 401
|
||||||
|
? "Ошибка авторизации: пользователь не найден или токен недействителен"
|
||||||
|
: "Не удалось сохранить данные пациента.",
|
||||||
|
placement: "topRight",
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (<div style={{padding: 20}}>
|
return (
|
||||||
|
<div style={{padding: 20}}>
|
||||||
<Row gutter={[16, 16]} style={{marginBottom: 20}}>
|
<Row gutter={[16, 16]} style={{marginBottom: 20}}>
|
||||||
<Col xs={24} sm={16}>
|
<Col xs={24} sm={16}>
|
||||||
<Input
|
<Input
|
||||||
@ -157,7 +171,6 @@ const PatientsPage = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
<FloatButton
|
<FloatButton
|
||||||
icon={<PlusOutlined/>}
|
icon={<PlusOutlined/>}
|
||||||
style={{position: "fixed", bottom: 20, right: 20}}
|
style={{position: "fixed", bottom: 20, right: 20}}
|
||||||
@ -170,7 +183,8 @@ const PatientsPage = () => {
|
|||||||
onSubmit={handleModalPatientSubmit}
|
onSubmit={handleModalPatientSubmit}
|
||||||
patient={selectedPatient}
|
patient={selectedPatient}
|
||||||
/>
|
/>
|
||||||
</div>);
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PatientsPage;
|
export default PatientsPage;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user