/* @flow */ 'use strict'; import React from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import * as NOTIFICATION from '~/js/actions/constants/notification'; import * as NotificationActions from '~/js/actions/NotificationActions'; import type { Action, State, Dispatch } from '~/flowtype'; type Props = { notifications: $ElementType, close: (notif?: any) => Action } type NProps = { key?: number; className: string; cancelable?: boolean; title: string; message?: string; actions?: Array; close?: typeof NotificationActions.close } export const Notification = (props: NProps): React$Element => { const className = `notification ${ props.className }`; const close: Function = typeof props.close === 'function' ? props.close : () => {}; // TODO: add default close action const actionButtons = props.actions ? props.actions.map((a, i) => { return ( ) }) : null; return (
{ props.cancelable ? ( ) : null }

{ props.title }

{ props.message ? (

) : null }
{ props.actions && props.actions.length > 0 ? (
{ actionButtons }
) : null }
) } export const NotificationGroup = (props: Props) => { const { notifications, close } = props; return notifications.map((n, i) => { return ( ) }); } export default connect( (state: State) => { return { notifications: state.notifications }; }, (dispatch: Dispatch) => { return { close: bindActionCreators(NotificationActions.close, dispatch), }; } )(NotificationGroup);