2019-10-19 16:38:07 +02:00
|
|
|
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,
|
2019-10-19 16:38:07 +02:00
|
|
|
ErrorPage,
|
|
|
|
|
} from '@scm-manager/ui-components';
|
|
|
|
|
import { Route } from 'react-router-dom';
|
|
|
|
|
import { Details } from './../components/table';
|
|
|
|
|
import EditUser from './EditUser';
|
|
|
|
|
import { User } from '@scm-manager/ui-types';
|
|
|
|
|
import { 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-10-19 16:38:07 +02:00
|
|
|
getFetchUserFailure,
|
|
|
|
|
} from '../modules/users';
|
|
|
|
|
import {
|
|
|
|
|
EditUserNavLink,
|
|
|
|
|
SetPasswordNavLink,
|
|
|
|
|
SetPermissionsNavLink,
|
|
|
|
|
} from './../components/navLinks';
|
|
|
|
|
import { translate } from 'react-i18next';
|
|
|
|
|
import { getUsersLink } from '../../modules/indexResource';
|
|
|
|
|
import SetUserPassword from '../components/SetUserPassword';
|
|
|
|
|
import SetPermissions from '../../permissions/components/SetPermissions';
|
|
|
|
|
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 = {
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string;
|
|
|
|
|
user: User;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
usersLink: string;
|
2018-07-30 13:38:15 +02:00
|
|
|
|
2019-01-18 15:26:55 +01:00
|
|
|
// dispatcher function
|
2019-10-19 16:38:07 +02:00
|
|
|
fetchUserByName: (p1: string, p2: string) => void;
|
2018-07-30 13:38:15 +02:00
|
|
|
|
|
|
|
|
// context objects
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
|
|
|
|
match: any;
|
|
|
|
|
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) => {
|
2019-10-19 16:38:07 +02:00
|
|
|
if (url.endsWith('/')) {
|
2018-07-25 13:21:49 +02:00
|
|
|
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-10-19 16:38:07 +02: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,
|
2019-10-19 16:38:07 +02:00
|
|
|
url,
|
2019-01-23 15:42:15 +01:00
|
|
|
};
|
|
|
|
|
|
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-10-19 16:38:07 +02: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-10-19 16:38:07 +02: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-10-19 16:38:07 +02: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
|
2019-02-07 16:55:34 +01:00
|
|
|
name="user.setting"
|
2019-01-23 15:42:15 +01:00
|
|
|
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,
|
2019-10-19 16:38:07 +02:00
|
|
|
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));
|
2019-10-19 16:38:07 +02:00
|
|
|
},
|
2018-07-25 13:21:49 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
2019-10-19 16:38:07 +02:00
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(translate('users')(SingleUser));
|