diff --git a/frontend/src/components/apotheke/ApothekeBtmList.js b/frontend/src/components/apotheke/ApothekeBtmList.js index 2ee6f0cb129610a4ad1bc9f14a6829d3eb55e7a8..e4629b5a42b4ca613a22c5c2cfcf04b9b7f20cdd 100644 --- a/frontend/src/components/apotheke/ApothekeBtmList.js +++ b/frontend/src/components/apotheke/ApothekeBtmList.js @@ -8,8 +8,9 @@ function ApothekeBtmList(props) { const [btms, setBtms] = useState([]); const [input, setInput] = useState(""); - const getBtms = () => { - fetch(`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung`, + const getBtms = async () => { + const response = await fetch( + `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung`, { method: "GET", headers: { @@ -17,26 +18,26 @@ function ApothekeBtmList(props) { "Bearer " + window.sessionStorage.getItem("edbapo-jwt"), }, } - ).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) => { + ).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, [apoId, props.history]); + useEffect(() => { + getBtms(); + }, []); return ( <div className="btm-buchung-wrapper"> @@ -53,12 +54,11 @@ 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; }) - .map((btm) => ( + .map((btm, key) => ( <BuchungTabelle {...props} btm={btm} /> ))} </div> diff --git a/frontend/src/components/btmbuch/BTMBuch.js b/frontend/src/components/btmbuch/BTMBuch.js index e4476c5e909717109759f5ce432fdf5ef580e93f..dc09a5579a2eb996158c1ba0a450320120fd2406 100644 --- a/frontend/src/components/btmbuch/BTMBuch.js +++ b/frontend/src/components/btmbuch/BTMBuch.js @@ -15,33 +15,33 @@ function BTMBuch (props) { const [isLoggedIn, setLoggedIn] = useState(false); const [aktiveRolle, setAktiveRolle] = useState(''); - const getUserDetails = event => { - fetch(`http://${process.env.REACT_APP_BACKEND_URL}/benutzer/me`, { + 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"), } - }).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; }); - + 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, [apoId, props.history]) + 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 = {}