fleet/frontend/components/EnsureUnauthenticated/EnsureUnauthenticated.jsx
Mike Stone 448e806c36 374 confirm invite (#583)
* ConfirmInviteForm

* Render ConfirmInvitePage at /invites/:invite_token

* Add email, pre-fill name, and handle successful submit

* Fix button text
2016-12-29 15:27:43 -05:00

61 lines
1.3 KiB
JavaScript

import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { noop } from 'lodash';
import { push } from 'react-router-redux';
import paths from 'router/paths';
import userInterface from 'interfaces/user';
export default (WrappedComponent) => {
class EnsureUnauthenticated extends Component {
static propTypes = {
currentUser: userInterface,
dispatch: PropTypes.func.isRequired,
isLoadingUser: PropTypes.bool,
};
static defaultProps = {
dispatch: noop,
};
componentWillMount () {
const { currentUser, dispatch } = this.props;
const { HOME } = paths;
if (currentUser) {
dispatch(push(HOME));
}
return false;
}
componentWillReceiveProps (nextProps) {
const { currentUser, dispatch } = nextProps;
const { HOME } = paths;
if (currentUser) {
dispatch(push(HOME));
}
return false;
}
render () {
const { isLoadingUser } = this.props;
if (isLoadingUser) {
return false;
}
return <WrappedComponent {...this.props} />;
}
}
const mapStateToProps = (state) => {
const { loading: isLoadingUser, user: currentUser } = state.auth;
return { currentUser, isLoadingUser };
};
return connect(mapStateToProps)(EnsureUnauthenticated);
};