The notification system provides real-time alerts for important events in the Ai Studio application. Notifications are categorized by type (order, reservation, general) and stored locally with read/unread status tracking.
ID of the related entity (order ID, reservation ID, etc.)Used to prevent duplicate notifications and link to source data.Example: "ORD-1709654321-abc123"
All notification operations persist to localStorage:
notificationService.ts
const persistNotifications = (notifications: Notification[]): void => { try { localStorage.setItem(NOTIFICATIONS_STORAGE_KEY, JSON.stringify(notifications)); } catch (error) { console.error("Failed to save notifications to localStorage", error); }};
Notifications are stored locally and will be cleared if the user clears browser data. Consider implementing server-side storage for critical notifications.
Craft notification messages that provide clear, actionable information:
// GoodaddNotification({ message: 'Order #1234 from Table 5 is ready to serve', type: 'order', relatedId: orderId});// AvoidaddNotification({ message: 'Order ready', type: 'order'});
Always Provide relatedId for Orders and Reservations
This enables duplicate prevention and linking:
addNotification({ message: `Reservation confirmed for ${name}`, type: 'reservation', relatedId: reservation.id // Always include for tracking});
Implement Notification Sound/Visual Alerts
Enhance user experience with audio or visual cues:
function notifyWithSound(notificationData) { const notification = addNotification(notificationData); if (notification && notification.type === 'order') { // Play sound for important notifications const audio = new Audio('/notification-sound.mp3'); audio.play(); } return notification;}
Regularly Clean Old Notifications
While the system limits to 50 notifications, implement custom cleanup:
function cleanupOldNotifications(daysToKeep: number = 7) { const notifications = getNotifications(); const cutoffDate = new Date(); cutoffDate.setDate(cutoffDate.getDate() - daysToKeep); const recentNotifications = notifications.filter(n => new Date(n.createdAt) > cutoffDate ); // Save filtered list localStorage.setItem('pizzeria-notifications', JSON.stringify(recentNotifications));}
The notification service includes built-in error handling:
// Safe retrieval with fallbackconst notifications = getNotifications(); // Returns [] on error// Check for null on add (duplicate prevention)const notification = addNotification({ ... });if (!notification) { console.log('Notification was not created (duplicate)');}
All localStorage operations are wrapped in try-catch blocks to prevent crashes from quota exceeded or other storage errors.