gab-social/app/javascript/gabsocial/containers/notifications_container.js

29 lines
743 B
JavaScript
Raw Normal View History

2020-02-24 21:56:07 +00:00
import { injectIntl } from 'react-intl'
import { NotificationStack } from 'react-notification'
import { dismissAlert } from '../actions/alerts'
import { getAlerts } from '../selectors'
2019-07-02 08:10:25 +01:00
const mapStateToProps = (state, { intl }) => {
2020-02-24 21:56:07 +00:00
const notifications = getAlerts(state)
2019-07-02 08:10:25 +01:00
notifications.forEach(notification => ['title', 'message'].forEach(key => {
2020-02-24 21:56:07 +00:00
const value = notification[key]
2019-07-02 08:10:25 +01:00
if (typeof value === 'object') {
2020-02-24 21:56:07 +00:00
notification[key] = intl.formatMessage(value)
2019-07-02 08:10:25 +01:00
}
2020-02-24 21:56:07 +00:00
}))
2019-07-02 08:10:25 +01:00
2020-02-24 21:56:07 +00:00
return { notifications }
}
2019-07-02 08:10:25 +01:00
const mapDispatchToProps = (dispatch) => {
return {
onDismiss: alert => {
2020-02-24 21:56:07 +00:00
dispatch(dismissAlert(alert))
2019-07-02 08:10:25 +01:00
},
2020-02-24 21:56:07 +00:00
}
}
2019-07-02 08:10:25 +01:00
2020-02-24 21:56:07 +00:00
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(NotificationStack))