2018-07-25 13:21:49 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
2018-09-05 14:32:49 +02:00
|
|
|
import {
|
|
|
|
|
Page,
|
|
|
|
|
Loading,
|
|
|
|
|
Navigation,
|
2019-01-18 11:53:14 +01:00
|
|
|
SubNavigation,
|
2018-09-05 14:32:49 +02:00
|
|
|
Section,
|
|
|
|
|
NavLink,
|
|
|
|
|
ErrorPage
|
|
|
|
|
} from "@scm-manager/ui-components";
|
2018-07-25 13:21:49 +02:00
|
|
|
import { Route } from "react-router";
|
2018-07-25 15:04:19 +02:00
|
|
|
import { Details } from "./../components/table";
|
2019-01-29 08:22:43 +01:00
|
|
|
import EditUser from "./EditUser";
|
2018-09-05 14:32:49 +02:00
|
|
|
import type { User } from "@scm-manager/ui-types";
|
2018-07-26 08:33:22 +02:00
|
|
|
import type { History } from "history";
|
2018-07-30 13:38:15 +02:00
|
|
|
import {
|
2018-11-05 13:14:52 +01:00
|
|
|
fetchUserByName,
|
2018-07-30 13:38:15 +02:00
|
|
|
getUserByName,
|
|
|
|
|
isFetchUserPending,
|
2019-01-18 15:26:55 +01:00
|
|
|
getFetchUserFailure
|
2018-07-30 13:38:15 +02:00
|
|
|
} from "../modules/users";
|
2019-01-29 08:22:43 +01:00
|
|
|
import { EditUserNavLink, SetPasswordNavLink, SetPermissionsNavLink } from "./../components/navLinks";
|
2018-07-26 10:19:26 +02:00
|
|
|
import { translate } from "react-i18next";
|
2018-10-09 16:40:44 +02:00
|
|
|
import { getUsersLink } from "../../modules/indexResource";
|
2018-11-05 15:08:58 +01:00
|
|
|
import SetUserPassword from "../components/SetUserPassword";
|
2019-01-18 14:16:26 +01:00
|
|
|
import SetPermissions from "../../permissions/components/SetPermissions";
|
2019-01-23 15:42:15 +01:00
|
|
|
import {ExtensionPoint} from "@scm-manager/ui-extensions";
|
2018-07-26 10:19:26 +02:00
|
|
|
|
2018-07-25 13:21:49 +02:00
|
|
|
type Props = {
|
|
|
|
|
name: string,
|
2018-07-30 13:38:15 +02:00
|
|
|
user: User,
|
|
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
2018-10-09 16:40:44 +02:00
|
|
|
usersLink: string,
|
2018-07-30 13:38:15 +02:00
|
|
|
|
2019-01-18 15:26:55 +01:00
|
|
|
// dispatcher function
|
2018-11-05 13:14:52 +01:00
|
|
|
fetchUserByName: (string, string) => void,
|
2018-07-30 13:38:15 +02:00
|
|
|
|
|
|
|
|
// context objects
|
|
|
|
|
t: string => string,
|
|
|
|
|
match: any,
|
2018-07-26 08:33:22 +02:00
|
|
|
history: History
|
2018-07-25 13:21:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SingleUser extends React.Component<Props> {
|
|
|
|
|
componentDidMount() {
|
2018-11-05 13:14:52 +01:00
|
|
|
this.props.fetchUserByName(this.props.usersLink, this.props.name);
|
2018-07-25 13:21:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stripEndingSlash = (url: string) => {
|
|
|
|
|
if (url.endsWith("/")) {
|
|
|
|
|
return url.substring(0, url.length - 2);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-26 08:33:22 +02:00
|
|
|
matchedUrl = () => {
|
|
|
|
|
return this.stripEndingSlash(this.props.match.url);
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-25 13:21:49 +02:00
|
|
|
render() {
|
2018-07-30 13:38:15 +02:00
|
|
|
const { t, loading, error, user } = this.props;
|
2018-07-25 13:21:49 +02:00
|
|
|
|
2018-07-30 13:38:15 +02:00
|
|
|
if (error) {
|
2018-07-25 13:21:49 +02:00
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
2019-01-23 11:14:30 +01:00
|
|
|
title={t("singleUser.errorTitle")}
|
|
|
|
|
subtitle={t("singleUser.errorSubtitle")}
|
2018-07-30 13:38:15 +02:00
|
|
|
error={error}
|
2018-07-25 13:21:49 +02:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 13:38:15 +02:00
|
|
|
if (!user || loading) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-26 08:33:22 +02:00
|
|
|
const url = this.matchedUrl();
|
2018-07-25 13:21:49 +02:00
|
|
|
|
2019-01-23 15:42:15 +01:00
|
|
|
const extensionProps = {
|
|
|
|
|
user,
|
|
|
|
|
url
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-25 13:21:49 +02:00
|
|
|
return (
|
|
|
|
|
<Page title={user.displayName}>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column is-three-quarters">
|
|
|
|
|
<Route path={url} exact component={() => <Details user={user} />} />
|
|
|
|
|
<Route
|
2019-01-18 15:26:55 +01:00
|
|
|
path={`${url}/settings/general`}
|
2019-01-29 08:22:43 +01:00
|
|
|
component={() => <EditUser user={user} />}
|
2018-07-25 13:21:49 +02:00
|
|
|
/>
|
2018-11-05 15:08:58 +01:00
|
|
|
<Route
|
2019-01-18 11:53:14 +01:00
|
|
|
path={`${url}/settings/password`}
|
2018-11-05 15:08:58 +01:00
|
|
|
component={() => <SetUserPassword user={user} />}
|
|
|
|
|
/>
|
2019-01-18 10:49:35 +01:00
|
|
|
<Route
|
2019-01-23 14:48:29 +01:00
|
|
|
path={`${url}/settings/permissions`}
|
2019-01-18 14:16:26 +01:00
|
|
|
component={() => (
|
|
|
|
|
<SetPermissions
|
|
|
|
|
selectedPermissionsLink={user._links.permissions}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2019-01-18 10:49:35 +01:00
|
|
|
/>
|
2019-02-15 16:09:46 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="user.route"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2018-07-25 13:21:49 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="column">
|
|
|
|
|
<Navigation>
|
2019-01-23 11:14:30 +01:00
|
|
|
<Section label={t("singleUser.menu.navigationLabel")}>
|
2018-07-30 13:38:15 +02:00
|
|
|
<NavLink
|
|
|
|
|
to={`${url}`}
|
2018-12-21 14:08:19 +01:00
|
|
|
icon="fas fa-info-circle"
|
2019-01-23 11:14:30 +01:00
|
|
|
label={t("singleUser.menu.informationNavLink")}
|
2018-07-30 13:38:15 +02:00
|
|
|
/>
|
2019-01-18 11:53:14 +01:00
|
|
|
<SubNavigation
|
2019-01-18 15:26:55 +01:00
|
|
|
to={`${url}/settings/general`}
|
2019-01-23 11:14:30 +01:00
|
|
|
label={t("singleUser.menu.settingsNavLink")}
|
2019-01-18 11:53:14 +01:00
|
|
|
>
|
2019-01-29 08:22:43 +01:00
|
|
|
<EditUserNavLink
|
2019-01-18 17:28:38 +01:00
|
|
|
user={user}
|
|
|
|
|
editUrl={`${url}/settings/general`}
|
|
|
|
|
/>
|
2019-01-18 11:53:14 +01:00
|
|
|
<SetPasswordNavLink
|
|
|
|
|
user={user}
|
|
|
|
|
passwordUrl={`${url}/settings/password`}
|
|
|
|
|
/>
|
2019-01-23 13:46:46 +01:00
|
|
|
<SetPermissionsNavLink
|
|
|
|
|
user={user}
|
|
|
|
|
permissionsUrl={`${url}/settings/permissions`}
|
|
|
|
|
/>
|
2019-01-23 15:42:15 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="user.subnavigation"
|
|
|
|
|
props={extensionProps}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-01-18 11:53:14 +01:00
|
|
|
</SubNavigation>
|
2018-07-25 13:21:49 +02:00
|
|
|
</Section>
|
|
|
|
|
</Navigation>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
const name = ownProps.match.params.name;
|
2018-07-30 13:38:15 +02:00
|
|
|
const user = getUserByName(state, name);
|
2019-01-18 15:26:55 +01:00
|
|
|
const loading = isFetchUserPending(state, name);
|
|
|
|
|
const error = getFetchUserFailure(state, name);
|
2018-10-09 16:40:44 +02:00
|
|
|
const usersLink = getUsersLink(state);
|
2018-07-25 13:21:49 +02:00
|
|
|
return {
|
2018-10-09 16:40:44 +02:00
|
|
|
usersLink,
|
2018-07-25 13:21:49 +02:00
|
|
|
name,
|
2018-07-30 13:38:15 +02:00
|
|
|
user,
|
|
|
|
|
loading,
|
|
|
|
|
error
|
2018-07-25 13:21:49 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
2018-11-05 13:14:52 +01:00
|
|
|
fetchUserByName: (link: string, name: string) => {
|
|
|
|
|
dispatch(fetchUserByName(link, name));
|
2018-07-25 13:21:49 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-07-26 10:19:26 +02:00
|
|
|
)(translate("users")(SingleUser));
|