Skip to content
Snippets Groups Projects
Commit ad14c23c authored by AdrianBeilharz's avatar AdrianBeilharz
Browse files

fix react errors for btmbuch

parent b362d6a4
No related branches found
No related tags found
No related merge requests found
...@@ -8,8 +8,8 @@ function ApothekeBtmList(props) { ...@@ -8,8 +8,8 @@ function ApothekeBtmList(props) {
const [btms, setBtms] = useState([]); const [btms, setBtms] = useState([]);
const [input, setInput] = useState(""); const [input, setInput] = useState("");
const getBtms = async () => { const getBtms = () => {
const response = await fetch( fetch(
`http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung`, `http://${process.env.REACT_APP_BACKEND_URL}/apotheke/${apoId}/btmbuchung`,
{ {
method: "GET", method: "GET",
...@@ -18,26 +18,26 @@ function ApothekeBtmList(props) { ...@@ -18,26 +18,26 @@ function ApothekeBtmList(props) {
"Bearer " + window.sessionStorage.getItem("edbapo-jwt"), "Bearer " + window.sessionStorage.getItem("edbapo-jwt"),
}, },
} }
).catch((err) => { ).then(response => {
//SHOW ERROR
return;
});
if (response.status === 200) { if (response.status === 200) {
setBtms(await response.json()); return response.json()
} else if (response.status === 403) { } else if (response.status === 403) {
props.history.push("/forbidden"); props.history.push("/forbidden");
} else if (response.status === 400) { } else if (response.status === 400) {
props.history.push("/badrequest"); props.history.push("/badrequest");
} }
}).then(data => setBtms(data)).catch((err) => {
//SHOW ERROR
return;
});
}; };
//wird aufgerufen von NeuesBtmModal wenn ein neues BTM hinzugefügt wurde //wird aufgerufen von NeuesBtmModal wenn ein neues BTM hinzugefügt wurde
props.apothekeRefFunctions.updateBtmList = getBtms; props.apothekeRefFunctions.updateBtmList = getBtms;
useEffect(() => { useEffect(getBtms, [apoId, props.history]);
getBtms();
}, []);
return ( return (
<div className="btm-buchung-wrapper"> <div className="btm-buchung-wrapper">
...@@ -57,9 +57,10 @@ function ApothekeBtmList(props) { ...@@ -57,9 +57,10 @@ function ApothekeBtmList(props) {
} else if (val.btm.name.toLowerCase().includes(input.toLowerCase())){ } else if (val.btm.name.toLowerCase().includes(input.toLowerCase())){
return val; return val;
} }
return null;
}) })
.map((btm, key) => ( .map((btm) => (
<BuchungTabelle {...props} btm={btm} /> <BuchungTabelle {...props} key={btm.id} btm={btm} />
))} ))}
</div> </div>
); );
......
...@@ -15,33 +15,33 @@ function BTMBuch (props) { ...@@ -15,33 +15,33 @@ function BTMBuch (props) {
const [isLoggedIn, setLoggedIn] = useState(false); const [isLoggedIn, setLoggedIn] = useState(false);
const [aktiveRolle, setAktiveRolle] = useState(''); const [aktiveRolle, setAktiveRolle] = useState('');
const getUserDetails = async event => { const getUserDetails = event => {
const response = await fetch(`http://${process.env.REACT_APP_BACKEND_URL}/benutzer/me`, { fetch(`http://${process.env.REACT_APP_BACKEND_URL}/benutzer/me`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"), 'Authorization': 'Bearer ' + window.sessionStorage.getItem("edbapo-jwt"),
} }
}).catch((err) => { }).then(response => {
//SHOW ERROR
return;
});
if (response.status === 200) { if (response.status === 200) {
let u = await response.json(); return response.json();
console.log(JSON.stringify(u))
setUser(u);
setAktiveRolle(u.rolle);
setLoggedIn(true);
} else if (response.status === 403) { } else if (response.status === 403) {
props.history.push('/forbidden'); props.history.push('/forbidden');
} else if (response.status === 400) { } else if (response.status === 400) {
props.history.push('/badrequest'); props.history.push('/badrequest');
} }
}).then(data => {
setUser(data);
setAktiveRolle(data.rolle);
setLoggedIn(true);
}).catch((err) => {
//SHOW ERROR
return;
});
} }
useEffect(() => { useEffect(getUserDetails, [apoId, props.history])
getUserDetails();
}, [])
//this obj is passed to each child, each child can add functions to this object and call functions from this object //this obj is passed to each child, each child can add functions to this object and call functions from this object
let apothekeRefFunctions = {} let apothekeRefFunctions = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment