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

75 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, getUsersFromState } from "../modules/users";
import Loading from "../../components/Loading";
2018-07-18 14:02:07 +02:00
import ErrorNotification from "../../components/ErrorNotification";
2018-07-11 17:02:38 +02:00
import UserTable from "./UserTable";
import type { User } from "../types/User";
2018-07-17 11:29:58 +02:00
import type { UserEntry } from "../types/UserEntry";
2018-07-12 16:02:37 +02:00
2018-07-02 16:05:58 +02:00
type Props = {
2018-07-02 16:22:24 +02:00
login: boolean,
error: Error,
2018-07-12 16:02:37 +02:00
userEntries: Array<UserEntry>,
2018-07-10 15:18:37 +02:00
fetchUsers: () => void,
deleteUser: User => void
2018-07-10 08:38:38 +02:00
};
2018-07-02 16:05:58 +02:00
2018-07-17 08:39:51 +02:00
class Users extends React.Component<Props, User> {
componentDidMount() {
this.props.fetchUsers();
2018-07-02 16:05:58 +02:00
}
render() {
return (
<section className="section">
<div className="container">
<h1 className="title">SCM</h1>
<h2 className="subtitle">Users</h2>
{this.renderContent()}
</div>
</section>
);
}
renderContent() {
const { userEntries, deleteUser, error } = this.props;
2018-07-12 16:02:37 +02:00
if (userEntries) {
2018-07-02 16:05:58 +02:00
return (
<div>
2018-07-18 14:02:07 +02:00
<ErrorNotification error={error} />
<UserTable entries={userEntries} deleteUser={deleteUser} />
</div>
2018-07-02 16:05:58 +02:00
);
2018-07-10 08:38:38 +02:00
} else {
return <Loading />;
2018-07-10 08:38:38 +02:00
}
2018-07-02 16:05:58 +02:00
}
}
2018-07-10 08:38:38 +02:00
const mapStateToProps = state => {
2018-07-12 16:02:37 +02:00
const userEntries = getUsersFromState(state);
2018-07-10 08:38:38 +02:00
return {
2018-07-17 08:39:51 +02:00
userEntries,
2018-07-18 14:02:07 +02:00
error: state.users.error
2018-07-10 08:38:38 +02:00
};
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: (user: User) => {
dispatch(deleteUser(user));
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);