From 4746470aee038f22c1c441f737e8c520618126d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Mon, 27 Nov 2023 16:08:49 +0100 Subject: [PATCH] error toasts always show even when showNotifications is false --- .../src/components/NotificationsComponent.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/NotificationsComponent.tsx b/frontend/src/components/NotificationsComponent.tsx index 5c4defb..e756fc4 100644 --- a/frontend/src/components/NotificationsComponent.tsx +++ b/frontend/src/components/NotificationsComponent.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { ToastContainer, Toast } from 'react-bootstrap'; -export type LevelName = 'ERROR' | 'WARNING' | 'INFO' | 'DEBUG'; // Added levelname +export type LevelName = 'ERROR' | 'WARNING' | 'INFO' | 'DEBUG'; export type Notification = { id: number; timeStamp: string; @@ -20,8 +20,18 @@ export const Notifications = React.memo((props: NotificationProps) => { return ( - {showNotification && - notifications.map((notification) => ( + {notifications.map((notification) => { + // Determine if the toast should be shown + const shouldShow = + notification.levelname === 'ERROR' || + (showNotification && + ['WARNING', 'INFO', 'DEBUG'].includes(notification.levelname)); + + if (!shouldShow) { + return null; + } + + return ( { {notification.message} - ))} + ); + })} ); });