Notification Badges
==================
Overview
--------
The LUStores application displays dynamic notification badges in the top navigation bar to alert users about important system events and inventory conditions. These badges provide real-time feedback and help users stay informed about critical system status. Clicking on the badges provides quick navigation to relevant pages for taking action on the alerts.
Notification Types
------------------
System Monitoring Alerts (Server Icon)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Purpose**: Displays real-time system health and operational alerts
- **Visual Indicator**: Server icon with red badge when alerts are present
- **Navigation**: Click to go to System Management page (``/system``)
- **Update Frequency**: Refreshes every 30 seconds automatically
- **Badge Display Logic**:
- Shows red badge only when ``hasSystemAlerts: true``
- Displays count from API ``alertCount`` field
- Shows "99+" for counts over 99
- Tooltip shows detailed alert messages and navigation hint
**API Endpoint**: ``/api/system/alerts``
Low Stock Notifications (Bell Icon)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Purpose**: Alerts users when inventory items are running low on stock
- **Visual Indicator**: Bell icon with red badge when low stock items exist
- **Navigation**: Click to go to Inventory page (``/inventory``)
- **Badge Display Logic**:
- Shows red badge when low stock items are detected
- Displays count of items below minimum threshold
- Shows "99+" for counts over 99
- Tooltip shows "X low stock items" and navigation hint
**API Endpoint**: ``/api/dashboard/low-stock``
User Interface Details
----------------------
Badge Styling
~~~~~~~~~~~~~
Both notification badges use consistent styling:
- **Color**: Red background (``bg-red-600`` for system alerts, ``bg-error`` for low stock)
- **Position**: Positioned absolutely in top-right corner of respective icons
- **Size**: Small circular badge (``h-5 w-5``)
- **Text**: White text, extra small font size
- **Behavior**: Only visible when relevant conditions are met
Interactive Features
~~~~~~~~~~~~~~~~~~~
- **Hover Tooltips**: Both badges show detailed information on hover
- **Click Navigation**:
- **Server Icon**: Clicking navigates to System Management page (``/system``)
- **Bell Icon**: Clicking navigates to Inventory page (``/inventory``)
- **Real-time Updates**: System alerts refresh automatically every 30 seconds
- **Responsive Design**: Badges scale appropriately on different screen sizes
Historical Issues and Solutions
-------------------------------
Hard-coded Badge Number (Resolved)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Issue**: Previously, a hard-coded notification badge displaying the number "3" appeared due to a legacy backup file.
**Root Cause**: The file ``TopBar.jsx.backup`` contained hardcoded JSX:
.. code-block:: jsx
3
**Resolution**:
- **Date Fixed**: July 10, 2025
- **Action**: Removed the backup file containing the hard-coded value
- **Current Status**: All notification badges now use dynamic data from API endpoints
Technical Implementation
------------------------
The notification system is implemented in ``/client/src/components/TopBar.tsx`` using React Query for data fetching and Wouter for navigation:
.. code-block:: tsx
// Import navigation hook
const [location, setLocation] = useLocation();
// System alerts from API
const { data: systemAlerts } = useQuery<{
alertCount: number;
alerts: Array<{ type: string; level: string; message: string }>;
hasSystemAlerts: boolean;
}>({
queryKey: ["/api/system/alerts"],
refetchInterval: 30000, // 30 seconds
});
// Low stock items from API
const { data: lowStockItems } = useQuery({
queryKey: ["/api/dashboard/low-stock"],
});
// Navigation handlers