/* Copyright (C) 2017 Cloudbase Solutions SRL This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ import React, { Component, PropTypes } from 'react'; import withStyles from 'isomorphic-style-loader/lib/withStyles'; import s from './EditProfile.scss'; import Dropdown from '../NewDropdown'; import NotificationActions from '../../actions/NotificationActions'; import UserActions from '../../actions/UserActions'; const title = 'Edit Profile'; class EditProfile extends Component { static contextTypes = { onSetTitle: PropTypes.func.isRequired, } static propTypes = { user: PropTypes.object, type: PropTypes.string, closeHandle: PropTypes.func } static defaultProps = { user: null, type: "edit" } constructor(props) { super(props) this.state = { firstName: props.user.firstName, lastName: props.user.lastName, email: props.user.email, primaryProject: null, requiredFields: [], formSubmitted: false } } componentWillMount() { this.context.onSetTitle(title); } componentDidMount() { } handleChangeFirstName(e) { this.setState({ firstName: e.target.value }) } handleChangeLastName(e) { this.setState({ lastName: e.target.value }) } handleChangeEmail(e) { this.setState({ email: e.target.value }) } handleSave() { UserActions.setUserInfo(this.props.user.id, { extra: { firstName: this.state.firstName, lastName: this.state.lastName }, email: this.state.email }) let valid = true for (let i in this.state.currentCloudData) { if (this.state.requiredFields.indexOf(i) > -1 && !this.state.currentCloudData[i]) { valid = false } } if (this.state.connectionName.trim().length == 0) { valid = false } if (!valid) { NotificationActions.notify("Please fill all required fields", "error") this.setState({ formSubmitted: true }) } else { // TODO: Save action here } } isValid(field) { if (field.required && this.state.formSubmitted) { return this.state.currentCloudData[field.name].length != 0; } else { return true } } handleCancel() { this.props.closeHandle(); } render() { let projectOptions = [] if (this.props.user) { projectOptions = this.props.user.projects.map(project => ({ label: project.name, id: project.id })) } return (

{title}

this.handleChangeFirstName(e)} value={this.state.firstName} />
this.handleChangeLastName(e)} value={this.state.lastName} />
this.handleChangeEmail(e)} value={this.state.email} />
this.switchProject(e)} value={this.state.primaryProject} />
); } } export default withStyles(EditProfile, s);