mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 22:45:45 +01:00
restructure ui for users
This commit is contained in:
@@ -3,50 +3,23 @@ import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import UserForm from "./UserForm";
|
||||
import type { User } from "../types/User";
|
||||
import type { UserEntry } from "../types/UserEntry";
|
||||
import Loading from "../../components/Loading";
|
||||
|
||||
import { modifyUser, fetchUser } from "../modules/users";
|
||||
import { modifyUser } from "../modules/users";
|
||||
|
||||
type Props = {
|
||||
name: string,
|
||||
fetchUser: string => void,
|
||||
userEntry?: UserEntry,
|
||||
user: User,
|
||||
updateUser: User => void,
|
||||
loading: boolean
|
||||
};
|
||||
|
||||
class EditUser extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
this.props.fetchUser(this.props.name);
|
||||
}
|
||||
|
||||
render() {
|
||||
const submitUser = this.props.updateUser;
|
||||
|
||||
const { userEntry } = this.props;
|
||||
|
||||
if (!userEntry || userEntry.loading) {
|
||||
return <Loading />;
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
<UserForm
|
||||
submitForm={user => submitUser(user)}
|
||||
user={userEntry.entry}
|
||||
loading={userEntry.loading}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const { user, updateUser } = this.props;
|
||||
return <UserForm submitForm={user => updateUser(user)} user={user} />;
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchUser: (name: string) => {
|
||||
dispatch(fetchUser(name));
|
||||
},
|
||||
updateUser: (user: User) => {
|
||||
dispatch(modifyUser(user));
|
||||
}
|
||||
@@ -54,16 +27,7 @@ const mapDispatchToProps = dispatch => {
|
||||
};
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const name = ownProps.match.params.name;
|
||||
let userEntry;
|
||||
if (state.users && state.users.usersByNames) {
|
||||
userEntry = state.users.usersByNames[name];
|
||||
}
|
||||
|
||||
return {
|
||||
name,
|
||||
userEntry
|
||||
};
|
||||
return {};
|
||||
};
|
||||
|
||||
export default connect(
|
||||
|
||||
Reference in New Issue
Block a user