2018-07-18 17:40:05 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import UserForm from "./UserForm";
|
|
|
|
|
import type { User } from "../types/User";
|
|
|
|
|
|
2018-07-23 17:00:33 +02:00
|
|
|
import { createUser } from "../modules/users";
|
2018-07-18 17:40:05 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2018-07-19 12:05:50 +02:00
|
|
|
addUser: User => void,
|
|
|
|
|
loading?: boolean
|
2018-07-18 17:40:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class AddUser extends React.Component<Props> {
|
|
|
|
|
render() {
|
|
|
|
|
const addUser = this.props.addUser;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2018-07-19 12:05:50 +02:00
|
|
|
<UserForm
|
|
|
|
|
submitForm={user => addUser(user)}
|
|
|
|
|
loading={this.props.loading}
|
|
|
|
|
/>
|
2018-07-18 17:40:05 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
addUser: (user: User) => {
|
2018-07-23 17:00:33 +02:00
|
|
|
dispatch(createUser(user));
|
2018-07-18 17:40:05 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2018-07-19 12:05:50 +02:00
|
|
|
if (state.users && state.users.users) {
|
|
|
|
|
return {
|
|
|
|
|
loading: state.users.users.loading
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-07-18 17:40:05 +02:00
|
|
|
return {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)(AddUser);
|