Files
SCM-Manager/scm-ui/src/containers/Profile.js

91 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-11-05 16:03:54 +01:00
// @flow
import React from "react";
import {
Page,
Navigation,
2018-11-07 15:43:33 +01:00
Section
} from "../../../scm-ui-components/packages/ui-components/src/index";
2018-11-07 15:43:33 +01:00
import { NavLink, Route, withRouter } from "react-router-dom";
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";
import type { Me } from "../../../scm-ui-components/packages/ui-types/src/index";
import { ErrorPage } from "@scm-manager/ui-components";
2018-11-07 14:45:27 +01:00
import ChangeUserPassword from "./ChangeUserPassword";
import ProfileInfo from "./ProfileInfo";
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) {
return (
<ErrorPage
title={t("profile.error-title")}
subtitle={t("profile.error-subtitle")}
error={{ name: "Error", message: "'me' is undefined" }}
/>
);
2018-11-05 16:03:54 +01:00
}
2018-11-07 14:45:27 +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} />} />
<Route
path={`${url}/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>
<Section label={t("profile.actions-label")} />
<NavLink to={`${url}/password`}>
{t("profile.change-password")}
</NavLink>
</Navigation>
</div>
</div>
2018-11-05 16:03:54 +01:00
</Page>
);
}
}
const mapStateToProps = state => {
return {
me: getMe(state)
};
};
export default compose(
translate("commons"),
2018-11-07 15:43:33 +01:00
connect(mapStateToProps),
withRouter
2018-11-05 16:03:54 +01:00
)(Profile);