fleet/frontend/components/App/App.jsx
Gabe Hernandez efb35b537a
add prettier and have it format all fleet application code (#625)
* 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
2021-04-12 14:32:25 +01:00

67 lines
1.5 KiB
JavaScript

import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { noop } from "lodash";
import classnames from "classnames";
import { authToken } from "utilities/local";
import { fetchCurrentUser } from "redux/nodes/auth/actions";
import { getConfig, getEnrollSecret } from "redux/nodes/app/actions";
import userInterface from "interfaces/user";
export class App extends Component {
static propTypes = {
children: PropTypes.element,
dispatch: PropTypes.func,
user: userInterface,
};
static defaultProps = {
dispatch: noop,
};
componentWillMount() {
const { dispatch, user } = this.props;
if (!user && authToken()) {
dispatch(fetchCurrentUser()).catch(() => false);
}
if (user) {
dispatch(getConfig()).catch(() => false);
dispatch(getEnrollSecret()).catch(() => false);
}
return false;
}
componentWillReceiveProps(nextProps) {
const { dispatch, user } = nextProps;
if (user && this.props.user !== user) {
dispatch(getConfig()).catch(() => false);
dispatch(getEnrollSecret()).catch(() => false);
}
}
render() {
const { children } = this.props;
const wrapperStyles = classnames("wrapper");
return <div className={wrapperStyles}>{children}</div>;
}
}
const mapStateToProps = (state) => {
const { app, auth } = state;
const { showBackgroundImage } = app;
const { user } = auth;
return {
showBackgroundImage,
user,
};
};
export default connect(mapStateToProps)(App);