|
| 1 | +# NotificationInbox Multi-Select Refactor |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The NotificationInbox component has been refactored to support multi-select functionality with bulk delete operations. Users can now select multiple notifications and delete them all at once with a confirmation modal. |
| 6 | + |
| 7 | +## Features Added |
| 8 | + |
| 9 | +### 1. Multi-Select Mode |
| 10 | +- **Long Press to Enter**: Long press any notification to enter selection mode |
| 11 | +- **Visual Indicators**: Selected notifications are highlighted with a blue background and checkmark icon |
| 12 | +- **Selection Counter**: Shows the count of selected notifications in the header |
| 13 | + |
| 14 | +### 2. Selection Controls |
| 15 | +- **Select All/Deselect All**: Toggle button to select or deselect all notifications at once |
| 16 | +- **Individual Toggle**: Tap notifications to toggle their selection state in selection mode |
| 17 | +- **Cancel**: Exit selection mode without performing any actions |
| 18 | + |
| 19 | +### 3. Bulk Delete |
| 20 | +- **Delete Button**: Trash icon button that's only enabled when notifications are selected |
| 21 | +- **Confirmation Modal**: Shows a confirmation dialog before deleting multiple notifications |
| 22 | +- **Batch Processing**: Iterates through selected notifications and calls the `deleteMessage` API for each |
| 23 | +- **Loading State**: Shows loading indicator while deletion is in progress |
| 24 | +- **Error Handling**: Displays appropriate toast messages for success/failure |
| 25 | + |
| 26 | +### 4. Enhanced UI/UX |
| 27 | +- **Responsive Header**: Changes layout based on normal vs selection mode |
| 28 | +- **Loading States**: Visual feedback during delete operations |
| 29 | +- **Toast Notifications**: Success/error messages for user feedback |
| 30 | +- **Clean State Management**: Resets selection state when component closes |
| 31 | + |
| 32 | +## Technical Implementation |
| 33 | + |
| 34 | +### New State Variables |
| 35 | +```typescript |
| 36 | +const [isSelectionMode, setIsSelectionMode] = useState(false); |
| 37 | +const [selectedNotificationIds, setSelectedNotificationIds] = useState<Set<string>>(new Set()); |
| 38 | +const [showDeleteConfirmModal, setShowDeleteConfirmModal] = useState(false); |
| 39 | +const [isDeletingSelected, setIsDeletingSelected] = useState(false); |
| 40 | +``` |
| 41 | + |
| 42 | +### Key Functions |
| 43 | +- `enterSelectionMode()`: Enters multi-select mode |
| 44 | +- `exitSelectionMode()`: Exits multi-select mode and clears selections |
| 45 | +- `toggleNotificationSelection(id)`: Toggles selection state of a notification |
| 46 | +- `selectAllNotifications()`: Selects all visible notifications |
| 47 | +- `deselectAllNotifications()`: Clears all selections |
| 48 | +- `handleBulkDelete()`: Shows confirmation modal for bulk delete |
| 49 | +- `confirmBulkDelete()`: Executes the bulk delete operation |
| 50 | + |
| 51 | +### Component Structure |
| 52 | + |
| 53 | +#### Header Modes |
| 54 | +1. **Normal Mode**: Shows "Notifications" title with close and menu buttons |
| 55 | +2. **Selection Mode**: Shows selection count with Select All, Delete, and Cancel buttons |
| 56 | + |
| 57 | +#### Notification Items |
| 58 | +- **Normal Mode**: Tap to view details, long press to enter selection |
| 59 | +- **Selection Mode**: Tap to toggle selection, shows checkmark/circle icons |
| 60 | + |
| 61 | +#### Confirmation Modal |
| 62 | +- Uses the existing `Modal` component from `@/components/ui/modal` |
| 63 | +- Displays count of notifications to be deleted |
| 64 | +- Provides Cancel and Delete buttons |
| 65 | + |
| 66 | +## Usage |
| 67 | + |
| 68 | +### Entering Selection Mode |
| 69 | +1. Long press any notification item |
| 70 | +2. Or tap the menu (three dots) button in the header (future enhancement) |
| 71 | + |
| 72 | +### Selecting Notifications |
| 73 | +1. In selection mode, tap individual notifications to toggle selection |
| 74 | +2. Use "Select All" to select all visible notifications |
| 75 | +3. Use "Deselect All" to clear all selections |
| 76 | + |
| 77 | +### Bulk Delete |
| 78 | +1. Select one or more notifications |
| 79 | +2. Tap the trash icon button |
| 80 | +3. Confirm deletion in the modal dialog |
| 81 | +4. Wait for completion and see success/error toast |
| 82 | + |
| 83 | +### Exiting Selection Mode |
| 84 | +1. Tap "Cancel" button |
| 85 | +2. Complete a bulk delete operation |
| 86 | +3. Close the notification inbox |
| 87 | + |
| 88 | +## API Integration |
| 89 | + |
| 90 | +The component uses the existing `deleteMessage` API function: |
| 91 | +```typescript |
| 92 | +import { deleteMessage } from '@/api/novu/inbox'; |
| 93 | +``` |
| 94 | + |
| 95 | +Each selected notification is deleted individually using Promise.all: |
| 96 | +```typescript |
| 97 | +const deletePromises = Array.from(selectedNotificationIds).map((id) => deleteMessage(id)); |
| 98 | +await Promise.all(deletePromises); |
| 99 | +``` |
| 100 | + |
| 101 | +## Error Handling |
| 102 | + |
| 103 | +- Network errors during deletion show error toast |
| 104 | +- Individual notification delete failures are handled gracefully |
| 105 | +- Loading states prevent multiple simultaneous operations |
| 106 | +- State is properly reset on errors |
| 107 | + |
| 108 | +## Accessibility |
| 109 | + |
| 110 | +- Visual indicators for selection state |
| 111 | +- Clear labeling of actions |
| 112 | +- Confirmation dialogs for destructive actions |
| 113 | +- Loading states for better user feedback |
| 114 | + |
| 115 | +## Testing |
| 116 | + |
| 117 | +Comprehensive test suite includes: |
| 118 | +- Component rendering in different states |
| 119 | +- Selection mode entry/exit |
| 120 | +- Multi-select functionality |
| 121 | +- Bulk delete operations |
| 122 | +- Error handling |
| 123 | +- State management |
| 124 | +- API integration |
| 125 | + |
| 126 | +Run tests with: |
| 127 | +```bash |
| 128 | +npm test -- --testPathPattern="NotificationInbox.test.tsx" |
| 129 | +``` |
| 130 | + |
| 131 | +## Styling |
| 132 | + |
| 133 | +New styles added: |
| 134 | +- `selectedNotificationItem`: Blue background for selected items |
| 135 | +- `selectionIndicator`: Spacing for checkmark/circle icons |
| 136 | +- `selectionHeader`: Layout for selection mode header |
| 137 | +- `selectionCount`: Styling for selection counter |
| 138 | +- `selectionActions`: Layout for selection mode buttons |
| 139 | +- `headerActions`: Layout for normal mode header buttons |
| 140 | +- `actionButton`: Styling for menu button |
| 141 | + |
| 142 | +## Dependencies |
| 143 | + |
| 144 | +- `lucide-react-native`: Added CheckCircle, Circle, MoreVertical, Trash2 icons |
| 145 | +- `@/components/ui/modal`: Used for confirmation dialog |
| 146 | +- Existing dependencies: Button, Text, animations, etc. |
| 147 | + |
| 148 | +## Future Enhancements |
| 149 | + |
| 150 | +1. **Keyboard Shortcuts**: Add keyboard support for desktop usage |
| 151 | +2. **Swipe Actions**: Swipe to delete individual notifications |
| 152 | +3. **Filtering**: Select notifications by type or status |
| 153 | +4. **Archive Functionality**: Bulk archive instead of delete |
| 154 | +5. **Undo Feature**: Allow undoing bulk deletions |
| 155 | +6. **Performance**: Virtual scrolling for large notification lists |
0 commit comments