import React from 'react'; import stl from './announcements.css'; import ListItem from './ListItem'; import { connect } from 'react-redux'; import { SlideModal, Icon, NoContent, Popup } from 'UI'; import { fetchList, setLastRead } from 'Duck/announcements'; import withToggle from 'Components/hocs/withToggle'; import { withRouter } from 'react-router-dom'; @withToggle('visible', 'toggleVisisble') @withRouter class Announcements extends React.Component { constructor(props) { super(props); props.fetchList(); } navigateToUrl = url => { if (url) { if (url.startsWith(window.ENV.ORIGIN)) { const { history } = this.props; var path = new URL(url).pathname if (path.includes('/metrics')) { const { siteId, sites } = this.props; const activeSite = sites.find(s => s.id == siteId); history.push(`/${activeSite.id + path}`); } else { history.push(path) } } else { window.open(url, "_blank") } this.toggleModal() } } toggleModal = () => { if (!this.props.visible) { const { setLastRead, fetchList } = this.props; fetchList().then(() => { setTimeout(() => { setLastRead() }, 5000); }); } this.props.toggleVisisble(!this.props.visible); } render() { const { announcements, visible, loading } = this.props; const unReadNotificationsCount = announcements.filter(({viewed}) => !viewed).size return (