UNPKG

stitch-ui

Version:

44 lines (36 loc) 1.09 kB
import React from "react"; import PropTypes from "prop-types"; import { Admin } from "mongodb-stitch"; import { connect } from "react-redux"; import { Banner } from "../../core"; import { clearUserProfile } from "../../actions"; class Logout extends React.Component { componentDidMount() { this.props.client.client .logout() .then(() => this.context.router.history.push("/login")) .then(this.props.clearUserProfile) .catch(e => this.setState({ error: e.message })); } render() { return ( <Banner message={(this.state || {}).error} error onClear={() => this.setState({ error: null })} /> ); } } Logout.contextTypes = { router: PropTypes.object }; Logout.propTypes = { client: PropTypes.instanceOf(Admin).isRequired, clearUserProfile: PropTypes.func.isRequired }; const mapStateToProps = state => ({ client: state.base.client }); const mapDispatchToProps = dispatch => ({ clearUserProfile: () => dispatch(clearUserProfile()) }); export default connect(mapStateToProps, mapDispatchToProps)(Logout);