import React from 'react'
export default class Notification extends React.Component {
constructor (props) {
super()
this.state = {
isExtended: false
}
}
toggleDetails () {
this.setState({ isExtended: !this.state.isExtended })
}
renderItems (items) {
if (!items) return ''
return (
{items.map((item) => {
if (item.error) {
return (
{item.error.message}
)
}
return ''
})}
)
}
renderNotificationContent (notification) {
let { type, message, items } = notification
return (
{message}
{(items !== null) ? this.renderItems(items) : ''}
)
}
render () {
if (!this.props.notifications) return null
const notificationsToRender = this.props.notifications.filter(n => !('isRead' in n && n.isRead))
if (notificationsToRender.length > 0) {
return (
{this.props.notifications.map((notification) => {
return (
this.toggleDetails()}>
{this.renderNotificationContent(notification)}
)
})
}
)
}
return ()
}
}