2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
2018-11-05 16:03:54 +01:00
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
import { Route, withRouter } from "react-router-dom";
|
|
|
|
|
import { getMe } from "../modules/auth";
|
|
|
|
|
import { compose } from "redux";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import { Me } from "@scm-manager/ui-types";
|
2019-10-21 10:57:56 +02:00
|
|
|
import { ErrorPage, Page, Navigation, SubNavigation, Section, NavLink } from "@scm-manager/ui-components";
|
2019-10-20 18:02:52 +02:00
|
|
|
import ChangeUserPassword from "./ChangeUserPassword";
|
|
|
|
|
import ProfileInfo from "./ProfileInfo";
|
|
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
2018-11-05 16:03:54 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
me: Me;
|
2018-11-05 16:03:54 +01:00
|
|
|
|
|
|
|
|
// Context props
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
|
|
|
|
match: any;
|
2018-11-05 16:03:54 +01:00
|
|
|
};
|
|
|
|
|
type State = {};
|
|
|
|
|
|
|
|
|
|
class Profile extends React.Component<Props, State> {
|
2018-11-07 15:43:33 +01:00
|
|
|
stripEndingSlash = (url: string) => {
|
2019-10-20 18:02:52 +02:00
|
|
|
if (url.endsWith("/")) {
|
2018-11-07 15:43:33 +01:00
|
|
|
return url.substring(0, url.length - 2);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
matchedUrl = () => {
|
|
|
|
|
return this.stripEndingSlash(this.props.match.url);
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-05 16:03:54 +01:00
|
|
|
render() {
|
2018-11-07 15:43:33 +01:00
|
|
|
const url = this.matchedUrl();
|
|
|
|
|
|
2018-11-05 16:03:54 +01:00
|
|
|
const { me, t } = this.props;
|
|
|
|
|
|
2018-11-07 14:45:27 +01:00
|
|
|
if (!me) {
|
2018-11-07 12:55:09 +01:00
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
2019-10-20 18:02:52 +02:00
|
|
|
title={t("profile.error-title")}
|
|
|
|
|
subtitle={t("profile.error-subtitle")}
|
2018-11-08 08:48:04 +01:00
|
|
|
error={{
|
2019-10-20 18:02:52 +02:00
|
|
|
name: t("profile.error"),
|
|
|
|
|
message: t("profile.error-message")
|
2018-11-08 08:48:04 +01:00
|
|
|
}}
|
2018-11-07 12:55:09 +01:00
|
|
|
/>
|
|
|
|
|
);
|
2018-11-05 16:03:54 +01:00
|
|
|
}
|
2018-11-07 14:45:27 +01:00
|
|
|
|
2019-01-23 15:42:15 +01:00
|
|
|
const extensionProps = {
|
|
|
|
|
me,
|
2019-10-20 18:02:52 +02:00
|
|
|
url
|
2019-01-23 15:42:15 +01:00
|
|
|
};
|
|
|
|
|
|
2018-11-05 16:03:54 +01:00
|
|
|
return (
|
|
|
|
|
<Page title={me.displayName}>
|
2018-11-07 15:43:33 +01:00
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column is-three-quarters">
|
|
|
|
|
<Route path={url} exact render={() => <ProfileInfo me={me} />} />
|
2019-10-21 10:57:56 +02:00
|
|
|
<Route path={`${url}/settings/password`} render={() => <ChangeUserPassword me={me} />} />
|
|
|
|
|
<ExtensionPoint name="profile.route" props={extensionProps} renderAll={true} />
|
2018-11-07 15:43:33 +01:00
|
|
|
</div>
|
|
|
|
|
<div className="column">
|
|
|
|
|
<Navigation>
|
2019-10-20 18:02:52 +02:00
|
|
|
<Section label={t("profile.navigationLabel")}>
|
2019-10-21 10:57:56 +02:00
|
|
|
<NavLink to={`${url}`} icon="fas fa-info-circle" label={t("profile.informationNavLink")} />
|
|
|
|
|
<SubNavigation to={`${url}/settings/password`} label={t("profile.settingsNavLink")}>
|
|
|
|
|
<NavLink to={`${url}/settings/password`} label={t("profile.changePasswordNavLink")} />
|
|
|
|
|
<ExtensionPoint name="profile.setting" props={extensionProps} renderAll={true} />
|
2019-01-18 11:41:41 +01:00
|
|
|
</SubNavigation>
|
2018-11-14 16:21:54 +01:00
|
|
|
</Section>
|
2018-11-07 15:43:33 +01:00
|
|
|
</Navigation>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2018-11-05 16:03:54 +01:00
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
|
return {
|
2019-10-20 18:02:52 +02:00
|
|
|
me: getMe(state)
|
2018-11-05 16:03:54 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default compose(
|
2019-10-20 18:02:52 +02:00
|
|
|
translate("commons"),
|
2018-11-07 15:43:33 +01:00
|
|
|
connect(mapStateToProps),
|
2019-10-20 18:02:52 +02:00
|
|
|
withRouter
|
2018-11-05 16:03:54 +01:00
|
|
|
)(Profile);
|