Use new modal for edit functionality

This commit is contained in:
Jonas Schwabe 2017-01-30 21:46:58 +01:00
parent b94303bfc5
commit bb21cf56d3
2 changed files with 42 additions and 10 deletions

View file

@ -13,6 +13,15 @@ class NewTeamModal extends React.Component {
}; };
} }
componentWillMount() {
this.state = {
teamName: this.props.team ? this.props.team.name : '',
teamUrl: this.props.team ? this.props.team.url : '',
teamIndex: this.props.team ? this.props.team.index : false,
saveStarted: false
};
}
getTeamNameValidationError() { getTeamNameValidationError() {
if (!this.state.saveStarted) { if (!this.state.saveStarted) {
return null; return null;
@ -69,7 +78,8 @@ class NewTeamModal extends React.Component {
if (this.validateForm()) { if (this.validateForm()) {
this.props.onSave({ this.props.onSave({
url: this.state.teamUrl, url: this.state.teamUrl,
name: this.state.teamName name: this.state.teamName,
index: this.state.teamIndex
}); });
} }
}); });
@ -159,7 +169,8 @@ class NewTeamModal extends React.Component {
NewTeamModal.propTypes = { NewTeamModal.propTypes = {
onClose: React.PropTypes.func, onClose: React.PropTypes.func,
onSave: React.PropTypes.func onSave: React.PropTypes.func,
team: React.PropTypes.object
}; };
module.exports = NewTeamModal; module.exports = NewTeamModal;

View file

@ -14,7 +14,7 @@ const TeamList = React.createClass({
getInitialState() { getInitialState() {
return { return {
showTeamListItemNew: false, showEditTeamForm: false,
indexToRemoveServer: -1, indexToRemoveServer: -1,
team: { team: {
url: '', url: '',
@ -41,7 +41,7 @@ const TeamList = React.createClass({
} }
this.setState({ this.setState({
showTeamListItemNew: false, showEditTeamForm: false,
team: { team: {
url: '', url: '',
name: '', name: '',
@ -53,7 +53,7 @@ const TeamList = React.createClass({
}, },
handleTeamEditing(teamName, teamUrl, teamIndex) { handleTeamEditing(teamName, teamUrl, teamIndex) {
this.setState({ this.setState({
showTeamListItemNew: true, showEditTeamForm: true,
team: { team: {
url: teamUrl, url: teamUrl,
name: teamName, name: teamName,
@ -94,19 +94,40 @@ const TeamList = React.createClass({
}); });
var addTeamForm; var addTeamForm;
if (this.props.showAddTeamForm || this.state.showTeamListItemNew) { if (this.props.showAddTeamForm || this.state.showEditTeamForm) {
addTeamForm = ( addTeamForm = (
<NewTeamModal <NewTeamModal
onClose={this.props.toggleAddTeamForm} onClose={() => {
onSave={(newTeam) => {
this.setState({ this.setState({
showNewTeamModal: false showNewTeamModal: false,
showEditTeamForm: false,
team: {
name: '',
url: '',
index: false
}
});
}}
onSave={(newTeam) => {
if (this.props.showAddTeamForm) {
this.props.teams.push(newTeam);
} else {
this.props.teams[newTeam.index] = newTeam;
}
this.setState({
showNewTeamModal: false,
showEditTeamForm: false,
team: {
name: '',
url: '',
index: false
}
}); });
this.props.teams.push(newTeam);
this.render(); this.render();
this.props.onTeamsChange(this.props.teams); this.props.onTeamsChange(this.props.teams);
}} }}
team={this.state.team}
/>); />);
} else { } else {
addTeamForm = ''; addTeamForm = '';