import React, { PropTypes } from 'react' import _ from 'lodash' import linkState from 'boost/linkState' import api from 'boost/api' export default class TeamSettingTab extends React.Component { constructor (props) { super(props) let team = this.getCurrentTeam(props) this.state = { teamName: team != null ? team.profileName : '', deleteConfirm: false, alert: null } } componentWillReceiveProps (nextProps) { let team = this.getCurrentTeam(nextProps) this.setState({ teamName: team != null ? team.profileName : '', deleteConfirm: false }) } getCurrentTeam (props) { if (props == null) props = this.props return _.findWhere(props.teams, {id: props.currentTeamId}) } handleTeamSelectChange (e) { this.props.switchTeam(e.target.value) } handleSaveButtonClick (e) { let input = { profileName: this.state.teamName } let alert = { type: 'info', message: 'Sending...' } this.setState({alert}, () => { api.updateTeamInfo(this.props.currentTeamId, input) .then(res => { console.log(res.body) let alert = { type: 'success', message: 'Successfully done!' } this.setState({alert}) }) .catch(err => { var message if (err.status != null) { message = err.response.body.message } else if (err.code === 'ECONNREFUSED') { message = 'Can\'t connect to API server.' } else throw err let alert = { type: 'error', message: message } this.setState({alert}) }) }) } renderTeamOptions () { return this.props.teams.map(team => { return ( ) }) } render () { let team = this.getCurrentTeam() if (team == null || team.userType === 'person') { return this.renderNoTeam() } return (
Setting of
Team profile
{this.state.alert != null ? (
{this.state.alert.message}
) : null}
{!this.state.deleteConfirm ? (
) : (
)}
) } renderNoTeam () { return (
Setting of
Please select a team
) } } TeamSettingTab.propTypes = { currentTeamId: PropTypes.number, teams: PropTypes.array, switchTeam: PropTypes.func } TeamSettingTab.prototype.linkState = linkState