2018-11-05 16:03:54 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
|
2018-11-14 16:21:54 +01:00
|
|
|
import { Route, withRouter } from "react-router-dom";
|
2018-11-07 12:55:09 +01:00
|
|
|
import { getMe } from "../modules/auth";
|
2018-11-05 16:03:54 +01:00
|
|
|
import { compose } from "redux";
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { translate } from "react-i18next";
|
2018-11-08 08:48:04 +01:00
|
|
|
import type { Me } from "@scm-manager/ui-types";
|
|
|
|
|
import {
|
|
|
|
|
ErrorPage,
|
|
|
|
|
Page,
|
|
|
|
|
Navigation,
|
2019-01-18 11:41:41 +01:00
|
|
|
SubNavigation,
|
2018-11-14 16:21:54 +01:00
|
|
|
Section,
|
|
|
|
|
NavLink
|
2018-11-08 08:48:04 +01:00
|
|
|
} from "@scm-manager/ui-components";
|
2018-11-07 14:45:27 +01:00
|
|
|
import ChangeUserPassword from "./ChangeUserPassword";
|
|
|
|
|
import ProfileInfo from "./ProfileInfo";
|
2019-01-23 17:01:12 +01:00
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
2018-11-05 16:03:54 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
me: Me,
|
|
|
|
|
|
|
|
|
|
// Context props
|
2018-11-07 15:43:33 +01:00
|
|
|
t: 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) => {
|
|
|
|
|
if (url.endsWith("/")) {
|
|
|
|
|
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
|
|
|
|
|
title={t("profile.error-title")}
|
|
|
|
|
subtitle={t("profile.error-subtitle")}
|
2018-11-08 08:48:04 +01:00
|
|
|
error={{
|
|
|
|
|
name: t("profile.error"),
|
|
|
|
|
message: t("profile.error-message")
|
|
|
|
|
}}
|
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,
|
|
|
|
|
url
|
|
|
|
|
};
|
|
|
|
|
|
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} />} />
|
|
|
|
|
<Route
|
2019-01-18 11:41:41 +01:00
|
|
|
path={`${url}/settings/password`}
|
2018-11-07 17:05:46 +01:00
|
|
|
render={() => <ChangeUserPassword me={me} />}
|
2018-11-07 15:43:33 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="column">
|
|
|
|
|
<Navigation>
|
2019-01-18 10:25:35 +01:00
|
|
|
<Section label={t("profile.navigationLabel")}>
|
2018-11-14 16:21:54 +01:00
|
|
|
<NavLink
|
2019-01-18 11:41:41 +01:00
|
|
|
to={`${url}`}
|
2019-01-23 17:01:12 +01:00
|
|
|
icon="fas fa-info-circle"
|
2019-01-18 11:41:41 +01:00
|
|
|
label={t("profile.informationNavLink")}
|
2018-11-14 16:21:54 +01:00
|
|
|
/>
|
2019-01-18 11:41:41 +01:00
|
|
|
<SubNavigation
|
2019-01-18 14:32:35 +01:00
|
|
|
to={`${url}/settings/password`}
|
2019-01-18 11:41:41 +01:00
|
|
|
label={t("profile.settingsNavLink")}
|
|
|
|
|
>
|
|
|
|
|
<NavLink
|
|
|
|
|
to={`${url}/settings/password`}
|
|
|
|
|
label={t("profile.changePasswordNavLink")}
|
|
|
|
|
/>
|
2019-01-23 15:42:15 +01:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="profile.subnavigation"
|
|
|
|
|
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 {
|
|
|
|
|
me: getMe(state)
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default compose(
|
2018-11-07 12:55:09 +01:00
|
|
|
translate("commons"),
|
2018-11-07 15:43:33 +01:00
|
|
|
connect(mapStateToProps),
|
|
|
|
|
withRouter
|
2018-11-05 16:03:54 +01:00
|
|
|
)(Profile);
|