Newer
Older
import React, { Component } from "react";
import Button from 'react-bootstrap/Button';
import Form from 'react-bootstrap/Form';
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as userManagementActions from '../../actions/UserManagementActions'
return {
accessToken: state.AuthenticationReducer.accessToken
};
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
constructor(props) {
super(props);
this.state = {
userID: '',
firstName: '',
lastName: '',
password: '',
isAdministrator: this.props.editUser.isAdministrator
}
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(e) {
const { name, value } = e.target;
if (name === 'isAdministrator') {
if (e.target.checked) {
this.setState({ [name]: true })
} else {
this.setState({ [name]: false })
}
} else {
this.setState({ [name]: value })
}
}
handleSubmit(e) {
e.preventDefault()
const { editUserWithIDAction } = this.props
editUserWithIDAction(this.state, this.props.editUser.userID, this.props.accessToken)
}
<div id="UserManagementPageEditComponent" style={{ display: 'flex', justifyContent: 'center', textAlign: 'left', background: '#fff', borderRadius: '30px', padding: '2rem' , margin: '3rem'}}>
<h2>Benutzer {this.props.editUser.userID} bearbeiten</h2>
<Form.Control name="userID" id="EditUserComponentEditUserID" type="text" disabled={true} defaultValue={this.props.editUser.userID} />
<Form.Text className="text-muted">
Die User-ID kann nicht geändert werden.
</Form.Text>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>Vorname</Form.Label>
<Form.Control name="firstName" id="EditUserComponentEditFirstName" type="text" placeholder="Bitte Vornamen eingeben" defaultValue={this.props.editUser.firstName} onChange={this.handleChange} />
</Form.Group>
<Form.Group className="mb-3">
<Form.Label>Nachname</Form.Label>
<Form.Control name="lastName" id="EditUserComponentEditLastName" type="text" placeholder="Bitte Nachnamen eingeben" defaultValue={this.props.editUser.lastName} onChange={this.handleChange} />
<Form.Control name="password" id="EditUserComponentEditPassword" type="password" placeholder="Passwort" onChange={this.handleChange} />
<Form.Text className="text-muted">
Wenn das Passwort gesetzt wird, wird es im Backend geändert!
</Form.Text>
</Form.Group>
<Form.Check name="isAdministrator" id="EditUserComponentEditIsAdministrator" type="checkbox" label="Administrator-Rechte" style={{ color: '#0eb30e' }} onChange={this.handleChange} defaultChecked={this.props.editUser.isAdministrator} />
<Button style={{marginRight: '1rem'}} id="EditUserComponentSaveUserButton" variant="primary" type="submit" onClick={this.handleSubmit}>
<Button id="OpenUserManagementPageListComponentButton" variant="primary" type="submit" onClick={this.props.goBack}>
const mapDispatchToProps = dispatch => bindActionCreators({
editUserWithIDAction: userManagementActions.editUserWithID
}, dispatch)
const ConnectedEditUser = connect(mapStateToProps, mapDispatchToProps)(EditUser)
export default ConnectedEditUser