Skip to content
Snippets Groups Projects
EditUser.js 4.38 KiB
Newer Older
Orlando Piñero's avatar
sth
Orlando Piñero committed
import React, { Component } from "react";
import Button from 'react-bootstrap/Button';
import Form from 'react-bootstrap/Form';
Orlando Piñero's avatar
Orlando Piñero committed
import { connect } from "react-redux";
import { bindActionCreators } from "redux";

Orlando Piñero's avatar
Orlando Piñero committed
import * as userManagementActions from "../state/UserManagementActions"
Orlando Piñero's avatar
Orlando Piñero committed

const mapStateToProps = state => {
    return {
        accessToken: state.AuthenticationReducer.accessToken
    };
Orlando Piñero's avatar
Orlando Piñero committed
}
Orlando Piñero's avatar
sth
Orlando Piñero committed

class EditUser extends Component {
Orlando Piñero's avatar
Orlando Piñero committed

    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)
    }



Orlando Piñero's avatar
sth
Orlando Piñero committed
    render() {
        return (
Orlando Piñero's avatar
Orlando Piñero committed
            <div id="UserManagementPageEditComponent" style={{ display: 'flex', justifyContent: 'center', textAlign: 'left', background: '#fff', borderRadius: '30px', padding: '2rem' , margin: '3rem'}}>
Orlando Piñero's avatar
sth
Orlando Piñero committed
                <Form style={{ width: '60rem' }}>
Orlando Piñero's avatar
Orlando Piñero committed
                    <h2>Benutzer {this.props.editUser.userID} bearbeiten</h2>
Orlando Piñero's avatar
sth
Orlando Piñero committed
                    <Form.Group className="mb-3">
                        <Form.Label>User-ID</Form.Label>
Orlando Piñero's avatar
Orlando Piñero committed
                        <Form.Control name="userID" id="EditUserComponentEditUserID" type="text" disabled={true} defaultValue={this.props.editUser.userID} />
Orlando Piñero's avatar
sth
Orlando Piñero committed
                        <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>
Orlando Piñero's avatar
Orlando Piñero committed
                        <Form.Control name="firstName" id="EditUserComponentEditFirstName" type="text" placeholder="Bitte Vornamen eingeben" defaultValue={this.props.editUser.firstName} onChange={this.handleChange} />
Orlando Piñero's avatar
sth
Orlando Piñero committed
                    </Form.Group>

                    <Form.Group className="mb-3">
                        <Form.Label>Nachname</Form.Label>
Orlando Piñero's avatar
Orlando Piñero committed
                        <Form.Control name="lastName" id="EditUserComponentEditLastName" type="text" placeholder="Bitte Nachnamen eingeben" defaultValue={this.props.editUser.lastName} onChange={this.handleChange} />
Orlando Piñero's avatar
sth
Orlando Piñero committed
                    </Form.Group>

Orlando Piñero's avatar
Orlando Piñero committed
                    <Form.Group className="mb-3">
Orlando Piñero's avatar
sth
Orlando Piñero committed
                        <Form.Label>Passwort</Form.Label>
Orlando Piñero's avatar
Orlando Piñero committed
                        <Form.Control name="password" id="EditUserComponentEditPassword" type="password" placeholder="Passwort" onChange={this.handleChange} />
Orlando Piñero's avatar
sth
Orlando Piñero committed
                        <Form.Text className="text-muted">
                            Wenn das Passwort gesetzt wird, wird es im Backend geändert!
                        </Form.Text>
                    </Form.Group>

Orlando Piñero's avatar
Orlando Piñero committed
                    <Form.Group className="mb-3">
Orlando Piñero's avatar
Orlando Piñero committed
                        <Form.Check name="isAdministrator" id="EditUserComponentEditIsAdministrator" type="checkbox" label="Administrator-Rechte" style={{ color: '#0eb30e' }} onChange={this.handleChange} defaultChecked={this.props.editUser.isAdministrator} />
Orlando Piñero's avatar
sth
Orlando Piñero committed
                    </Form.Group>
Orlando Piñero's avatar
Orlando Piñero committed
                    <Button style={{marginRight: '1rem'}} id="EditUserComponentSaveUserButton" variant="primary" type="submit" onClick={this.handleSubmit}>
Orlando Piñero's avatar
sth
Orlando Piñero committed
                        Speichern
                    </Button>
Orlando Piñero's avatar
Orlando Piñero committed
                    <Button id="OpenUserManagementPageListComponentButton" variant="primary" type="submit" onClick={this.props.goBack}>
Orlando Piñero's avatar
Orlando Piñero committed
                        User-Liste
                    </Button>
Orlando Piñero's avatar
sth
Orlando Piñero committed
                </Form>
            </div >
        )
    }
}

Orlando Piñero's avatar
Orlando Piñero committed
const mapDispatchToProps = dispatch => bindActionCreators({
    editUserWithIDAction: userManagementActions.editUserWithID
}, dispatch)

const ConnectedEditUser = connect(mapStateToProps, mapDispatchToProps)(EditUser)
export default ConnectedEditUser