import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import uuid from 'uuidv4'; import { connect as connectWS, disconnect as disconnectWS, send, } from '@giantmachines/redux-websocket'; import { Badge, Main, MainBody, Gradient, Sidebar, Navigation, NavigationSection, NavigationItem, NavigationGroup, Profilebar, Icon, } from '@kerberos-io/ui'; import { interval } from 'rxjs'; import { connect } from 'react-redux'; import { Link } from 'react-router-dom'; import { logout } from './actions'; import config from './config'; import { getDashboardInformation } from './actions/agent'; import LanguageSelect from './components/LanguageSelect/LanguageSelect'; import logo from './header-minimal-logo-36x36.svg'; import '@kerberos-io/ui/lib/index.css'; import './App.scss'; // eslint-disable-next-line react/prefer-stateless-function class App extends React.Component { componentDidMount() { const { dispatchGetDashboardInformation, dispatchConnect } = this.props; dispatchGetDashboardInformation(); dispatchConnect(); const interval$ = interval(5000); this.subscription = interval$.subscribe(() => { dispatchGetDashboardInformation(); }); } componentDidUpdate(prevProps) { // We are connected again, lets fire the initial events. const { connected, dispatchSend, dispatchConnect } = this.props; const { connected: connectedPrev } = prevProps; if (connectedPrev === false && connected === true) { const message = { client_id: uuid(), message_type: 'hello', }; dispatchSend(message); } // We disconnected, let's try to connect again if (connectedPrev === true && connected === false) { dispatchConnect(); } } componentWillUnmount() { this.subscription.unsubscribe(); const message = { client_id: uuid(), message_type: 'goodbye', }; const { dispatchSend, dispatchDisconnect } = this.props; dispatchSend(message); dispatchDisconnect(); } getCurrentTimestamp() { return Math.round(Date.now() / 1000); } render() { const { t, connected } = this.props; const { children, username, dashboard, dispatchLogout } = this.props; const cloudOnline = this.getCurrentTimestamp() - dashboard.cloudOnline < 30; return (