| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- /*
- 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 <http://www.gnu.org/licenses/>.
- */
- 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 (
- <div className={s.root}>
- <div className={s.header}>
- <h3>{title}</h3>
- </div>
- <div className={s.container}>
- <div className={s.fields}>
- <div className="form-group">
- <label>First Name</label>
- <input
- type="text"
- placeholder="First Name"
- onChange={(e) => this.handleChangeFirstName(e)}
- value={this.state.firstName}
- />
- </div>
- <div className="form-group">
- <label>Last Name</label>
- <input
- type="text"
- placeholder="Last Name"
- onChange={(e) => this.handleChangeLastName(e)}
- value={this.state.lastName}
- />
- </div>
- <div className="form-group">
- <label>Email</label>
- <input
- type="text"
- placeholder="Email"
- onChange={(e) => this.handleChangeEmail(e)}
- value={this.state.email}
- />
- </div>
- <div className="form-group">
- <label>Main Project</label>
- <Dropdown
- options={projectOptions}
- placeholder="Switch Project"
- onChange={(e) => this.switchProject(e)}
- value={this.state.primaryProject}
- />
- </div>
- </div>
- <div className={s.buttons}>
- <button className={s.leftBtn + " gray"} onClick={(e) => this.handleCancel(e)}>Cancel</button>
- <button className={s.rightBtn} onClick={(e) => this.handleSave(e)}>Save</button>
- </div>
- </div>
- </div>
- );
- }
- }
- export default withStyles(EditProfile, s);
|