import React, { useEffect, useState } from 'react'; import { connect } from 'react-redux'; import { NavLink, withRouter } from 'react-router-dom'; import cn from 'classnames'; import { sessions, client, errors, dashboard, withSiteId, CLIENT_DEFAULT_TAB, isRoute, } from 'App/routes'; import { logout } from 'Duck/user'; import { Icon, Popup } from 'UI'; import SiteDropdown from './SiteDropdown'; import styles from './header.css'; import Discover from './Discover/Discover'; import OnboardingExplore from './OnboardingExplore/OnboardingExplore' import Announcements from '../Announcements'; import Notifications from '../Alerts/Notifications'; import { init as initSite, fetchList as fetchSiteList } from 'Duck/site'; import ErrorGenPanel from 'App/dev/components'; import ErrorsBadge from 'Shared/ErrorsBadge'; import Alerts from '../Alerts/Alerts'; const DASHBOARD_PATH = dashboard(); const SESSIONS_PATH = sessions(); const ERRORS_PATH = errors(); const CLIENT_PATH = client(CLIENT_DEFAULT_TAB); const AUTOREFRESH_INTERVAL = 30 * 1000; let interval = null; const Header = (props) => { const { sites, location, account, onLogoutClick, siteId, boardingCompletion = 100, fetchSiteList, showAlerts = false } = props; const name = account.get('name').split(" ")[0]; const [hideDiscover, setHideDiscover] = useState(false) let activeSite = null; useEffect(() => { activeSite = sites.find(s => s.id == siteId); props.initSite(activeSite); }, [sites]) const showTrackingModal = ( isRoute(SESSIONS_PATH, location.pathname) || isRoute(ERRORS_PATH, location.pathname) ) && activeSite && !activeSite.recorded; useEffect(() => { if(showTrackingModal) { interval = setInterval(() => { fetchSiteList() }, AUTOREFRESH_INTERVAL); } else if (interval){ clearInterval(interval); } }, [showTrackingModal]) useEffect(() => { fetchSiteList() }, []) return (
v{window.ENV.VERSION}
{ 'Sessions' } { 'Errors' } { 'Metrics' }
{ (boardingCompletion < 100 && !hideDiscover) && ( setHideDiscover(true)} />
)}
} content={ `Preferences` } size="tiny" inverted position="top center" />
{ name }
{ } {showAlerts && }
); }; export default withRouter(connect( state => ({ account: state.getIn([ 'user', 'account' ]), appearance: state.getIn([ 'user', 'account', 'appearance' ]), siteId: state.getIn([ 'user', 'siteId' ]), sites: state.getIn([ 'site', 'list' ]), showAlerts: state.getIn([ 'dashboard', 'showAlerts' ]), boardingCompletion: state.getIn([ 'dashboard', 'boardingCompletion' ]) }), { onLogoutClick: logout, initSite, fetchSiteList }, )(Header));