Fixed prop passing and error handling

This commit is contained in:
Felix Albrigtsen 2022-03-25 13:52:37 +01:00
parent 56d4aa238f
commit 87ba5b263e
1 changed files with 10 additions and 6 deletions

View File

@ -8,18 +8,16 @@ import { useParams } from 'react-router-dom'
import { Button, TextField, MenuItem, InputLabel, Select, Container, Slider } from '@mui/material' import { Button, TextField, MenuItem, InputLabel, Select, Container, Slider } from '@mui/material'
function ManageTournament(props) { function ManageTournament(props) {
const { tournamentId } = useParams()
let [tournamentInfo, setTournamentInfo] = React.useState([]); let [tournamentInfo, setTournamentInfo] = React.useState([]);
React.useEffect(() => { React.useEffect(() => {
fetch(process.env.BACKEND_URL + `/api/tournament/${tournamentId}`) console.log(props.tournamentId);
fetch(process.env.REACT_APP_BACKEND_URL + `/api/tournament/${props.tournamentId}`)
.then(res => res.json()) .then(res => res.json())
.then(data => { .then(data => {
if (data.status !== "OK") { if (data.status !== "OK") {
// Do your error thing showError(data.data);
console.error(data.data);
return;
} }
setTournamentInfo(data.data); setTournamentInfo(data.data);
@ -68,6 +66,11 @@ function AnnounceButton(props) {
); );
} }
function showError(error) {
alert("Something went wrong. \n" + error);
console.error(error);
}
function InviteButton(props) { function InviteButton(props) {
function event() { function event() {
copy(); copy();
@ -86,10 +89,11 @@ function InviteButton(props) {
} }
export default function TournamentManager(props) { export default function TournamentManager(props) {
const { tournamentId } = useParams()
return ( return (
<> <>
<Appbar /> <Appbar />
<ManageTournament /> <ManageTournament tournamentId={tournamentId} />
<AnnounceButton /> <AnnounceButton />
<InviteButton /> <InviteButton />
<SaveButton /> <SaveButton />