import React, { Component } from 'react' import PropTypes from 'prop-types' import onClickOutsideAddon from 'react-onclickoutside' import Notification from '../Notification' import Loading from '../Loading' class NotificationBox extends Component { static propTypes = { notifications: PropTypes.array, fetchNotifications: PropTypes.func.isRequired, toggleNotificationsBox: PropTypes.func.isRequired, markAsRead: PropTypes.func.isRequired, markAsUnread: PropTypes.func.isRequired } componentDidMount = () => { const { notifications, fetchNotifications } = this.props if (!notifications) { fetchNotifications() } } handleClickOutside = () => { this.props.toggleNotificationsBox() } hasSomeNotifications = () => { const { notifications } = this.props return notifications && notifications.length > 0 } showLoading = () => { return
  • } showEmpty = () => { return
  • You have no notifications.
    More time for dancing.
  • } showNotifications = () => { const { notifications, markAsRead, markAsUnread } = this.props if (!this.hasSomeNotifications()) { return this.showEmpty() } return notifications.slice(0, 10).map( n => ).concat([
  • See all
  • ]) } render = () => { const { notifications } = this.props return
      {notifications ? this.showNotifications() : this.showLoading()}
    } } export default onClickOutsideAddon(NotificationBox)