import React, { useState, useEffect } from 'react' import { connect } from 'react-redux' import { deleteNotification, getUserNotifications } from '../../stores/exchange/duck/operations' import '../../styles/indexExchange.scss' const ExchangeNotifications = ({ user, exchange, deleteNotification, getUserNotifications }) => { useEffect( () => { getUserNotifications(user.id) }, [] ) const deleteOldNotification = (notifyID) => { let notify = { id: notifyID, token: user.token } deleteNotification(notify) } return (

{ user.login } exchange notifications:

{ exchange.userNotifications .sort( (a, b) => b.id - a.id ) .map( (notify, key) => { return (

{ key + 1 }. { notify.message }

) } ) }
) } const mapStateToProps = state => ({ user: state.user, exchange: state.exchange }) const mapDispatchToProps = dispatch => ({ getUserNotifications: exchange => dispatch( getUserNotifications(exchange) ), deleteNotification: exchange => dispatch( deleteNotification(exchange) ) }) export default connect(mapStateToProps,mapDispatchToProps)(ExchangeNotifications)