feat: implement bulk mute/unmute functionality for all conversations in MessagingPage
This commit is contained in:
@@ -153,7 +153,6 @@ export function MessagingPage({ initialConversationId, initialAgentProfileId }:
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [isPageMenuOpen, setIsPageMenuOpen] = useState(false);
|
||||
const [isAllMuted, setIsAllMuted] = useState(false);
|
||||
const [confirmDeleteId, setConfirmDeleteId] = useState<string | null>(null);
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [showScrollButton, setShowScrollButton] = useState(false);
|
||||
@@ -488,6 +487,13 @@ export function MessagingPage({ initialConversationId, initialAgentProfileId }:
|
||||
setConfirmDeleteId(null);
|
||||
}, [confirmDeleteId, deleteConversation]);
|
||||
|
||||
// True only when every conversation is currently muted for this user's role.
|
||||
const isAllMuted =
|
||||
conversations.length > 0 &&
|
||||
conversations.every((c) =>
|
||||
userRole === 'AGENT' ? c.agentMuted : c.userMuted,
|
||||
);
|
||||
|
||||
// Page header menu items
|
||||
const pageMenuItems: DropdownMenuItem[] = [
|
||||
{
|
||||
@@ -498,7 +504,21 @@ export function MessagingPage({ initialConversationId, initialAgentProfileId }:
|
||||
},
|
||||
{
|
||||
label: isAllMuted ? 'Unmute All Notifications' : 'Mute All Notifications',
|
||||
onClick: () => setIsAllMuted((prev) => !prev),
|
||||
onClick: async () => {
|
||||
const targetMuted = !isAllMuted;
|
||||
// Flip every conversation whose current mute state doesn't match the target
|
||||
const tasks = conversations
|
||||
.filter((c) => {
|
||||
const current = userRole === 'AGENT' ? c.agentMuted : c.userMuted;
|
||||
return !!current !== targetMuted;
|
||||
})
|
||||
.map((c) => toggleMute(c.id, targetMuted));
|
||||
try {
|
||||
await Promise.all(tasks);
|
||||
} catch (err) {
|
||||
console.error('Failed to toggle mute on all conversations:', err);
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user