2018-07-18 17:40:05 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
2018-07-26 09:52:21 +02:00
|
|
|
import {connect} from "react-redux";
|
|
|
|
|
import {withRouter} from "react-router-dom";
|
2018-07-25 15:04:19 +02:00
|
|
|
import UserForm from "./../components/UserForm";
|
2018-07-26 09:52:21 +02:00
|
|
|
import type {User} from "../types/User";
|
|
|
|
|
import {modifyUser} from "../modules/users";
|
|
|
|
|
import type {History} from "history";
|
2018-07-18 17:40:05 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2018-07-25 13:21:49 +02:00
|
|
|
user: User,
|
2018-07-26 08:51:05 +02:00
|
|
|
modifyUser: (user: User, callback?: () => void) => void,
|
|
|
|
|
loading: boolean,
|
|
|
|
|
history: History
|
2018-07-18 17:40:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class EditUser extends React.Component<Props> {
|
2018-07-26 08:51:05 +02:00
|
|
|
userModified = (user: User) => () => {
|
|
|
|
|
this.props.history.push(`/user/${user.name}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
modifyUser = (user: User) => {
|
|
|
|
|
this.props.modifyUser(user, this.userModified(user));
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-18 17:40:05 +02:00
|
|
|
render() {
|
2018-07-26 08:51:05 +02:00
|
|
|
const { user } = this.props;
|
|
|
|
|
return <UserForm submitForm={user => this.modifyUser(user)} user={user} />;
|
2018-07-18 17:40:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
2018-07-26 08:51:05 +02:00
|
|
|
modifyUser: (user: User, callback?: () => void) => {
|
|
|
|
|
dispatch(modifyUser(user, callback));
|
2018-07-18 17:40:05 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2018-07-25 13:21:49 +02:00
|
|
|
return {};
|
2018-07-18 17:40:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-07-26 08:51:05 +02:00
|
|
|
)(withRouter(EditUser));
|