Merge pull request #40 from turniere/ticket/TURNIERE-239
Make tournament variables independent of each other
This commit is contained in:
commit
cc3d27b0f6
|
|
@ -183,7 +183,10 @@ const reducerTournamentinfo = (state = defaultStateTournamentinfo, action) => {
|
||||||
postRequest(action.state, '/tournaments', action.parameters.tournament).then(resp => {
|
postRequest(action.state, '/tournaments', action.parameters.tournament).then(resp => {
|
||||||
storeOptionalToken(resp);
|
storeOptionalToken(resp);
|
||||||
action.parameters.successCallback();
|
action.parameters.successCallback();
|
||||||
}).catch(() => {
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
storeOptionalToken(error.response);
|
||||||
|
}
|
||||||
action.parameters.errorCallback();
|
action.parameters.errorCallback();
|
||||||
});
|
});
|
||||||
return Object.assign({}, state, {});
|
return Object.assign({}, state, {});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import {Alert, Collapse} from 'reactstrap';
|
||||||
|
|
||||||
|
export class WarningPopup extends React.Component {
|
||||||
|
render() {
|
||||||
|
return (<Collapse isOpen={this.props.shown}>
|
||||||
|
<Alert className='mt-2 py-1' color='danger'>
|
||||||
|
{this.props.text}
|
||||||
|
</Alert>
|
||||||
|
</Collapse>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WarningPopup.propTypes = {
|
||||||
|
text: PropTypes.string.isRequired,
|
||||||
|
shown: PropTypes.bool.isRequired
|
||||||
|
};
|
||||||
101
pages/create.js
101
pages/create.js
|
|
@ -2,12 +2,25 @@ import Head from 'next/head';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {notify} from 'react-notify-toast';
|
import {notify} from 'react-notify-toast';
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import posed from 'react-pose';
|
import {
|
||||||
import {Button, Card, CardBody, Col, Container, CustomInput, Form, FormGroup, Input, Label} from 'reactstrap';
|
Button,
|
||||||
|
Card,
|
||||||
|
CardBody,
|
||||||
|
Col,
|
||||||
|
Collapse,
|
||||||
|
Container,
|
||||||
|
CustomInput,
|
||||||
|
Form,
|
||||||
|
FormGroup,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
Row
|
||||||
|
} from 'reactstrap';
|
||||||
import {TurniereNavigation} from '../js/components/Navigation';
|
import {TurniereNavigation} from '../js/components/Navigation';
|
||||||
import {Footer} from '../js/components/Footer';
|
import {Footer} from '../js/components/Footer';
|
||||||
import EditableStringList from '../js/components/EditableStringList';
|
import EditableStringList from '../js/components/EditableStringList';
|
||||||
import {createTournament} from '../js/api';
|
import {createTournament} from '../js/api';
|
||||||
|
import {WarningPopup} from '../js/components/WarningPopup';
|
||||||
|
|
||||||
import '../static/css/everypage.css';
|
import '../static/css/everypage.css';
|
||||||
import RequireLogin from '../js/components/RequireLogin';
|
import RequireLogin from '../js/components/RequireLogin';
|
||||||
|
|
@ -48,14 +61,6 @@ function CreateTournamentCard() {
|
||||||
</Container>);
|
</Container>);
|
||||||
}
|
}
|
||||||
|
|
||||||
const GroupphaseFader = posed.div({
|
|
||||||
visible: {
|
|
||||||
opacity: 1, height: 150
|
|
||||||
}, hidden: {
|
|
||||||
opacity: 0, height: 0
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
class CreateTournamentForm extends React.Component {
|
class CreateTournamentForm extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
@ -78,6 +83,7 @@ class CreateTournamentForm extends React.Component {
|
||||||
this.increaseGroupSize = this.increaseGroupSize.bind(this);
|
this.increaseGroupSize = this.increaseGroupSize.bind(this);
|
||||||
this.decreaseGroupSize = this.decreaseGroupSize.bind(this);
|
this.decreaseGroupSize = this.decreaseGroupSize.bind(this);
|
||||||
this.generateTournamentCreationObject = this.generateTournamentCreationObject.bind(this);
|
this.generateTournamentCreationObject = this.generateTournamentCreationObject.bind(this);
|
||||||
|
this.valuesAreCredible = this.valuesAreCredible.bind(this);
|
||||||
|
|
||||||
this.create = this.create.bind(this);
|
this.create = this.create.bind(this);
|
||||||
}
|
}
|
||||||
|
|
@ -104,26 +110,34 @@ class CreateTournamentForm extends React.Component {
|
||||||
checked={this.state.groupPhaseEnabled}
|
checked={this.state.groupPhaseEnabled}
|
||||||
onChange={this.handleGroupPhaseEnabledInput}/>
|
onChange={this.handleGroupPhaseEnabledInput}/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<GroupphaseFader pose={this.state.groupPhaseEnabled ? 'visible' : 'hidden'}
|
<Collapse isOpen={this.state.groupPhaseEnabled}>
|
||||||
className="groupphasefader">
|
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<Label for="teams-per-group">Anzahl Teams pro Gruppe</Label>
|
<Label for="teams-per-group">Anzahl Teams pro Gruppe</Label>
|
||||||
<Col xs="3" className="pl-0">
|
<Row>
|
||||||
<NumericInput value={this.state.groupSize}
|
<Col xs="3">
|
||||||
incrementText="+1" incrementCallback={this.increaseGroupSize}
|
<NumericInput value={this.state.groupSize}
|
||||||
decrementText="-1" decrementCallback={this.decreaseGroupSize}/>
|
incrementText="+1" incrementCallback={this.increaseGroupSize}
|
||||||
</Col>
|
decrementText="-1" decrementCallback={this.decreaseGroupSize}/>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<WarningPopup text='Es gibt noch unvollständige Gruppen.' shown={this.areGroupsIncomplete()}/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<Label for="teams-group-to-playoff">Wie viele Teams sollen nach der Gruppenphase
|
<Label for="teams-group-to-playoff">Wie viele Teams sollen nach der Gruppenphase
|
||||||
weiterkommen?</Label>
|
weiterkommen?</Label>
|
||||||
<Col xs="3" className="pl-0">
|
<Row>
|
||||||
<NumericInput value={this.state.groupAdvance}
|
<Col xs="3">
|
||||||
incrementText="×2" incrementCallback={this.increaseGroupAdvance}
|
<NumericInput value={this.state.groupAdvance}
|
||||||
decrementText="÷2" decrementCallback={this.decreaseGroupAdvance}/>
|
incrementText="×2" incrementCallback={this.increaseGroupAdvance}
|
||||||
</Col>
|
decrementText="÷2" decrementCallback={this.decreaseGroupAdvance}/>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<WarningPopup
|
||||||
|
text={'Füge bitte noch ' + (this.state.groupAdvance - this.state.teams.length)
|
||||||
|
+ ' Team(s) hinzu, um ' + this.state.groupAdvance + ' Team(s) im Playoff zu haben.'}
|
||||||
|
shown={this.state.teams.length < this.state.groupAdvance}/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</GroupphaseFader>
|
</Collapse>
|
||||||
</Form>
|
</Form>
|
||||||
<h3 className="custom-font mt-4">Teams</h3>
|
<h3 className="custom-font mt-4">Teams</h3>
|
||||||
<EditableStringList
|
<EditableStringList
|
||||||
|
|
@ -142,6 +156,10 @@ class CreateTournamentForm extends React.Component {
|
||||||
</div>);
|
</div>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
areGroupsIncomplete() {
|
||||||
|
return this.state.groups.filter(group => group.length !== this.state.groupSize).length !== 0;
|
||||||
|
}
|
||||||
|
|
||||||
teamListUpdate(list) {
|
teamListUpdate(list) {
|
||||||
this.setState({teams: list});
|
this.setState({teams: list});
|
||||||
}
|
}
|
||||||
|
|
@ -153,11 +171,9 @@ class CreateTournamentForm extends React.Component {
|
||||||
increaseGroupAdvance() {
|
increaseGroupAdvance() {
|
||||||
const newGroupAdvance = this.state.groupAdvance * 2;
|
const newGroupAdvance = this.state.groupAdvance * 2;
|
||||||
|
|
||||||
if (newGroupAdvance <= this.state.groupSize) {
|
this.setState({
|
||||||
this.setState({
|
groupAdvance: newGroupAdvance
|
||||||
groupAdvance: newGroupAdvance
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
decreaseGroupAdvance() {
|
decreaseGroupAdvance() {
|
||||||
|
|
@ -171,21 +187,14 @@ class CreateTournamentForm extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
increaseGroupSize() {
|
increaseGroupSize() {
|
||||||
this.setState({groupSize: this.state.groupSize+1});
|
this.setState({groupSize: this.state.groupSize + 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
decreaseGroupSize() {
|
decreaseGroupSize() {
|
||||||
const newGroupSize = this.state.groupSize - 1;
|
const newGroupSize = this.state.groupSize - 1;
|
||||||
|
|
||||||
if (newGroupSize >= 3) {
|
if (newGroupSize >= 3) {
|
||||||
if (newGroupSize >= this.state.groupAdvance) {
|
this.setState({groupSize: newGroupSize});
|
||||||
this.setState({groupSize: newGroupSize});
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
groupSize: newGroupSize,
|
|
||||||
groupAdvance: Math.floor(this.state.groupAdvance / 2)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,11 +215,19 @@ class CreateTournamentForm extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
createTournament(this.generateTournamentCreationObject(), () => {
|
if (this.valuesAreCredible()) {
|
||||||
notify.show('Das Turnier wurde erfolgreich erstellt.', 'success', 5000);
|
createTournament(this.generateTournamentCreationObject(), () => {
|
||||||
}, () => {
|
notify.show('Das Turnier wurde erfolgreich erstellt.', 'success', 5000);
|
||||||
notify.show('Das Turnier konnte nicht erstellt werden.', 'warning', 5000);
|
}, () => {
|
||||||
});
|
notify.show('Das Turnier konnte nicht erstellt werden.', 'warning', 5000);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
notify.show('Bitte korrigiere deine Eingaben zuerst.', 'warning', 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
valuesAreCredible() {
|
||||||
|
return this.state.teams.length >= this.state.groupAdvance && !this.areGroupsIncomplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
generateTournamentCreationObject() {
|
generateTournamentCreationObject() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue