diff --git a/frontend/src/components/apotheke/ApothekeBtmList.js b/frontend/src/components/apotheke/ApothekeBtmList.js index 94a56db2f9de91b7f6cb2ab6d1ffd70a5e1f120d..2ee6f0cb129610a4ad1bc9f14a6829d3eb55e7a8 100644 --- a/frontend/src/components/apotheke/ApothekeBtmList.js +++ b/frontend/src/components/apotheke/ApothekeBtmList.js @@ -8,9 +8,8 @@ function ApothekeBtmList(props) { const [btms, setBtms] = useState([]); const [input, setInput] = useState(""); - const getBtms = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung`, + const getBtms = () => { + fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung`, { method: "GET", headers: { @@ -18,26 +17,26 @@ function ApothekeBtmList(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).catch((err) => { + ).then(response => { + if (response.status === 200) { + setBtms(response.json()); + } else if (response.status === 403) { + props.history.push("/forbidden"); + } else if (response.status === 400) { + props.history.push("/badrequest"); + } + }).catch((err) => { //SHOW ERROR return; }); - if (response.status === 200) { - setBtms(await response.json()); - } else if (response.status === 403) { - props.history.push("/forbidden"); - } else if (response.status === 400) { - props.history.push("/badrequest"); - } + }; //wird aufgerufen von NeuesBtmModal wenn ein neues BTM hinzugefügt wurde props.apothekeRefFunctions.updateBtmList = getBtms; - useEffect(() => { - getBtms(); - }, []); + useEffect(getBtms, [apoId, props.history]); return ( <div className="btm-buchung-wrapper"> @@ -54,8 +53,8 @@ function ApothekeBtmList(props) { .filter((val) => { if (input === "") { return val; - } else if (val.btm.name.toLowerCase().includes(input.toLowerCase())){ - return val; + } else if (val.btm.name.toLowerCase().includes(input.toLowerCase())) { + return val; } return null; }) diff --git a/frontend/src/components/apotheke/ApothekenDetails.js b/frontend/src/components/apotheke/ApothekenDetails.js index a055b77324289b61b4e7105b8fd9d2c90ea5f79b..e8ca3d4fce99764b6faf09cd671f96b536a1f1b4 100644 --- a/frontend/src/components/apotheke/ApothekenDetails.js +++ b/frontend/src/components/apotheke/ApothekenDetails.js @@ -1,16 +1,17 @@ import React, { useEffect, useState } from "react"; -import { Link } from 'react-router-dom'; +import { Link, useParams } from 'react-router-dom'; import { Button } from "react-bootstrap"; import NeuesBtmModal from "../btmbuch/NeuesBtmModal"; import "../../App.scss"; function ApothekenDetails(props) { + const { apoId } = useParams(); const [apotheke, setApotheke] = useState({ anschrift: {} }); const [neuesBtmModalShow, setneuesBtmModalShow] = useState(false); - const getApothekeData = async () => { - const response = await fetch( - `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${props.match.params.apoId}`, + const getApothekeData = () => { + fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}`, { method: "GET", headers: { @@ -18,23 +19,23 @@ function ApothekenDetails(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).catch((err) => { + ).then(response => { + if (response.status === 200) { + setApotheke(response.json()); + } else if (response.status === 403) { + props.history.push("/forbidden"); + } else if (response.status === 400) { + props.history.push("/badrequest"); + } + }).catch((err) => { //SHOW ERROR return; }); - if (response.status === 200) { - setApotheke(await response.json()); - } else if (response.status === 403) { - props.history.push("/forbidden"); - } else if (response.status === 400) { - props.history.push("/badrequest"); - } + }; - useEffect(() => { - getApothekeData(); - }, []); + useEffect(getApothekeData, [apoId, props.history]); return ( <div className="apo-details"> diff --git a/frontend/src/components/apotheke/einstellungen/ApothekeEinstellungen.js b/frontend/src/components/apotheke/einstellungen/ApothekeEinstellungen.js index 22526fc8e30f719f84ba9fe9a96f99e4fdd97f64..fcbbd4471e3c5263cd57b9331bf9a6368e23cb25 100644 --- a/frontend/src/components/apotheke/einstellungen/ApothekeEinstellungen.js +++ b/frontend/src/components/apotheke/einstellungen/ApothekeEinstellungen.js @@ -87,10 +87,8 @@ function ApothekeEinstellungen(props) { } } - useEffect(() => { - getUserData(); - getCurrentApotheke(); - }, []); + useEffect(getUserData, [apoId, props.history]) + useEffect(getCurrentApotheke, [apoId, props.history]) return ( <Fragment> diff --git a/frontend/src/components/apotheke/einstellungen/tabellen/ArztTabelle.js b/frontend/src/components/apotheke/einstellungen/tabellen/ArztTabelle.js index b7a2ec829354e5b9c39359ffdeef078c50d2e1d0..497c66c6cf0c94e06781c1f348315c3909eb2ab3 100644 --- a/frontend/src/components/apotheke/einstellungen/tabellen/ArztTabelle.js +++ b/frontend/src/components/apotheke/einstellungen/tabellen/ArztTabelle.js @@ -67,9 +67,7 @@ function ArztTabelle(props) { setShowDeleteModal(true); } - useEffect(() => { - getArztData(); - }, []) + useEffect(getArztData, [apoId, props.history]) return ( <Fragment> diff --git a/frontend/src/components/apotheke/einstellungen/tabellen/BtmTabelle.js b/frontend/src/components/apotheke/einstellungen/tabellen/BtmTabelle.js index 2075efdb1da88da7141020ab5047a41918a1a789..61cecf014ad52670ddbd73e5cd325b80a24d6b3c 100644 --- a/frontend/src/components/apotheke/einstellungen/tabellen/BtmTabelle.js +++ b/frontend/src/components/apotheke/einstellungen/tabellen/BtmTabelle.js @@ -67,9 +67,7 @@ function BtmTabelle(props) { setShowDeleteModal(true); } - useEffect(() => { - getBtmData() - }, []) + useEffect(getBtmData, [apoId, props.history]) return ( <Fragment> diff --git a/frontend/src/components/apotheke/einstellungen/tabellen/EmpfaengerTabelle.js b/frontend/src/components/apotheke/einstellungen/tabellen/EmpfaengerTabelle.js index 4796b89b15c287ccbdf89181cb59803a7e40aec5..2df2bb939fa6e881a02c6b770effcc1bee32cda4 100644 --- a/frontend/src/components/apotheke/einstellungen/tabellen/EmpfaengerTabelle.js +++ b/frontend/src/components/apotheke/einstellungen/tabellen/EmpfaengerTabelle.js @@ -67,9 +67,7 @@ function EmpfaengerTabelle(props) { setShowDeleteModal(true); } - useEffect(() => { - getEmpfaengerData() - }, []) + useEffect(getEmpfaengerData, [apoId, props.history]) return ( <Fragment> diff --git a/frontend/src/components/apotheke/einstellungen/tabellen/LieferantTabelle.js b/frontend/src/components/apotheke/einstellungen/tabellen/LieferantTabelle.js index 549bfbe4e0b6f97ae154eabd129ff9e37555d641..21b7ceecb84fdd9a4ed74cb4880e7a95589b3168 100644 --- a/frontend/src/components/apotheke/einstellungen/tabellen/LieferantTabelle.js +++ b/frontend/src/components/apotheke/einstellungen/tabellen/LieferantTabelle.js @@ -67,9 +67,7 @@ function LieferantTabelle(props) { setShowDeleteModal(true); } - useEffect(() => { - getLieferantData() - }, []) + useEffect(getLieferantData, [apoId, props.history]) return ( <Fragment> diff --git a/frontend/src/components/apotheke/einstellungen/tabellen/PersonalTabelle.js b/frontend/src/components/apotheke/einstellungen/tabellen/PersonalTabelle.js index 5cccc9ca250797186000cb54ba04b08d938c1e29..8a5df16b6869a37c4d41a1c90abec3dbd687f368 100644 --- a/frontend/src/components/apotheke/einstellungen/tabellen/PersonalTabelle.js +++ b/frontend/src/components/apotheke/einstellungen/tabellen/PersonalTabelle.js @@ -68,9 +68,7 @@ function PersonalTabelle(props) { setShowPersonalEditModal(true); } - useEffect(() => { - getPersonalData() - }, []) + useEffect(getPersonalData, [apoId, props.history]) return ( <Fragment> diff --git a/frontend/src/components/btmbuch/BTMBuch.js b/frontend/src/components/btmbuch/BTMBuch.js index a658866810bd6af70bba4cc6edd9c792ef0019b5..e4476c5e909717109759f5ce432fdf5ef580e93f 100644 --- a/frontend/src/components/btmbuch/BTMBuch.js +++ b/frontend/src/components/btmbuch/BTMBuch.js @@ -1,62 +1,62 @@ -import React, { useState, useEffect } from 'react'; -import { useParams } from 'react-router-dom'; -import Header from '../headers/Header' -import StatusHeader from '../headers/StatusHeader' -import ApothekenDetails from '../apotheke/ApothekenDetails'; -import UserDetails from '../../user/UserDetails'; -import ApothekeBtmList from '../apotheke/ApothekeBtmList'; -import {Row, Col} from 'react-bootstrap'; -import './BTMBuch.scss' - -function BTMBuch (props) { - const { apoId } = useParams(); - - const [user, setUser] = useState({}); - const [isLoggedIn, setLoggedIn] = useState(false); - const [aktiveRolle, setAktiveRolle] = useState(''); - - const getUserDetails = async event => { - const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/benutzer/me`, { - method: 'GET', - headers: { - 'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), - } - }).catch((err) => { - //SHOW ERROR - return; - }); - - if(response.status === 200) { - let u = await response.json(); - console.log(JSON.stringify(u)) - setUser(u); - setAktiveRolle(u.rolle); - setLoggedIn(true); - }else if(response.status === 403) { - props.history.push('/forbidden'); - }else if(response.status === 400){ - props.history.push('/badrequest'); - } - } - - useEffect(() => { - getUserDetails(); - }, []) - - //this obj is passed to each child, each child can add functions to this object and call functions from this object - let apothekeRefFunctions = {} - - return( - <React.Fragment> - {aktiveRolle.toLowerCase() !== 'benutzer' ?<StatusHeader aktiveRolle={aktiveRolle}/> : null} - <Header /> - <Row className="details-list"> - <Col><ApothekenDetails {...props} apothekeRefFunctions={apothekeRefFunctions} apothekeId={apoId}/></Col> - <Col>{isLoggedIn ? <UserDetails {...props} user={user} setUser={setUser} aktiveRolle={aktiveRolle} setAktiveRolle={setAktiveRolle}/> : null }</Col> - </Row> - <ApothekeBtmList apothekeId={apoId} user={user} apothekeRefFunctions={apothekeRefFunctions} {...props} aktiveRolle={aktiveRolle}/> - </React.Fragment> - ) -} - -export default BTMBuch; +import React, { useState, useEffect } from 'react'; +import { useParams } from 'react-router-dom'; +import Header from '../headers/Header' +import StatusHeader from '../headers/StatusHeader' +import ApothekenDetails from '../apotheke/ApothekenDetails'; +import UserDetails from '../../user/UserDetails'; +import ApothekeBtmList from '../apotheke/ApothekeBtmList'; +import {Row, Col} from 'react-bootstrap'; +import './BTMBuch.scss' + +function BTMBuch (props) { + const { apoId } = useParams(); + + const [user, setUser] = useState({}); + const [isLoggedIn, setLoggedIn] = useState(false); + const [aktiveRolle, setAktiveRolle] = useState(''); + + const getUserDetails = event => { + fetch(`http://${process.env.REACT_APP_BACKEND_URL}/benutzer/me`, { + method: 'GET', + headers: { + 'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), + } + }).then(response => { + if(response.status === 200) { + let u = response.json(); + console.log(JSON.stringify(u)) + setUser(u); + setAktiveRolle(u.rolle); + setLoggedIn(true); + }else if(response.status === 403) { + props.history.push('/forbidden'); + }else if(response.status === 400){ + props.history.push('/badrequest'); + } + }).catch((err) => { + //SHOW ERROR + return; + }); + + + } + + useEffect(getUserDetails, [apoId, props.history]) + + //this obj is passed to each child, each child can add functions to this object and call functions from this object + let apothekeRefFunctions = {} + + return( + <React.Fragment> + {aktiveRolle.toLowerCase() !== 'benutzer' ?<StatusHeader aktiveRolle={aktiveRolle}/> : null} + <Header /> + <Row className="details-list"> + <Col><ApothekenDetails {...props} apothekeRefFunctions={apothekeRefFunctions} apothekeId={apoId}/></Col> + <Col>{isLoggedIn ? <UserDetails {...props} user={user} setUser={setUser} aktiveRolle={aktiveRolle} setAktiveRolle={setAktiveRolle}/> : null }</Col> + </Row> + <ApothekeBtmList apothekeId={apoId} user={user} apothekeRefFunctions={apothekeRefFunctions} {...props} aktiveRolle={aktiveRolle}/> + </React.Fragment> + ) +} + +export default BTMBuch; diff --git a/frontend/src/components/btmbuch/BuchungTabelle.js b/frontend/src/components/btmbuch/BuchungTabelle.js index e6906a2e99094352a9058497062431fcc049eb82..6c38f7e9e97305604a459ac83e637a22706fd814 100644 --- a/frontend/src/components/btmbuch/BuchungTabelle.js +++ b/frontend/src/components/btmbuch/BuchungTabelle.js @@ -40,9 +40,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: { @@ -51,23 +50,24 @@ function BuchungTabelle(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).catch((err) => { + ).then(response => { + if (response.status === 200) { + setLieferanten(response.json()); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }).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: { @@ -76,23 +76,24 @@ function BuchungTabelle(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).catch((err) => { + ).then(response => { + if (response.status === 200) { + setAerzte(response.json()); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }).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: { @@ -101,18 +102,20 @@ function BuchungTabelle(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).catch((err) => { + ).then(response => { + if (response.status === 200) { + setEmpfaenger(response.json()); + } else if (response.status === 403) { + // props.history.push('/forbidden'); + } else if (response.status === 400) { + // props.history.push('/badrequest'); + } + }).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 () => { @@ -196,11 +199,9 @@ function BuchungTabelle(props) { } }; - useEffect(() => { - loadLieferanten(); - loadAerzte(); - loadEmpfaenger(); - }, []); + useEffect(loadLieferanten, [apoId, props.history]) + useEffect(loadAerzte, [apoId, props.history]) + useEffect(loadEmpfaenger, [apoId, props.history]) return ( <React.Fragment> @@ -293,7 +294,7 @@ function BuchungTabelle(props) { <td>{buchung.typ === "ZUGANG" ? "" : buchung.menge}</td> <td>{buchung.typ === "ZUGANG" ? buchung.anforderungsschein : buchung.rezept}</td> <td>{buchung.pruefdatum ? <Moment format="DD.MM.YYYY">{buchung.pruefdatum}</Moment> : ""}</td> - <td>{buchung.pruefer ? buchung.pruefer.vorname+" "+buchung.pruefer.name : ""}</td> + <td>{buchung.pruefer ? buchung.pruefer.vorname + " " + buchung.pruefer.name : ""}</td> {props.aktiveRolle.toLowerCase() === "admin" || props.aktiveRolle.toLowerCase() === "pruefer" ? <th>{renderPruefButton(buchung)}</th> : null} diff --git a/frontend/src/components/btmbuch/NeueBuchungModal.js b/frontend/src/components/btmbuch/NeueBuchungModal.js index bf59c911c6f1990e8bca75c7def462dbdd3259ca..3087d462f077678db2ab1a79c6431fe0ee376495 100644 --- a/frontend/src/components/btmbuch/NeueBuchungModal.js +++ b/frontend/src/components/btmbuch/NeueBuchungModal.js @@ -76,7 +76,7 @@ function NeueBuchungModal(props) { useEffect(() => { setMaxMenge(props.btm.btm.menge) - }, []); + }, [props.btm.btm.menge]); const renderZugang = () => { return ( diff --git a/frontend/src/modals/PersonalAddModal.js b/frontend/src/modals/PersonalAddModal.js index 40c0f15a566547d1a5f08ccd3f8079907c038a41..9cae6476943895684c161adfd26c7a8ed560be2a 100644 --- a/frontend/src/modals/PersonalAddModal.js +++ b/frontend/src/modals/PersonalAddModal.js @@ -129,7 +129,7 @@ function PersonalAddModal(props) { <Form.Row> <Form.Group as={Col} sm={4} controlId="rolle"> <Form.Label>Rolle</Form.Label> - <Form.Control required name="rolle" required as="select" > + <Form.Control required name="rolle" as="select" > {roles.map(r => <option key={r} value={r}>{r}</option>)} </Form.Control> </Form.Group>