import React, { useEffect } from 'react'; import { Button, NoContent } from 'UI'; import { connect } from 'react-redux'; import { fetchList, setViewed, clearAll } from 'Duck/notifications'; import { setLastRead } from 'Duck/announcements'; import cn from 'classnames'; import AnimatedSVG, { ICONS } from 'Shared/AnimatedSVG/AnimatedSVG'; import ListItem from './ListItem' import { useStore } from 'App/mstore'; import { useObserver } from 'mobx-react-lite'; interface Props { setLastRead: Function; clearingAll: boolean; loading: boolean; clearing: boolean; list: any; clearAll: Function; setViewed: Function; } function AlertTriggersModal(props: Props) { const { loading, clearingAll, clearing } = props; const { notificationStore } = useStore(); const count = useObserver(() => notificationStore.notificationsCount); const list = useObserver(() => notificationStore.notifications); const onClearAll = () => { const { list } = props; const firstItem = list.first(); props.clearAll({ endTimestamp: firstItem.createdAt.ts }); } const onClear = (notification: any) => { props.setViewed(notification.notificationId) } useEffect(() => { notificationStore.fetchNotifications(); }, []) return (
Alerts
{ count > 0 && (
)}
} subtext="There are no alerts to show." show={ !loading && count === 0 } size="small" > {list.map((item: any, i: any) => (
onClear(item)} loading={false} />
))}
); } export default connect((state: any) => ({ loading: state.getIn(['notifications', 'fetchRequest', 'loading']), clearing: state.getIn(['notifications', 'setViewed', 'loading']), clearingAll: state.getIn(['notifications', 'clearAll', 'loading']), list: state.getIn(['notifications', 'list']), }), { fetchList, setLastRead, setViewed, clearAll, })(AlertTriggersModal);