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

63 lines
1.3 KiB
JavaScript
Raw Normal View History

//@flow
import React from "react";
import { connect } from "react-redux";
2018-07-25 15:04:19 +02:00
import UserForm from "./../components/UserForm";
import type { User } from "../types/User";
2018-07-25 13:21:49 +02:00
import type { History } from "history";
2018-07-23 17:00:33 +02:00
import { createUser } from "../modules/users";
2018-07-25 14:29:43 +02:00
import { Page } from "../../components/layout";
type Props = {
2018-07-25 13:21:49 +02:00
addUser: (user: User, callback?: () => void) => void,
loading?: boolean,
error?: Error,
history: History
};
class AddUser extends React.Component<Props> {
2018-07-25 13:21:49 +02:00
userCreated = () => {
const { history } = this.props;
history.push("/users");
};
createUser = (user: User) => {
this.props.addUser(user, this.userCreated);
};
render() {
2018-07-25 13:21:49 +02:00
const { loading, error } = this.props;
2018-07-25 13:21:49 +02:00
// TODO i18n
return (
2018-07-25 13:21:49 +02:00
<Page
title="Create User"
subtitle="Create a new user"
loading={loading}
error={error}
>
<UserForm submitForm={user => this.createUser(user)} />
</Page>
);
}
}
const mapDispatchToProps = dispatch => {
return {
2018-07-25 13:21:49 +02:00
addUser: (user: User, callback?: () => void) => {
dispatch(createUser(user, callback));
}
};
};
const mapStateToProps = (state, ownProps) => {
if (state.users && state.users.create) {
return state.users.create;
2018-07-19 12:05:50 +02:00
}
return {};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(AddUser);