import {ComponentContext} from "../utils/ComponentContext"; import {observer} from "mobx-react"; import {Notification, NotificationType} from "../store/NotificationStore"; import {Card, CardBody, CardHeader, CardText, CardTitle} from "react-bootstrap"; import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; import {action, makeObservable} from "mobx"; @observer export class NotificationContainer extends ComponentContext { forEachNotificationRender(notifications: Notification[], type: NotificationType) { return notifications.map(notification => ( )); } render() { return
{this.forEachNotificationRender(this.notificationStore.errors, NotificationType.ERROR)} {this.forEachNotificationRender(this.notificationStore.successes, NotificationType.SUCCESS)} {this.forEachNotificationRender(this.notificationStore.warnings, NotificationType.WARNING)} {this.forEachNotificationRender(this.notificationStore.infos, NotificationType.INFO)}
} } @observer class NotificationPopup extends ComponentContext<{ notification: Notification, type: NotificationType }> { constructor(props: { notification: Notification, type: NotificationType }) { super(props); makeObservable(this); } @action.bound close() { this.notificationStore.close(this.props.notification.uuid); } get cardClassName() { switch (this.props.type) { case NotificationType.ERROR: return 'text-bg-danger'; case NotificationType.WARNING: return 'text-bg-warning'; case NotificationType.INFO: return 'text-bg-info'; case NotificationType.SUCCESS: return 'text-bg-success'; } } render() { const hasTitle = !!this.props.notification.title && this.props.notification.title.length > 0; const title = this.props.notification.title?.split('\n').map((item, key) => {item}
); const message = this.props.notification.message?.split('\n').map((item, key) => {item}
); const closeIcon = ; return { hasTitle && {title} {closeIcon} } {message ?? ''} { !hasTitle && closeIcon } } }