mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
restructure ui for users
This commit is contained in:
118
scm-ui/src/users/containers/SingleUser.js
Normal file
118
scm-ui/src/users/containers/SingleUser.js
Normal file
@@ -0,0 +1,118 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import Page from "../../components/Page";
|
||||
import { Route } from "react-router";
|
||||
import Details from "./Details";
|
||||
import EditUser from "./EditUser";
|
||||
import type { User } from "../types/User";
|
||||
import type { UserEntry } from "../types/UserEntry";
|
||||
import { fetchUser, deleteUser } from "../modules/users";
|
||||
import Loading from "../../components/Loading";
|
||||
|
||||
import {
|
||||
Navigation,
|
||||
Section,
|
||||
NavLink
|
||||
} from "../../components/SecondaryNavigation";
|
||||
import DeleteUserButton from "./DeleteUserButton";
|
||||
import ErrorPage from "../../components/ErrorPage";
|
||||
|
||||
type Props = {
|
||||
name: string,
|
||||
userEntry?: UserEntry,
|
||||
match: any,
|
||||
deleteUser: (user: User) => void,
|
||||
fetchUser: string => void
|
||||
};
|
||||
|
||||
class SingleUser extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
this.props.fetchUser(this.props.name);
|
||||
}
|
||||
|
||||
stripEndingSlash = (url: string) => {
|
||||
if (url.endsWith("/")) {
|
||||
return url.substring(0, url.length - 2);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
render() {
|
||||
const { userEntry, match, deleteUser } = this.props;
|
||||
|
||||
if (!userEntry || userEntry.loading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
if (userEntry.error) {
|
||||
return (
|
||||
<ErrorPage
|
||||
title="Error"
|
||||
subtitle="Unknown user error"
|
||||
error={userEntry.error}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const user = userEntry.entry;
|
||||
const url = this.stripEndingSlash(match.url);
|
||||
|
||||
// TODO i18n
|
||||
|
||||
return (
|
||||
<Page title={user.displayName}>
|
||||
<div className="columns">
|
||||
<div className="column is-three-quarters">
|
||||
<Route path={url} exact component={() => <Details user={user} />} />
|
||||
<Route
|
||||
path={`${url}/edit`}
|
||||
component={() => <EditUser user={user} />}
|
||||
/>
|
||||
</div>
|
||||
<div className="column">
|
||||
<Navigation>
|
||||
<Section label="Navigation">
|
||||
<NavLink to={`${url}`} label="Information" />
|
||||
<NavLink to={`${url}/edit`} label="Edit" />
|
||||
</Section>
|
||||
<Section label="Actions">
|
||||
<DeleteUserButton user={user} deleteUser={deleteUser} />
|
||||
<NavLink to="/users" label="Back" />
|
||||
</Section>
|
||||
</Navigation>
|
||||
</div>
|
||||
</div>
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchUser: (name: string) => {
|
||||
dispatch(fetchUser(name));
|
||||
},
|
||||
deleteUser: (user: User) => {
|
||||
dispatch(deleteUser(user));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(SingleUser);
|
||||
Reference in New Issue
Block a user