Logo

Notifications

User notification system with broadcast messaging and read/archive status

Overview

The Notifications feature provides a comprehensive user notification system supporting both individual notifications and broadcast messages. It includes read/unread tracking, archiving, batch operations, search functionality, and admin controls for composing and sending notifications to users.

Key Features

Notification Management

  • User Notifications: Individual notifications for specific users
  • Broadcast Messaging: Send notifications to multiple users
  • Read/Unread Tracking: Track which notifications users have read
  • Archive System: Archive old or completed notifications
  • Action URLs: Link notifications to specific pages or actions

Notification States

  • Unread: New notifications that haven't been read (readAt: null)
  • Read: Notifications that have been viewed (readAt: DateTime)
  • Archived: Notifications moved to archive (archived: true)
  • Active: Non-archived notifications (archived: false)

User Interface

  • Tab Navigation: Switch between Unread, All, and Archived views
  • Batch Operations: Select multiple notifications for bulk actions
  • Mark as Read: Single or batch mark as read
  • Archive/Unarchive: Move notifications between active and archived
  • Search: Full-text search across notification content
  • Pagination: Handle large numbers of notifications efficiently

Admin Features

  • Compose Interface: Create and send notifications
  • Broadcast Messaging: Send to multiple users simultaneously
  • Admin-Only Access: Notification creation restricted to admin users
  • Delivery Tracking: See which users received notifications

Database Models

Notification Model

model Notification {
  id              String    @id @default(cuid())
  createdAt       DateTime  @default(now())
  updatedAt       DateTime  @updatedAt
  tenantId        String
  tenant          Tenant    @relation(fields: [tenantId], references: [id])
  userId          String
  user            User      @relation(fields: [userId], references: [id])
  createdByUserId String?
  createdByUser   User?     @relation("createdByUser", fields: [createdByUserId], references: [id])
  title           String
  message         String    @db.NVarChar(max)
  type            String    @default("info")  // info, success, warning, error
  actionUrl       String?
  actionText      String?
  readAt          DateTime?
  archived        Boolean   @default(false)
}

Routes

User Routes

  • /app/{tenant}/notifications - View notifications inbox

Features:

  • Tabs for Unread, All, and Archived
  • Batch selection and operations
  • Mark as read functionality
  • Archive/unarchive actions
  • Delete notifications
  • Search functionality
  • Pagination support

Admin Routes

  • /app/{tenant}/settings/notifications?add=true - Compose new notification

Admin compose features:

  • Send to specific users
  • Broadcast to multiple users
  • Set notification type (info, success, warning, error)
  • Add action URL and action text
  • Preview before sending

Notification Types

Type Indicators

Notifications can be categorized by type for visual distinction:

  • info: Informational notifications (default)
  • success: Success or completion messages
  • warning: Warning or attention-required messages
  • error: Error or critical notifications

Type determines visual styling (color, icon) in the UI.

Notification Operations

Creating Notifications

await createNotification({
  tenantId,
  userId,
  title,
  message,
  type: "info",
  actionUrl: "/app/tenant/some-page",
  actionText: "View Details",
  createdByUserId,
});

Marking as Read

await markNotificationAsRead(notificationId);

Updates readAt to current timestamp.

Archiving

await archiveNotification(notificationId);

Sets archived: true to move notification to archived tab.

Unarchiving

await unarchiveNotification(notificationId);

Sets archived: false to restore notification to active inbox.

Deleting

await deleteNotification(notificationId);

Permanently removes notification from database.

User Interface Tabs

Unread Tab

Shows notifications where:

  • readAt is null
  • archived is false

Default tab when user visits notifications page.

All Tab

Shows all notifications where:

  • archived is false

Includes both read and unread notifications.

Archived Tab

Shows notifications where:

  • archived is true

Includes notifications user has archived for later reference.

Batch Operations

Batch Mark as Read

  1. Select multiple unread notifications
  2. Click "Mark as Read" button
  3. All selected unread notifications updated
  4. Selection cleared automatically

Implementation:

const handleBatchMarkAsRead = () => {
  selectedIds.forEach((id) => {
    const item = data.items.find((n) => n.id === id);
    if (item && !item.readAt) {
      onMarkAsRead(id);
    }
  });
  setSelectedIds([]);
};

Batch Archive

  1. Select multiple active notifications
  2. Click "Archive" button
  3. All selected notifications archived
  4. Selection cleared automatically

Search Functionality

Search across:

  • Notification title
  • Notification message
  • Notification type
  • Action text
  • Creation date

Search is URL-based with ?q= parameter for deep linking.

Pagination

Notifications support pagination for performance:

const { items, pagination } = await getNotificationsWithPagination({
  tenantId,
  userId,
  pagination: { page, pageSize },
  filters: {
    read: unreadTab ? false : undefined,
    archived: archivedTab ? true : false,
    search,
  },
});

Pagination data includes:

  • Current page
  • Page size
  • Total items
  • Total pages

Notification Delivery

Broadcast Notifications

Admin users can broadcast to multiple users:

  1. Compose notification in admin interface
  2. Select multiple user recipients
  3. Set title, message, type, and action details
  4. Click "Send"
  5. Individual notification created for each recipient

Individual Notifications

Send notification to specific user:

  • Target single user by userId
  • Notification appears in user's inbox
  • User receives in-app notification

Access Control

Permission Requirements

  • View Notifications: All authenticated users
  • Create Notifications: Admin users only (canCreate flag)
  • Compose Interface: Admin route with ?add=true parameter
  • Batch Operations: Available to all users for their own notifications

Notification Filtering

Users only see notifications where:

  • tenantId matches their tenant
  • userId matches their user ID
  • Tenant isolation enforced at database level

Best Practices

  1. Clear Titles: Use concise, descriptive notification titles
  2. Action URLs: Provide actionable links when relevant
  3. Type Selection: Choose appropriate notification type for context
  4. Read Management: Encourage users to mark notifications as read
  5. Archive Strategy: Archive old or completed notifications
  6. Search Usage: Use search to find specific notifications
  7. Batch Operations: Use batch operations for managing multiple notifications
  8. Admin Compose: Use admin interface for broadcast announcements

Common Operations

View Unread Notifications

  1. Navigate to /app/{tenant}/notifications
  2. Default view shows unread notifications
  3. Click on notification to mark as read (optional)
  4. Click action link if provided

Mark Notification as Read

  1. View notification in list
  2. Click "Mark as Read" button or link
  3. Notification moves to read state
  4. readAt timestamp recorded

Archive Notifications

  1. Select notification(s) from active inbox
  2. Click "Archive" button
  3. Notifications move to Archived tab
  4. Can be unarchived later if needed

Search Notifications

  1. Enter search term in search box
  2. URL updates with ?q=search-term
  3. Results filter to matching notifications
  4. Clear search to show all notifications

Compose and Send (Admin)

  1. Navigate to /app/{tenant}/settings/notifications?add=true
  2. Enter notification details:
    • Title
    • Message
    • Type (info, success, warning, error)
    • Action URL and text (optional)
  3. Select recipient users
  4. Click "Send" or "Compose"
  5. Notifications delivered to selected users

Delete Notification

  1. Click dropdown menu on notification
  2. Select "Delete"
  3. Confirm deletion in dialog
  4. Notification permanently removed

Integration Points

  • Users: Recipient and creator tracking
  • Tenants: Multi-tenant isolation for notifications
  • Permissions: Admin-only notification creation
  • URLs: Deep linking to relevant pages via actionUrl
  • Batch Actions: Multi-select for bulk operations
  • Search: Full-text search across notification content
  • Pagination: Efficient handling of large notification volumes

Notification Workflows

Onboarding Flow

  1. Admin sends welcome notification to new users
  2. Notification includes action link to onboarding guide
  3. User clicks notification and reads guide
  4. User marks notification as read
  5. Notification archived after completion

Alert Flow

  1. System detects important event
  2. Admin sends warning notification to affected users
  3. Users receive immediate notification
  4. Action URL links to resolution page
  5. Users mark as read after addressing

Announcement Flow

  1. Admin composes broadcast notification
  2. Sends to all users or specific department
  3. Users see notification in inbox
  4. Action URL links to announcement details
  5. Users can archive after reading

Troubleshooting

Notifications Not Appearing

  • Verify user is authenticated
  • Check tenantId matches user's tenant
  • Confirm userId matches recipient
  • Check notification is not archived by default

Can't Mark as Read

  • Verify notification belongs to current user
  • Check notification ID is valid
  • Ensure user has permission to modify notification

Search Not Working

  • Verify search parameter in URL (?q=)
  • Check search is applied to correct fields
  • Clear search to reset filters

Pagination Issues

  • Verify page and pageSize parameters
  • Check total items count
  • Ensure pagination component receives correct data

We respect your privacy.

TLDR: We use cookies for language selection, theme, and analytics. Learn more.