Skip to content

Commit

Permalink
if the last member of a team is removed, add a new blank one #33
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbeier committed Apr 28, 2017
1 parent af1d76a commit b349aab
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions client/components/MissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ export default React.createClass({

if (_.isEmpty(crew)) return null;

const onChange = oldVolunteerID => newVolunteerID => {
const addMember = () => {
crew.push({ status: 'none', volunteer: _.uniqueId() });
this.setState({ mission });
};

const changeMember = oldVolunteerID => newVolunteerID => {
const assignment = _.find(mission.crew, a => a.volunteer === oldVolunteerID);
assignment.status = 'none';
assignment.volunteer = newVolunteerID;
this.setState({ mission });
};

const onRemove = volunteerID => () => {
const removeMember = volunteerID => () => {
_.remove(crew, n => n.volunteer === volunteerID);
this.setState({ mission });
};

const addMember = () => {
crew.push({ status: 'none', volunteer: _.uniqueId() });
this.setState({ mission });
this.setState({ mission }, (crew.length ? _.noop : addMember));
};

return (
Expand All @@ -118,8 +118,8 @@ export default React.createClass({
key={assignment.volunteer}
assignment={assignment}
mission={this.state.mission}
onChange={onChange(assignment.volunteer)}
onRemove={onRemove(assignment.volunteer)}
onChange={changeMember(assignment.volunteer)}
onRemove={removeMember(assignment.volunteer)}
/>
)}
</tbody>
Expand Down

0 comments on commit b349aab

Please sign in to comment.