diff --git a/src/user/edit-user.js b/src/user/edit-user.js index 5d20bf4..4925d57 100644 --- a/src/user/edit-user.js +++ b/src/user/edit-user.js @@ -21,28 +21,48 @@ import { Form, Col } from 'react-bootstrap'; import Dialog from '../common/dialogs/dialog'; class EditUserDialog extends React.Component { - valid: true; - constructor(props) { super(props); this.state = { - username: props.user.username, - mail: props.user.mail, - role: props.user.role, - id: props.user.id, - active: props.user.active, - password: '', - confirmPassword: '', - oldPassword: '' + username: '', + mail: '', + role: '', + active: '', + password: "", + confirmPassword: "", + oldPassword: "", } } onClose(canceled) { if (canceled === false) { - if (this.valid) { - this.props.onClose(this.state); + + let user = {} + user.id = this.props.user.id; + + user.password = this.state.password; + user.confirmPassword = this.state.confirmPassword + user.oldpassword = this.state.oldPassword + + if (this.state.username != null && this.state.username !== this.props.user.username){ + user.username = this.state.username } + + if (this.state.mail != null && this.state.mail !== this.props.user.mail){ + user.mail = this.state.mail + } + + if (this.state.role != null && this.state.role !== this.props.user.role){ + user.role = this.state.role + } + + if (this.state.active != null && this.state.active !== this.props.user.active){ + user.active = this.state.active + } + + this.props.onClose(user); + } else { this.props.onClose(); } @@ -50,46 +70,6 @@ class EditUserDialog extends React.Component { handleChange(e) { this.setState({ [e.target.id]: e.target.value }); - - // check all controls - var username = true; - var role = true; - var mail = true; - var pw = true; - var active = true; - var confirmPassword = true; - var oldPassword = true; - - if (this.state.username === '') { - username = false; - } - - if (this.state.role === '') { - role = false; - } - - if (this.state.mail === '') { - mail = false; - } - - if (this.state.password === '') { - pw = false; - } - - if (this.state.active === '') { - active = false; - } - - if (this.state.confirmPassword === '') { - confirmPassword = false; - } - - if (this.state.oldPassword === '') { - oldPassword = false; - } - - // form is valid if any of the fields contain somethig - this.valid = username || role || mail || pw || active || confirmPassword || oldPassword; } resetState() { @@ -97,38 +77,37 @@ class EditUserDialog extends React.Component { username: this.props.user.username, mail: this.props.user.mail, role: this.props.user.role, - id: this.props.user.id }); } render() { return ( - this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}> + this.onClose(c)} onReset={() => this.resetState()} valid={true}>
Username - this.handleChange(e)} /> + this.handleChange(e)} /> E-mail - this.handleChange(e)} /> + this.handleChange(e)} /> Admin Password this.handleChange(e)} /> - Password + New User Password this.handleChange(e)} /> - Confirm New Password + Confirm new Password this.handleChange(e)} /> Role - this.handleChange(e)}> + this.handleChange(e)}>