import React from 'react'
import { connect, MapStateToProps } from 'react-redux'
import { AppState } from 'reducers'
import { Notification } from 'reducers/notifications'
import Flash from 'components/Flash'
import Unhandled from 'components/Notifications/UnhandledError'
export function renderNotification(notification: Notification) {
if (typeof notification === 'string') {
return notification
} else if (notification.component) {
return notification.component(notification.props)
}
return
}
export function render(notification: Notification, idx: number) {
let n
if (typeof notification === 'string') {
n = notification
} else if (notification.component) {
n = notification.component(notification.props)
} else {
n =
}
return
{n}
}
interface NotificationProps {
notifications: Notification[]
}
const Error: React.FC = ({ notifications }) => {
return {notifications.map(render)}
}
const Success: React.FC = ({ notifications }) => {
return {notifications.map(render)}
}
/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
interface OwnProps {}
interface StateProps {
errors: Notification[]
successes: Notification[]
}
interface Props extends OwnProps, StateProps {}
export const Notifications: React.FC = ({ errors, successes }) => {
return (
{errors.length > 0 && }
{successes.length > 0 && }
)
}
const mapStateToProps: MapStateToProps = (
state,
) => {
return {
errors: state.notifications.errors,
successes: state.notifications.successes,
}
}
export const ConnectedNotifications = connect(mapStateToProps)(Notifications)
export default ConnectedNotifications