From 03060bd81461815db7db79fe04d14f299daea45c Mon Sep 17 00:00:00 2001 From: Jonny Date: Mon, 17 Jun 2019 15:36:40 +0200 Subject: [PATCH] Add the actual backend call to change tournament information --- js/api.js | 13 +++++++++++++ pages/tournament-edit.js | 29 +++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/js/api.js b/js/api.js index ea3d9a2..dd58be9 100644 --- a/js/api.js +++ b/js/api.js @@ -499,6 +499,19 @@ export function requestTournamentList(type, successCallback, errorCallback) { }); } +export function updateTournament(tournament, successCallback, errorCallback) { + patchRequest(getState(), '/tournaments/' + tournament.id, tournament) + .then(resp => { + storeOptionalToken(resp); + successCallback(); + }).catch(err => { + if (err.response) { + storeOptionalToken(err.response); + } + errorCallback(); + }); +} + function rehydrateApplicationState() { const persistedState = localStorage.getItem('reduxState') ? JSON.parse(localStorage.getItem('reduxState')) : diff --git a/pages/tournament-edit.js b/pages/tournament-edit.js index 2d2269d..dcca7a8 100644 --- a/pages/tournament-edit.js +++ b/pages/tournament-edit.js @@ -13,7 +13,7 @@ import {UserRestrictor, Option} from '../js/components/UserRestrictor'; import {Footer} from '../js/components/Footer'; import {Login} from '../js/components/Login'; import {ErrorPageComponent} from '../js/components/ErrorComponents'; -import {updateTeamName} from '../js/api'; +import {updateTournament, updateTeamName} from '../js/api'; import NumericInput from '../js/components/NumericInput'; import {WarningPopup} from '../js/components/WarningPopup'; @@ -235,7 +235,28 @@ class EditTournamentForm extends React.Component { } handleClick() { - // TODO: Apply changes to the tournament properties + if (this.state.name !== '' && this.state.playoffTeamsAmount === this.state.instantFinalistAmount + + (this.state.intermediateRoundParticipants / 2)) { + updateTournament(this.generateUpdatedTeam(), () => { + notify.show('Turnier wurde erfolgreich geƤndert.', 'success', 5000); + }, () => { + notify.show('Turnier konnte nicht aktualisiert werden.', 'warning', 5000); + }); + } else { + notify.show('Bitte korrigiere deine Eingaben zuerst.', 'warning', 5000); + } + } + + generateUpdatedTeam() { + return { + id: this.props.id, + name: this.state.name, + description: this.state.description, + public: this.state.isPublic, + playoff_teams_amount: this.state.playoffTeamsAmount, + instant_finalists_amount: this.state.instantFinalistAmount, + intermediate_round_participants_amount: this.state.intermediateRoundParticipants + }; } handleNameInput(input) { @@ -283,9 +304,9 @@ class EditTournamentForm extends React.Component { } function mapStateToTournamentFormProps(state) { - const {name, description, isPublic, stages, playoffTeamsAmount, instantFinalistAmount, + const {name, id, description, isPublic, stages, playoffTeamsAmount, instantFinalistAmount, intermediateRoundParticipants} = state.tournamentinfo; - return {name, description, isPublic, stages, playoffTeamsAmount, instantFinalistAmount, + return {name, id, description, isPublic, stages, playoffTeamsAmount, instantFinalistAmount, intermediateRoundParticipants}; }