mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
83 lines
1.8 KiB
JavaScript
83 lines
1.8 KiB
JavaScript
import React, { Component } from "react";
|
|
import Main from "./Main";
|
|
import { connect } from "react-redux";
|
|
import { translate } from "react-i18next";
|
|
import { withRouter } from "react-router-dom";
|
|
import { fetchMe } from "../modules/auth";
|
|
|
|
import "./App.css";
|
|
import "../components/modals/ConfirmAlert.css";
|
|
import { PrimaryNavigation } from "../components/navigation";
|
|
import Loading from "../components/Loading";
|
|
import ErrorPage from "../components/ErrorPage";
|
|
import { Footer, Header } from "../components/layout";
|
|
|
|
type Props = {
|
|
me: Me,
|
|
error: Error,
|
|
loading: boolean,
|
|
authenticated?: boolean,
|
|
t: string => string,
|
|
fetchMe: () => void
|
|
};
|
|
|
|
class App extends Component<Props> {
|
|
componentDidMount() {
|
|
this.props.fetchMe();
|
|
}
|
|
|
|
render() {
|
|
const { me, loading, error, authenticated, t } = this.props;
|
|
|
|
let content;
|
|
const navigation = authenticated ? <PrimaryNavigation /> : "";
|
|
|
|
if (loading) {
|
|
content = <Loading />;
|
|
} else if (error) {
|
|
content = (
|
|
<ErrorPage
|
|
title={t("app.error.title")}
|
|
subtitle={t("app.error.subtitle")}
|
|
error={error}
|
|
/>
|
|
);
|
|
} else {
|
|
content = <Main authenticated={authenticated} />;
|
|
}
|
|
return (
|
|
<div className="App">
|
|
<Header>{navigation}</Header>
|
|
{content}
|
|
<Footer me={me} />
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
|
return {
|
|
fetchMe: () => dispatch(fetchMe())
|
|
};
|
|
};
|
|
|
|
const mapStateToProps = state => {
|
|
let mapped = state.auth.me || {};
|
|
|
|
if (state.auth.login) {
|
|
mapped.authenticated = state.auth.login.authenticated;
|
|
}
|
|
|
|
return {
|
|
...mapped,
|
|
me: mapped.entry
|
|
};
|
|
};
|
|
|
|
export default withRouter(
|
|
connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
)(translate("commons")(App))
|
|
);
|