2018-07-13 10:57:11 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
2018-07-24 14:36:14 +02:00
|
|
|
import { translate } from "react-i18next";
|
2018-07-13 10:57:11 +02:00
|
|
|
import { Redirect } from "react-router-dom";
|
|
|
|
|
|
|
|
|
|
import { logout, isAuthenticated } from "../modules/auth";
|
|
|
|
|
import ErrorPage from "../components/ErrorPage";
|
|
|
|
|
import Loading from "../components/Loading";
|
|
|
|
|
|
|
|
|
|
type Props = {
|
2018-07-24 14:36:14 +02:00
|
|
|
t: string => string,
|
2018-07-13 10:57:11 +02:00
|
|
|
loading: boolean,
|
|
|
|
|
authenticated: boolean,
|
|
|
|
|
error?: Error,
|
|
|
|
|
logout: () => void
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Logout extends React.Component<Props> {
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.props.logout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-07-24 14:36:14 +02:00
|
|
|
const { authenticated, loading, t, error } = this.props;
|
2018-07-13 10:57:11 +02:00
|
|
|
// TODO logout is called twice
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
2018-07-24 14:36:14 +02:00
|
|
|
title={t("logout.error.title")}
|
|
|
|
|
subtitle={t("logout.error.subtitle")}
|
2018-07-13 10:57:11 +02:00
|
|
|
error={error}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else if (loading || authenticated) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
} else {
|
|
|
|
|
return <Redirect to="/login" />;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
|
let mapped = state.auth.logout || {};
|
|
|
|
|
mapped.authenticated = isAuthenticated(state);
|
|
|
|
|
return mapped;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
logout: () => dispatch(logout())
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-07-24 14:36:14 +02:00
|
|
|
)(translate("commons")(Logout));
|