Files
SCM-Manager/scm-ui/src/users/containers/Users.js

79 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-07-02 16:05:58 +02:00
// @flow
2018-07-10 08:38:38 +02:00
import React from "react";
import { connect } from "react-redux";
2018-07-02 16:05:58 +02:00
import { fetchUsers, deleteUser } from "../modules/users";
2018-07-10 08:38:38 +02:00
import Login from "../../containers/Login";
import UserRow from "./UserRow";
import type { User } from "../types/User";
2018-07-02 16:05:58 +02:00
type Props = {
2018-07-02 16:22:24 +02:00
login: boolean,
error: Error,
users: Array<User>,
2018-07-10 15:18:37 +02:00
fetchUsers: () => void,
deleteUser: string => void
2018-07-10 08:38:38 +02:00
};
2018-07-02 16:05:58 +02:00
class Users extends React.Component<Props> {
componentDidMount() {
this.props.fetchUsers();
2018-07-02 16:05:58 +02:00
}
render() {
2018-07-10 08:38:38 +02:00
if (this.props.users) {
2018-07-02 16:05:58 +02:00
return (
<div>
<h1>SCM</h1>
<h2>Users</h2>
2018-07-10 08:38:38 +02:00
<table>
<thead>
<tr>
<th>Name</th>
<th>Display Name</th>
2018-07-10 08:38:38 +02:00
<th>E-Mail</th>
<th>Admin</th>
</tr>
</thead>
<tbody>
{this.props.users.map((user, index) => {
return (
<UserRow
key={index}
user={user}
deleteUser={this.props.deleteUser}
/>
);
2018-07-10 08:38:38 +02:00
})}
</tbody>
</table>
2018-07-02 16:05:58 +02:00
</div>
);
2018-07-10 08:38:38 +02:00
} else {
return <div>Loading...</div>;
}
2018-07-02 16:05:58 +02:00
}
}
2018-07-10 08:38:38 +02:00
const mapStateToProps = state => {
return {
users: state.users.users
};
2018-07-02 16:05:58 +02:00
};
2018-07-10 08:38:38 +02:00
const mapDispatchToProps = dispatch => {
2018-07-02 16:05:58 +02:00
return {
2018-07-10 08:38:38 +02:00
fetchUsers: () => {
dispatch(fetchUsers());
},
deleteUser: (link: string) => {
dispatch(deleteUser(link));
2018-07-02 16:05:58 +02:00
}
2018-07-10 08:38:38 +02:00
};
2018-07-02 16:05:58 +02:00
};
2018-07-10 08:38:38 +02:00
export default connect(
mapStateToProps,
mapDispatchToProps
)(Users);