restructure ui for users

This commit is contained in:
Sebastian Sdorra
2018-07-25 13:21:49 +02:00
parent 978565609a
commit fe0b7ea986
19 changed files with 426 additions and 201 deletions

View File

@@ -3,33 +3,48 @@ import React from "react";
import { connect } from "react-redux";
import UserForm from "./UserForm";
import type { User } from "../types/User";
import type { History } from "history";
import { createUser } from "../modules/users";
import Page from "../../components/Page";
type Props = {
addUser: User => void,
loading?: boolean
addUser: (user: User, callback?: () => void) => void,
loading?: boolean,
error?: Error,
history: History
};
class AddUser extends React.Component<Props> {
render() {
const addUser = this.props.addUser;
userCreated = () => {
const { history } = this.props;
history.push("/users");
};
createUser = (user: User) => {
this.props.addUser(user, this.userCreated);
};
render() {
const { loading, error } = this.props;
// TODO i18n
return (
<div>
<UserForm
submitForm={user => addUser(user)}
loading={this.props.loading}
/>
</div>
<Page
title="Create User"
subtitle="Create a new user"
loading={loading}
error={error}
>
<UserForm submitForm={user => this.createUser(user)} />
</Page>
);
}
}
const mapDispatchToProps = dispatch => {
return {
addUser: (user: User) => {
dispatch(createUser(user));
addUser: (user: User, callback?: () => void) => {
dispatch(createUser(user, callback));
}
};
};