mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 17:28:54 +00:00
efb35b537a
* add prettier and have it format all js code except website: : * trying running prettier check in CI * fix runs on in CI * change CI job name * fix prettier erros and fix CI
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
import React, { Component } from "react";
|
|
import PropTypes from "prop-types";
|
|
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 { currentUser, isLoadingUser } = this.props;
|
|
|
|
if (isLoadingUser || currentUser) {
|
|
return false;
|
|
}
|
|
|
|
return <WrappedComponent {...this.props} />;
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = (state) => {
|
|
const { loading: isLoadingUser, user: currentUser } = state.auth;
|
|
|
|
return { currentUser, isLoadingUser };
|
|
};
|
|
|
|
return connect(mapStateToProps)(EnsureUnauthenticated);
|
|
};
|