доелал выдачу линзы пациенту
This commit is contained in:
parent
9f432a4314
commit
9190723abd
20
web-app/src/api/lenses/GetNotIssuedLenses.jsx
Normal file
20
web-app/src/api/lenses/GetNotIssuedLenses.jsx
Normal file
@ -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;
|
||||||
@ -1,9 +1,10 @@
|
|||||||
import {useEffect, useState} from "react";
|
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 PropTypes from "prop-types";
|
||||||
import getAllPatients from "../../api/patients/GetAllPatients.jsx";
|
import getAllPatients from "../../api/patients/GetAllPatients.jsx";
|
||||||
import getAllLenses from "../../api/lenses/GetAllLenses.jsx";
|
|
||||||
import {useAuth} from "../../AuthContext.jsx";
|
import {useAuth} from "../../AuthContext.jsx";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import getNotIssuedLenses from "../../api/lenses/GetNotIssuedLenses.jsx";
|
||||||
|
|
||||||
|
|
||||||
const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
||||||
@ -13,11 +14,13 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
|
|
||||||
const [searchPatientString, setSearchPatientString] = useState("");
|
const [searchPatientString, setSearchPatientString] = useState("");
|
||||||
const [searchLensString, setSearchLensString] = useState("");
|
const [searchLensString, setSearchLensString] = useState("");
|
||||||
const [issueDate, setIssueDate] = useState(null);
|
const [issueDate, setIssueDate] = useState(dayjs(new Date()));
|
||||||
|
|
||||||
const [selectedPatient, setSelectedPatient] = useState(null);
|
const [selectedPatient, setSelectedPatient] = useState(null);
|
||||||
const [selectedLens, setSelectedLens] = useState(null);
|
const [selectedLens, setSelectedLens] = useState(null);
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const [currentStep, setCurrentStep] = useState(0);
|
const [currentStep, setCurrentStep] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -32,7 +35,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
const data = await getAllPatients(user.token);
|
const data = await getAllPatients(user.token);
|
||||||
setPatients(data);
|
setPatients(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
notification.error({
|
notification.error({
|
||||||
message: "Ошибка загрузки пациентов",
|
message: "Ошибка загрузки пациентов",
|
||||||
description: "Проверьте подключение к сети.",
|
description: "Проверьте подключение к сети.",
|
||||||
@ -42,10 +45,10 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
|
|
||||||
const fetchLenses = async () => {
|
const fetchLenses = async () => {
|
||||||
try {
|
try {
|
||||||
const data = await getAllLenses(user.token);
|
const data = await getNotIssuedLenses(user.token);
|
||||||
setLenses(data);
|
setLenses(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
notification.error({
|
notification.error({
|
||||||
message: "Ошибка загрузки линз",
|
message: "Ошибка загрузки линз",
|
||||||
description: "Проверьте подключение к сети.",
|
description: "Проверьте подключение к сети.",
|
||||||
@ -55,11 +58,15 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
|
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
try {
|
try {
|
||||||
// const values = await form.validateFields();
|
setLoading(true);
|
||||||
onSubmit({...values, patient: selectedPatient});
|
setCurrentStep(0);
|
||||||
|
onSubmit(issueDate.format("YYYY-MM-DD"), selectedPatient.id, selectedLens.id);
|
||||||
setSelectedPatient(null);
|
setSelectedPatient(null);
|
||||||
|
setSelectedLens(null);
|
||||||
|
setIssueDate(dayjs(new Date()));
|
||||||
|
setLoading(false);
|
||||||
} catch (errorInfo) {
|
} catch (errorInfo) {
|
||||||
console.log("Validation Failed:", errorInfo);
|
console.error("Validation Failed:", errorInfo);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -198,40 +205,25 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Alert
|
<Alert
|
||||||
type={"warning"}
|
type="warning"
|
||||||
message={
|
message="Внимание! После подтверждения линза будет считаться выданной, данное действие нельзя будет отменить."
|
||||||
"Внимание! После подтверждения линза будет считаться выданной, данное действие нельзя будет отменить."
|
|
||||||
}
|
|
||||||
style={{marginBottom: 15}}
|
style={{marginBottom: 15}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Row
|
<Row style={{padding: "10px", background: "#f5f5f5", borderRadius: 5, marginBottom: 15}}
|
||||||
style={{padding: "10px", background: "#f5f5f5", borderRadius: 5, marginBottom: 15}}
|
gutter={[16, 16]}>
|
||||||
gutter={[16, 16]}
|
<Col xs={24} md={16} style={{display: "flex", alignItems: "center"}}>
|
||||||
>
|
<Typography.Text strong>
|
||||||
<Col
|
Дата выдачи: {issueDate?.toDate().toLocaleDateString("ru-RU")}
|
||||||
xs={24}
|
|
||||||
md={16}
|
|
||||||
style={{display: "flex", alignItems: "center"}}
|
|
||||||
>
|
|
||||||
<Typography.Text
|
|
||||||
strong
|
|
||||||
>
|
|
||||||
Дата выдачи будет установлена автоматически: {issueDate.toLocaleDateString("ru-RU")}
|
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col xs={24} md={8}>
|
||||||
<Col
|
<DatePicker
|
||||||
xs={24}
|
value={issueDate}
|
||||||
md={8}
|
onChange={(date) => setIssueDate(date)}
|
||||||
>
|
format="DD.MM.YYYY"
|
||||||
<Button
|
style={{width: "100%"}}
|
||||||
type="primary"
|
/>
|
||||||
onClick={}
|
|
||||||
block
|
|
||||||
>
|
|
||||||
Установить дату вручную
|
|
||||||
</Button>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
@ -260,7 +252,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
<p><b>Esa:</b> {selectedLens.esa}</p>
|
<p><b>Esa:</b> {selectedLens.esa}</p>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const steps = [
|
const steps = [
|
||||||
@ -302,6 +294,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
setSelectedPatient(null);
|
setSelectedPatient(null);
|
||||||
setSelectedLens(null);
|
setSelectedLens(null);
|
||||||
setCurrentStep(0);
|
setCurrentStep(0);
|
||||||
|
setIssueDate(dayjs(new Date()));
|
||||||
onCancel();
|
onCancel();
|
||||||
}}
|
}}
|
||||||
footer={null}
|
footer={null}
|
||||||
@ -309,10 +302,16 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
width={window.innerWidth > 768 ? 700 : "90%"}
|
width={window.innerWidth > 768 ? 700 : "90%"}
|
||||||
centered
|
centered
|
||||||
>
|
>
|
||||||
|
{loading ? (
|
||||||
|
<div style={{display: "flex", justifyContent: "center", alignItems: "center", height: "70vh"}}>
|
||||||
|
<Spin size="large"/>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div style={{maxHeight: "70vh", overflowY: "auto", padding: "10px"}}>
|
||||||
|
{steps[currentStep].content}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div style={{maxHeight: "60vh", overflowY: "auto", padding: "10px"}}>
|
|
||||||
{steps[currentStep].content}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{window.innerWidth > 768 && (
|
{window.innerWidth > 768 && (
|
||||||
<Steps
|
<Steps
|
||||||
@ -329,21 +328,26 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
|
|||||||
gutter={[8, 8]}
|
gutter={[8, 8]}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
style={{marginRight: 8}}
|
||||||
onClick={() => setCurrentStep(currentStep + 1)}
|
|
||||||
disabled={!isActiveNextButton() && !isActiveFinishButton()}
|
|
||||||
>
|
|
||||||
{isActiveFinishButton() ? "Завершить" : "Далее"}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
style={{marginLeft: 8}}
|
|
||||||
onClick={() => setCurrentStep(currentStep - 1)}
|
onClick={() => setCurrentStep(currentStep - 1)}
|
||||||
disabled={!isActivePrevButton()}
|
disabled={!isActivePrevButton()}
|
||||||
>
|
>
|
||||||
Назад
|
Назад
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={async () => {
|
||||||
|
if (isActiveFinishButton()) {
|
||||||
|
await handleOk();
|
||||||
|
} else {
|
||||||
|
setCurrentStep(currentStep + 1);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={!isActiveNextButton() && !isActiveFinishButton()}
|
||||||
|
>
|
||||||
|
{isActiveFinishButton() ? "Завершить" : "Далее"}
|
||||||
|
</Button>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import {DatabaseOutlined, LoadingOutlined, PlusOutlined} from "@ant-design/icons
|
|||||||
import LensIssueViewModal from "../components/lens_issues/LensIssueViewModal.jsx";
|
import LensIssueViewModal from "../components/lens_issues/LensIssueViewModal.jsx";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import LensIssueFormModal from "../components/lens_issues/LensIssueFormModal.jsx";
|
import LensIssueFormModal from "../components/lens_issues/LensIssueFormModal.jsx";
|
||||||
|
import addLensIssue from "../api/lens_issues/AddLensIssue.jsx";
|
||||||
|
|
||||||
const {Title} = Typography;
|
const {Title} = Typography;
|
||||||
|
|
||||||
@ -61,8 +62,24 @@ const IssuesPage = () => {
|
|||||||
setIsModalVisible(false);
|
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 () => {
|
const fetchLensIssues = async () => {
|
||||||
@ -85,7 +102,6 @@ const IssuesPage = () => {
|
|||||||
setSearchTerm(e.target.value.toLowerCase());
|
setSearchTerm(e.target.value.toLowerCase());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const filteredIssues = lensIssues.filter(issue => {
|
const filteredIssues = lensIssues.filter(issue => {
|
||||||
let dateFilter = true;
|
let dateFilter = true;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user