import React, { Component } from 'react'; import classnames from 'classnames'; import { notificationsTypes } from 'features/notifications'; import TransactionSucceeded from 'components/ExtendedNotifications/TransactionSucceeded'; import './Notifications.scss'; interface Props { notification: notificationsTypes.Notification; onClose(n: notificationsTypes.Notification): void; } export default class NotificationRow extends Component { public render() { const { msg, level, rendersComponent, componentConfig } = this.props.notification; const notifClass = classnames({ Notification: true, alert: true, [`alert-${level}`]: !!level }); let internal: any; if (!rendersComponent) { internal = msg; } else if (rendersComponent && componentConfig) { const customComponents: any = { TransactionSucceeded }; const { component, ...rest } = componentConfig; if (customComponents[component]) { const CustomComponent = customComponents[component]; internal = ; } else { const BasicComponent = component; internal = {msg}; } } else { throw new Error('If a notification renders a component is must contain config'); } return (
{level}
{internal}
); } public onClose = () => { this.props.onClose(this.props.notification); }; }