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
|
|
|
|
2018-07-11 12:02:53 +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";
|
2018-07-11 12:02:53 +02:00
|
|
|
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,
|
2018-07-11 12:02:53 +02:00
|
|
|
error: Error,
|
|
|
|
|
users: Array<User>,
|
2018-07-10 15:18:37 +02:00
|
|
|
fetchUsers: () => void,
|
2018-07-11 12:02:53 +02:00
|
|
|
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> {
|
2018-07-11 12:02:53 +02:00
|
|
|
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>
|
2018-07-11 12:02:53 +02:00
|
|
|
<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) => {
|
2018-07-11 12:02:53 +02:00
|
|
|
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());
|
2018-07-11 12:02:53 +02:00
|
|
|
},
|
|
|
|
|
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);
|