From 25513c31e88f227514e50f2350cc980bf3174a6e Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Tue, 29 Mar 2022 20:07:42 +0200 Subject: [PATCH] Delete teams --- src/client/src/TournamentCreator.js | 12 ++++-------- src/client/src/TournamentTeams.js | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/client/src/TournamentCreator.js b/src/client/src/TournamentCreator.js index 1ee9eae..73325f2 100644 --- a/src/client/src/TournamentCreator.js +++ b/src/client/src/TournamentCreator.js @@ -6,23 +6,19 @@ import { Button, TextField, Stack, InputLabel, Select, Container, Slider, Paper, import FileUploadIcon from '@mui/icons-material/FileUpload'; function postTournament(tournamentName, tournamentDescription, tournamentStartDate, tournamentEndDate, tournamentMaxTeams) { - // event.preventDefault(); - //TODO use refs to get values - - - if (!tournamentName || tournamentName == "") { + if (!tournamentName || tournamentName === "") { alert("Tournament name cannot be empty"); return; } - if (!tournamentDescription || tournamentDescription == "") { + if (!tournamentDescription || tournamentDescription === "") { alert("Tournament description cannot be empty"); return; } - if (!tournamentStartDate || tournamentStartDate == "") { + if (!tournamentStartDate || tournamentStartDate === "") { alert("Tournament start date cannot be empty"); return; } - if (!tournamentEndDate || tournamentEndDate == "") { + if (!tournamentEndDate || tournamentEndDate === "") { alert("Tournament end date cannot be empty"); return; } diff --git a/src/client/src/TournamentTeams.js b/src/client/src/TournamentTeams.js index b974cdb..6cddc6b 100644 --- a/src/client/src/TournamentTeams.js +++ b/src/client/src/TournamentTeams.js @@ -57,6 +57,19 @@ function TeamCreator(props) { } function TeamList(props) { + const deleteTeam = teamId => { + fetch(process.env.REACT_APP_API_URL + `/team/${teamId}`, {method: "DELETE"}) + .then(res => res.json()) + .then(data => { + if (data.status !== "OK") { + showError(data.data); + return; + } + props.setTeams(props.teams.filter(team => team.id !== teamId)); + }) + .catch(error => showError(error)); + } + return (
@@ -80,7 +93,7 @@ function TeamList(props) { {/* {team.members} */} - + @@ -148,7 +161,7 @@ function TeamEditor(props) { return; } setTeam(data.data); - props.setTeams(props.teams.map(listTeam => listTeam.id === team.id ? team : listTeam)); + props.setTeams(props.teams.map(origTeam => origTeam.id === team.id ? team : origTeam)); props.setSelectedTeamId(-1); } ); @@ -195,7 +208,7 @@ export default function TournamentTeams(props) {
- +