import React from 'react'; import { ToastContainer, Toast } from 'react-bootstrap'; export type LevelName = 'CRITICAL' | 'ERROR' | 'WARNING' | 'INFO' | 'DEBUG'; export type Notification = { id: number; timeStamp: string; message: string; levelname: LevelName; }; type NotificationProps = { showNotification: boolean; notifications: Notification[]; removeNotificationById: (id: number) => void; }; export const Notifications = React.memo((props: NotificationProps) => { const { showNotification, notifications, removeNotificationById } = props; return ( {notifications.map((notification) => { // Determine if the toast should be shown const shouldShow = notification.levelname === 'ERROR' || notification.levelname === 'CRITICAL' || (showNotification && ['WARNING', 'INFO', 'DEBUG'].includes(notification.levelname)); if (!shouldShow) { return null; } return ( removeNotificationById(notification.id)} onClick={() => removeNotificationById(notification.id)} onMouseLeave={() => { if (notification.levelname !== 'ERROR') { removeNotificationById(notification.id); } }} show={true} autohide={ notification.levelname === 'WARNING' || notification.levelname === 'INFO' || notification.levelname === 'DEBUG' } delay={ notification.levelname === 'WARNING' || notification.levelname === 'INFO' || notification.levelname === 'DEBUG' ? 2000 : undefined }> {notification.levelname} {notification.timeStamp} {notification.message} ); })} ); });