From 9190723abd9064543a69e5f68c612e9ca7403a3e Mon Sep 17 00:00:00 2001 From: andrei Date: Mon, 10 Mar 2025 07:20:06 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B4=D0=B0=D1=87=D1=83=20=D0=BB=D0=B8=D0=BD=D0=B7=D1=8B?= =?UTF-8?q?=20=D0=BF=D0=B0=D1=86=D0=B8=D0=B5=D0=BD=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web-app/src/api/lenses/GetNotIssuedLenses.jsx | 20 ++++ .../lens_issues/LensIssueFormModal.jsx | 106 +++++++++--------- web-app/src/pages/IssuesPage.jsx | 22 +++- 3 files changed, 94 insertions(+), 54 deletions(-) create mode 100644 web-app/src/api/lenses/GetNotIssuedLenses.jsx diff --git a/web-app/src/api/lenses/GetNotIssuedLenses.jsx b/web-app/src/api/lenses/GetNotIssuedLenses.jsx new file mode 100644 index 0000000..2f67da2 --- /dev/null +++ b/web-app/src/api/lenses/GetNotIssuedLenses.jsx @@ -0,0 +1,20 @@ +import axios from "axios"; +import CONFIG from "../../core/Config.jsx"; + +const getNotIssuedLenses = async (token) => { + try { + const response = await axios.get(`${CONFIG.BASE_URL}/lenses/not_issued/`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + return response.data; + } catch (error) { + if (error.response?.status === 403) { + throw Error("Ошибка авторизации: пользователь неяден или токен недействителен"); + } + throw Error(error.message); + } +}; + +export default getNotIssuedLenses; \ No newline at end of file diff --git a/web-app/src/components/lens_issues/LensIssueFormModal.jsx b/web-app/src/components/lens_issues/LensIssueFormModal.jsx index 45aa3f8..09a39ad 100644 --- a/web-app/src/components/lens_issues/LensIssueFormModal.jsx +++ b/web-app/src/components/lens_issues/LensIssueFormModal.jsx @@ -1,9 +1,10 @@ import {useEffect, useState} from "react"; -import {Modal, Input, Button, notification, Typography, Collapse, Steps, Row, Alert, Col} from "antd"; +import {Modal, Input, Button, notification, Typography, Collapse, Steps, Row, Alert, Col, DatePicker, Spin} from "antd"; import PropTypes from "prop-types"; import getAllPatients from "../../api/patients/GetAllPatients.jsx"; -import getAllLenses from "../../api/lenses/GetAllLenses.jsx"; import {useAuth} from "../../AuthContext.jsx"; +import dayjs from "dayjs"; +import getNotIssuedLenses from "../../api/lenses/GetNotIssuedLenses.jsx"; const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { @@ -13,11 +14,13 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { const [searchPatientString, setSearchPatientString] = useState(""); const [searchLensString, setSearchLensString] = useState(""); - const [issueDate, setIssueDate] = useState(null); + const [issueDate, setIssueDate] = useState(dayjs(new Date())); const [selectedPatient, setSelectedPatient] = useState(null); const [selectedLens, setSelectedLens] = useState(null); + const [loading, setLoading] = useState(false); + const [currentStep, setCurrentStep] = useState(0); useEffect(() => { @@ -32,7 +35,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { const data = await getAllPatients(user.token); setPatients(data); } catch (error) { - console.log(error); + console.error(error); notification.error({ message: "Ошибка загрузки пациентов", description: "Проверьте подключение к сети.", @@ -42,10 +45,10 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { const fetchLenses = async () => { try { - const data = await getAllLenses(user.token); + const data = await getNotIssuedLenses(user.token); setLenses(data); } catch (error) { - console.log(error); + console.error(error); notification.error({ message: "Ошибка загрузки линз", description: "Проверьте подключение к сети.", @@ -55,11 +58,15 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { const handleOk = async () => { try { - // const values = await form.validateFields(); - onSubmit({...values, patient: selectedPatient}); + setLoading(true); + setCurrentStep(0); + onSubmit(issueDate.format("YYYY-MM-DD"), selectedPatient.id, selectedLens.id); setSelectedPatient(null); + setSelectedLens(null); + setIssueDate(dayjs(new Date())); + setLoading(false); } catch (errorInfo) { - console.log("Validation Failed:", errorInfo); + console.error("Validation Failed:", errorInfo); } }; @@ -198,40 +205,25 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { return ( <> - - - - Дата выдачи будет установлена автоматически: {issueDate.toLocaleDateString("ru-RU")} + + + + Дата выдачи: {issueDate?.toDate().toLocaleDateString("ru-RU")} - - - + + setIssueDate(date)} + format="DD.MM.YYYY" + style={{width: "100%"}} + /> @@ -260,7 +252,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {

Esa: {selectedLens.esa}

- ) + ); }; const steps = [ @@ -302,6 +294,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { setSelectedPatient(null); setSelectedLens(null); setCurrentStep(0); + setIssueDate(dayjs(new Date())); onCancel(); }} footer={null} @@ -309,10 +302,16 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { width={window.innerWidth > 768 ? 700 : "90%"} centered > + {loading ? ( +
+ +
+ ) : ( +
+ {steps[currentStep].content} +
+ )} -
- {steps[currentStep].content} -
{window.innerWidth > 768 && ( { gutter={[8, 8]} > - +
- ); }; diff --git a/web-app/src/pages/IssuesPage.jsx b/web-app/src/pages/IssuesPage.jsx index a05b78f..bb70ab0 100644 --- a/web-app/src/pages/IssuesPage.jsx +++ b/web-app/src/pages/IssuesPage.jsx @@ -6,6 +6,7 @@ import {DatabaseOutlined, LoadingOutlined, PlusOutlined} from "@ant-design/icons import LensIssueViewModal from "../components/lens_issues/LensIssueViewModal.jsx"; import dayjs from "dayjs"; import LensIssueFormModal from "../components/lens_issues/LensIssueFormModal.jsx"; +import addLensIssue from "../api/lens_issues/AddLensIssue.jsx"; const {Title} = Typography; @@ -61,8 +62,24 @@ const IssuesPage = () => { setIsModalVisible(false); }; - const handleSubmitFormModal = () => { - + const handleSubmitFormModal = async (issue_date, patient_id, lens_id) => { + try { + await addLensIssue(user.token, {issue_date, patient_id, lens_id}); + setIsModalVisible(false); + notification.success({ + message: "Линза выдана", + description: "Линза успешно выдана пациенту.", + placement: "topRight", + }); + await fetchLensIssues(); + } catch (error) { + console.log(error); + notification.error({ + message: "Ошибка добавления", + description: "Не удалось выдать линзу пациенту.", + placement: "topRight", + }); + } }; const fetchLensIssues = async () => { @@ -85,7 +102,6 @@ const IssuesPage = () => { setSearchTerm(e.target.value.toLowerCase()); }; - const filteredIssues = lensIssues.filter(issue => { let dateFilter = true;