убрал ошибки, появляющиеся на странице пациентов в браузере

This commit is contained in:
Андрей Дувакин 2025-02-10 18:43:10 +05:00
parent 6c2a6e4c00
commit f5f9cac37e
2 changed files with 18 additions and 12 deletions

View File

@ -9,15 +9,17 @@ const PatientModal = ({visible, onCancel, onSubmit, patient}) => {
const [form] = Form.useForm(); const [form] = Form.useForm();
useEffect(() => { useEffect(() => {
if (patient) { if (visible) {
form.setFieldsValue({ if (patient) {
...patient, form.setFieldsValue({
birthday: patient.birthday ? moment(patient.birthday) : null, ...patient,
}); birthday: patient.birthday ? moment(patient.birthday) : null,
} else { });
form.resetFields(); } else {
form.resetFields();
}
} }
}, [patient, form]); }, [visible, patient, form]);
const handleOk = async () => { const handleOk = async () => {
try { try {
@ -26,6 +28,7 @@ const PatientModal = ({visible, onCancel, onSubmit, patient}) => {
values.birthday = values.birthday.format("YYYY-MM-DD"); values.birthday = values.birthday.format("YYYY-MM-DD");
} }
onSubmit(values); onSubmit(values);
form.resetFields();
} catch (errorInfo) { } catch (errorInfo) {
console.log("Validation Failed:", errorInfo); console.log("Validation Failed:", errorInfo);
} }
@ -35,13 +38,17 @@ const PatientModal = ({visible, onCancel, onSubmit, patient}) => {
<Modal <Modal
title={patient ? "Редактировать пациента" : "Добавить пациента"} title={patient ? "Редактировать пациента" : "Добавить пациента"}
open={visible} open={visible}
onCancel={onCancel} onCancel={() => {
form.resetFields();
onCancel();
}}
onOk={handleOk} onOk={handleOk}
okText="Сохранить" okText="Сохранить"
cancelText="Отмена" cancelText="Отмена"
centered centered
maskClosable={false} maskClosable={false}
bodyStyle={{padding: 24}} forceRender={true}
styles={{body: {padding: 24}}}
style={{top: 20}} style={{top: 20}}
> >
<Form form={form} layout="vertical"> <Form form={form} layout="vertical">

View File

@ -6,7 +6,6 @@ import getAllPatients from "../api/GetAllPatients.jsx";
import PatientListCard from "../components/PatientListCard.jsx"; import PatientListCard from "../components/PatientListCard.jsx";
import PatientModal from "../components/PatientModal.jsx"; // Подключаем модальное окно import PatientModal from "../components/PatientModal.jsx"; // Подключаем модальное окно
const { Search } = Input;
const { Option } = Select; const { Option } = Select;
const PatientsPage = () => { const PatientsPage = () => {
@ -83,7 +82,7 @@ const PatientsPage = () => {
<div style={{ padding: 20 }}> <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}>
<Search <Input
placeholder="Поиск пациента" placeholder="Поиск пациента"
onChange={(e) => setSearchText(e.target.value)} onChange={(e) => setSearchText(e.target.value)}
style={{ width: "100%" }} style={{ width: "100%" }}