2018-07-04 16:43:46 +02:00
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import Main from "./Main";
|
2018-07-09 11:38:13 +02:00
|
|
|
import { connect } from "react-redux";
|
2018-07-24 14:36:14 +02:00
|
|
|
import { translate } from "react-i18next";
|
2018-07-04 16:43:46 +02:00
|
|
|
import { withRouter } from "react-router-dom";
|
2018-07-13 10:57:11 +02:00
|
|
|
import { fetchMe } from "../modules/auth";
|
2018-07-04 16:43:46 +02:00
|
|
|
|
2018-07-11 14:59:01 +02:00
|
|
|
import "./App.css";
|
2018-07-12 16:35:19 +02:00
|
|
|
import "../components/ConfirmAlert.css";
|
2018-07-11 14:59:01 +02:00
|
|
|
import Header from "../components/Header";
|
|
|
|
|
import PrimaryNavigation from "../components/PrimaryNavigation";
|
2018-07-11 21:01:29 +02:00
|
|
|
import Loading from "../components/Loading";
|
2018-07-12 12:57:23 +02:00
|
|
|
import ErrorPage from "../components/ErrorPage";
|
2018-07-13 10:57:11 +02:00
|
|
|
import Footer from "../components/Footer";
|
2018-07-11 14:59:01 +02:00
|
|
|
|
2018-07-04 16:43:46 +02:00
|
|
|
type Props = {
|
2018-07-11 21:01:29 +02:00
|
|
|
me: any,
|
2018-07-11 22:01:36 +02:00
|
|
|
error: Error,
|
|
|
|
|
loading: boolean,
|
2018-07-13 10:57:11 +02:00
|
|
|
authenticated?: boolean,
|
2018-07-24 14:48:20 +02:00
|
|
|
displayName: string,
|
2018-07-24 14:36:14 +02:00
|
|
|
t: string => string,
|
2018-07-13 10:57:11 +02:00
|
|
|
fetchMe: () => void
|
2018-07-05 16:48:56 +02:00
|
|
|
};
|
2018-07-04 16:43:46 +02:00
|
|
|
|
2018-07-11 12:02:53 +02:00
|
|
|
class App extends Component<Props> {
|
|
|
|
|
componentDidMount() {
|
2018-07-11 21:01:29 +02:00
|
|
|
this.props.fetchMe();
|
2018-07-09 11:38:13 +02:00
|
|
|
}
|
2018-07-12 11:33:41 +02:00
|
|
|
|
2018-07-04 16:43:46 +02:00
|
|
|
render() {
|
2018-07-24 14:48:20 +02:00
|
|
|
const { loading, error, authenticated, displayName, t } = this.props;
|
2018-07-11 14:59:01 +02:00
|
|
|
|
2018-07-12 08:23:24 +02:00
|
|
|
let content;
|
2018-07-13 10:57:11 +02:00
|
|
|
const navigation = authenticated ? <PrimaryNavigation /> : "";
|
2018-07-11 14:59:01 +02:00
|
|
|
|
2018-07-11 12:02:53 +02:00
|
|
|
if (loading) {
|
2018-07-12 08:23:24 +02:00
|
|
|
content = <Loading />;
|
2018-07-11 22:01:36 +02:00
|
|
|
} else if (error) {
|
2018-07-12 12:57:23 +02:00
|
|
|
content = (
|
|
|
|
|
<ErrorPage
|
2018-07-24 14:36:14 +02:00
|
|
|
title={t("app.error.title")}
|
|
|
|
|
subtitle={t("app.error.subtitle")}
|
2018-07-12 12:57:23 +02:00
|
|
|
error={error}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2018-07-05 16:48:56 +02:00
|
|
|
} else {
|
2018-07-13 10:57:11 +02:00
|
|
|
content = <Main authenticated={authenticated} />;
|
2018-07-05 16:48:56 +02:00
|
|
|
}
|
2018-07-11 14:59:01 +02:00
|
|
|
return (
|
|
|
|
|
<div className="App">
|
|
|
|
|
<Header>{navigation}</Header>
|
2018-07-12 08:23:24 +02:00
|
|
|
{content}
|
2018-07-24 13:02:50 +02:00
|
|
|
<Footer me={displayName} />
|
2018-07-11 14:59:01 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
2018-07-04 16:43:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 10:57:11 +02:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
2018-07-09 11:38:13 +02:00
|
|
|
return {
|
2018-07-13 10:57:11 +02:00
|
|
|
fetchMe: () => dispatch(fetchMe())
|
2018-07-09 11:38:13 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
2018-07-13 10:57:11 +02:00
|
|
|
let mapped = state.auth.me || {};
|
2018-07-24 13:02:50 +02:00
|
|
|
let displayName;
|
2018-07-13 10:57:11 +02:00
|
|
|
if (state.auth.login) {
|
|
|
|
|
mapped.authenticated = state.auth.login.authenticated;
|
|
|
|
|
}
|
2018-07-24 13:02:50 +02:00
|
|
|
if (state.auth.me && state.auth.me.entry) {
|
2018-07-24 15:43:39 +02:00
|
|
|
displayName = state.auth.me.entry.displayName;
|
2018-07-24 13:02:50 +02:00
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
...mapped,
|
|
|
|
|
displayName
|
|
|
|
|
};
|
2018-07-09 11:38:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default withRouter(
|
|
|
|
|
connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-07-24 14:36:14 +02:00
|
|
|
)(translate("commons")(App))
|
2018-07-09 11:38:13 +02:00
|
|
|
);
|