diff --git a/frontend/src/components/apotheke/ApothekenDetails.js b/frontend/src/components/apotheke/ApothekenDetails.js index e8ca3d4fce99764b6faf09cd671f96b536a1f1b4..9431b2eca17ec88aff3604774a5e64942664ea84 100644 --- a/frontend/src/components/apotheke/ApothekenDetails.js +++ b/frontend/src/components/apotheke/ApothekenDetails.js @@ -1,7 +1,7 @@ import React, { useEffect, useState } from "react"; import { Link, useParams } from 'react-router-dom'; import { Button } from "react-bootstrap"; -import NeuesBtmModal from "../btmbuch/NeuesBtmModal"; +import BtmAddModal from '../../modals/BtmAddModal'; import "../../App.scss"; function ApothekenDetails(props) { @@ -50,7 +50,7 @@ function ApothekenDetails(props) { > Neues Betäubungsmittel anlegen </Button> - <NeuesBtmModal + <BtmAddModal show={neuesBtmModalShow} {...props} onHide={() => setneuesBtmModalShow(false)} diff --git a/frontend/src/components/btmbuch/BuchungTabelle.js b/frontend/src/components/btmbuch/BuchungTabelle.js index 89c2e5acaadc52c4ddfbc4a0b95600503b9b9b3f..f8a3ccc22062e5ae31855faedc6d9dccf2fe25e0 100644 --- a/frontend/src/components/btmbuch/BuchungTabelle.js +++ b/frontend/src/components/btmbuch/BuchungTabelle.js @@ -10,26 +10,14 @@ import TableBody from '@material-ui/core/TableBody'; import NeueBuchungModal from "./NeueBuchungModal"; import UpdateBuchungModal from "../../modals/UpdateBuchungModal"; import DeleteModal from "../../modals/DeleteModal"; -import { makeStyles } from '@material-ui/core/styles'; import TablePagination from '@material-ui/core/TablePagination'; import jsPDF from 'jspdf' import 'jspdf-autotable' - -const useStyles = makeStyles({ - root: { - width: '100%', - }, - container: { - maxHeight: 440, - }, -}); - function BuchungTabelle(props) { let { btm } = props; const { apoId } = useParams(); - const classes = useStyles(); const [page, setPage] = React.useState(0); const [rowsPerPage, setRowsPerPage] = React.useState(10); @@ -54,9 +42,8 @@ function BuchungTabelle(props) { setPage(0); }; - const loadLieferanten = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/lieferant`, + const loadLieferanten = () => { + fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/lieferant`, { method: "GET", headers: { @@ -65,23 +52,24 @@ function BuchungTabelle(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).catch((err) => { + ).then(response => { + if (response.status === 200) { + return response.json(); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }).then(data => setLieferanten(data)).catch((err) => { //SHOW ERROR console.log(err); }); - if (response.status === 200) { - setLieferanten(await response.json()); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); - } + }; - const loadAerzte = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/arzt`, + const loadAerzte = () => { + fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/arzt`, { method: "GET", headers: { @@ -90,23 +78,24 @@ function BuchungTabelle(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).catch((err) => { + ).then(response => { + if (response.status === 200) { + return response.json(); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }).then(data => setAerzte(data)).catch((err) => { //SHOW ERROR console.log(err); }); - if (response.status === 200) { - setAerzte(await response.json()); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); - } + }; - const loadEmpfaenger = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/empfaenger`, + const loadEmpfaenger = () => { + fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/empfaenger`, { method: "GET", headers: { @@ -115,18 +104,20 @@ function BuchungTabelle(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).catch((err) => { + ).then(response => { + if (response.status === 200) { + return response.json(); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }).then(data => setEmpfaenger(data)).catch((err) => { //SHOW ERROR console.log(err); }); - if (response.status === 200) { - setEmpfaenger(await response.json()); - } else if (response.status === 403) { - // props.history.push('/forbidden'); - } else if (response.status === 400) { - // props.history.push('/badrequest'); - } + }; const deleteBtm = async () => { @@ -250,11 +241,9 @@ function BuchungTabelle(props) { } - useEffect(() => { - loadLieferanten(); - loadAerzte(); - loadEmpfaenger(); - }, []); + useEffect(loadLieferanten, [apoId]); + useEffect(loadAerzte, [apoId]); + useEffect(loadEmpfaenger, [apoId]); return ( <React.Fragment> diff --git a/frontend/src/components/btmbuch/NeueBuchungModal.js b/frontend/src/components/btmbuch/NeueBuchungModal.js index 3087d462f077678db2ab1a79c6431fe0ee376495..f0001ba242f5abe5c39e5f43bb69d6a0ea989d32 100644 --- a/frontend/src/components/btmbuch/NeueBuchungModal.js +++ b/frontend/src/components/btmbuch/NeueBuchungModal.js @@ -26,7 +26,7 @@ function NeueBuchungModal(props) { if (response && response.status === 201) { - const data = await response.json(); + //const data = await response.json(); // console.log(data); hideModal(); enqueueSnackbar('Buchung erfolgreich angelegt', { variant:'success', autoHideDuration: 3000} ); @@ -167,7 +167,7 @@ function NeueBuchungModal(props) { label="Abgang" name="TypRadio" id="AbgangRadio" - onClick={() => setTyp('abgang')} + onClick={() => {setTyp('abgang'); setMaxMenge(props.btm.btm.menge)}} /> </Row> </Col> @@ -178,7 +178,7 @@ function NeueBuchungModal(props) { Menge </Form.Label> <Col sm="10"> - <Form.Control name="btmMenge" type="number" min="1" defaultValue="0" /> + <Form.Control name="btmMenge" type="number" min="1" max={maxMenge} defaultValue="0" /> </Col> </Form.Group> <Form.Group as={Row} controlId="datum"> diff --git a/frontend/src/components/btmbuch/NeuesBtmModal.js b/frontend/src/components/btmbuch/NeuesBtmModal.js deleted file mode 100644 index 0f13a52ad4ddc9fcecc38cb1a59feeaf69d656e1..0000000000000000000000000000000000000000 --- a/frontend/src/components/btmbuch/NeuesBtmModal.js +++ /dev/null @@ -1,152 +0,0 @@ -import React, { useState } from "react"; -import { Modal, Button, Form, Row, Col, Alert } from "react-bootstrap"; -import { useSnackbar } from "notistack"; - -export default function NeuesBtmModal(props) { - const { enqueueSnackbar } = useSnackbar(); - const [activeDarreichungsform, setActiveDarreichungsform] = useState("Tbl"); - const [showError, setShowError] = useState(false); - const [errorMessage, setErrorMessage] = useState(""); - - const hideModal = () => { - setShowError(false); - props.onHide(); - }; - - const createNewBtm = async (event) => { - event.preventDefault(); - let { btmName, btmMenge, btmDarreichungsform, btmEinheit } = event.target; - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.apothekeId}/btm`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: - "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), - }, - body: JSON.stringify({ - name: btmName.value, - menge: btmMenge.value, - darreichungsform: btmDarreichungsform.value, - einheit: btmEinheit.value, - }), - } - ).catch((err) => { - //SHOW ERROR - console.log(err); - }); - - if (response && response.status === 201) { - const data = await response.json(); - console.log(data); - hideModal(); - enqueueSnackbar("Betäubungsmittel erfolgreich angelegt", { - variant: "success", - autoHideDuration: 3000, - }); - props.apothekeRefFunctions.updateBtmList(); - } else if (response && response.status === 400) { - setErrorMessage("OHJE"); - setShowError(true); - } - }; - - let darreichungsformen = { - Tbl: { einheiten: ["Stueck"] }, - Trp: { einheiten: ["ml"] }, - Sup: { einheiten: ["Stueck"] }, - RTA: { einheiten: ["Stueck"] }, - RKA: { einheiten: ["Stueck"] }, - Ampullen: { einheiten: ["Stueck"] }, - Rezeptursubstanz: { einheiten: ["g"] }, - HKP: { einheiten: ["Stueck"] }, - Pfl: { einheiten: ["Stueck"] }, - }; - var units = darreichungsformen[activeDarreichungsform].einheiten; - - return ( - <Modal - {...props} - size="lg" - aria-labelledby="contained-modal-title-vcenter" - centered - onExiting={hideModal} - backdrop="static" - > - <Modal.Header closeButton> - <Modal.Title id="contained-modal-title-vcenter"> - Betäubungsmittel hinzufügen - </Modal.Title> - </Modal.Header> - <Form onSubmit={createNewBtm}> - {showError ? <Alert variant="danger">{errorMessage}</Alert> : null} - <Modal.Body> - <Form.Group as={Row} controlId="btmName"> - <Form.Label column sm="2"> - Name - </Form.Label> - <Col sm="10"> - <Form.Control name="btmName" required type="text" /> - </Col> - </Form.Group> - <Form.Group as={Row} controlId="btmMenge"> - <Form.Label column sm="2"> - Menge - </Form.Label> - <Col sm="10"> - <Form.Control - name="btmMenge" - type="number" - min="0" - defaultValue="0" - /> - </Col> - </Form.Group> - <Form.Group as={Row} controlId="btmDarreichungsform"> - <Form.Label column sm="2"> - Darreichungsform - </Form.Label> - <Col sm="10"> - <Form.Control - onChange={(event) => - setActiveDarreichungsform(event.target.value) - } - name="btmDarreichungsform" - required - as="select" - > - {Object.keys(darreichungsformen).map((df) => ( - <option value={df}>{df}</option> - ))} - </Form.Control> - </Col> - </Form.Group> - - <Form.Group as={Row} controlId="btmEinheit"> - <Form.Label column sm="2"> - Einheit - </Form.Label> - <Col sm="10"> - <Form.Control name="btmEinheit" required as="select"> - {activeDarreichungsform !== "" - ? Object.keys(units).map((e) => ( - <option value={units[e]}>{units[e]}</option> - )) - : null} - </Form.Control> - </Col> - </Form.Group> - </Modal.Body> - <Modal.Footer> - <Button variant="danger" onClick={props.onHide}> - Close - </Button> - <Button variant="primary" type="submit"> - Bestätigen - </Button> - </Modal.Footer> - </Form> - </Modal> - ); -} diff --git a/frontend/src/modals/ApothekeRegisterModal.js b/frontend/src/modals/ApothekeRegisterModal.js index 25a205c88e1769ff775434430485ce867d8489a4..d43d7413b4aa37ce37cf47b8e6bf8742c1185929 100644 --- a/frontend/src/modals/ApothekeRegisterModal.js +++ b/frontend/src/modals/ApothekeRegisterModal.js @@ -132,10 +132,6 @@ function ApothekeRegisterModal(props) { } }; - const cancel = () => { - setShowContinueModal(false); - }; - const renderSchritt1 = () => { return ( <React.Fragment> diff --git a/frontend/src/modals/BtmEditModal.js b/frontend/src/modals/BtmEditModal.js index 8454fc156546fcd288c420b2449e06a09fa0ffd5..548ca404dc0414d287d0fea251e10d3f92bf2783 100644 --- a/frontend/src/modals/BtmEditModal.js +++ b/frontend/src/modals/BtmEditModal.js @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { useParams } from 'react-router-dom'; -import { Modal, Col, Button, Form, Alert, Row } from 'react-bootstrap'; +import { Modal, Col, Button, Form, Row } from 'react-bootstrap'; import { useSnackbar } from 'notistack'; import { responsiveFontSizes } from '@material-ui/core'; @@ -22,13 +22,8 @@ function BtmEditModal(props) { let { id, darreichungsform, einheit, name, menge } = props.btm; // console.log(props.btm) - - const [activeDarreichungsform, setActiveDarreichungsform] = useState(darreichungsform); - const [activeEinheit, setActiveEinheit] = useState(einheit); const [einheiten, setEinheiten] = useState(darreichungsformen[darreichungsform].einheiten); - const [showError, setShowError] = useState(false); - const [errorMessage, setErrorMessage] = useState(''); const { enqueueSnackbar } = useSnackbar(); @@ -63,20 +58,12 @@ function BtmEditModal(props) { console.log(err); return; }); - - } - useEffect(() => { - setActiveDarreichungsform(props.btm.darreichungsform); - setActiveEinheit(props.btm.einheit); - setEinheiten(darreichungsformen[props.btm.darreichungsform].einheiten) - console.log(activeDarreichungsform, activeEinheit, einheiten) - }, [props.btm]) + //eslint-disable-next-line react-hooks/exhaustive-deps + useEffect(() => setEinheiten(darreichungsformen[props.btm.darreichungsform].einheiten), [props.btm]) const hide = () => { - setActiveDarreichungsform(props.btm.darreichungsform); - setActiveEinheit(props.btm.einheit); setEinheiten(darreichungsformen[props.btm.darreichungsform].einheiten) props.onHide(); } @@ -96,7 +83,6 @@ function BtmEditModal(props) { </Modal.Title> </Modal.Header> <Form onSubmit={updateDetails}> - {showError ? <Alert variant="danger">{errorMessage}</Alert> : null} <Modal.Body> <Form.Group as={Row} controlId="name"> <Form.Label column sm="2"> @@ -123,7 +109,6 @@ function BtmEditModal(props) { </Form.Label> <Col sm="10"> <Form.Control defaultValue={darreichungsform} onChange={event => { - setActiveDarreichungsform(event.target.value) setEinheiten(darreichungsformen[event.target.value].einheiten) }} name="darreichungsform" required as="select"> {