handle email axtion email in websocket

This commit is contained in:
hamid zarghami
2025-08-04 16:06:50 +03:30
parent 52508741ab
commit bec4c2c1d1
2 changed files with 11 additions and 2 deletions
+9 -1
View File
@@ -1,6 +1,6 @@
import React, { useState, useCallback, useEffect } from 'react'; import React, { useState, useCallback, useEffect } from 'react';
import { useEmailWebSocket } from '@/hooks/useEmailWebSocket'; import { useEmailWebSocket } from '@/hooks/useEmailWebSocket';
import { useEmailEvents, EmailPayload, UnreadCountPayload } from '@/hooks/useEmailEvents'; import { useEmailEvents, EmailPayload, UnreadCountPayload, EmailStatusPayload } from '@/hooks/useEmailEvents';
import { useNotificationSound } from '@/hooks/useNotificationSound'; import { useNotificationSound } from '@/hooks/useNotificationSound';
import { Notification as NotificationIcon, VolumeHigh } from 'iconsax-react'; import { Notification as NotificationIcon, VolumeHigh } from 'iconsax-react';
@@ -74,10 +74,18 @@ export const EmailNotifications: React.FC<EmailNotificationsProps> = ({
); );
}, []); }, []);
const handleEmailSent = useCallback((data: EmailStatusPayload) => {
// Remove from notifications if it was there
setNotifications(prev =>
prev.filter(notification => notification.messageId !== data.messageId)
);
}, []);
useEmailEvents(socket, { useEmailEvents(socket, {
onNewEmail: handleNewEmail, onNewEmail: handleNewEmail,
onUnreadCountUpdated: handleUnreadCountUpdate, onUnreadCountUpdated: handleUnreadCountUpdate,
onEmailRead: handleEmailRead, onEmailRead: handleEmailRead,
onEmailSent: handleEmailSent,
}); });
// Request notification permission on mount // Request notification permission on mount
+2 -1
View File
@@ -22,13 +22,14 @@ const SocketManagment: FC = () => {
const handleEmailActionEvent = useCallback(() => { const handleEmailActionEvent = useCallback(() => {
queryClient.invalidateQueries({ queryKey: ['mailbox-count'] }); queryClient.invalidateQueries({ queryKey: ['mailbox-count'] });
queryClient.invalidateQueries({ queryKey: ['inbox'] }); queryClient.invalidateQueries({ queryKey: ['inbox'] });
queryClient.invalidateQueries({ queryKey: ['drafts'] });
}, []); }, []);
useEmailEvents(socket, { useEmailEvents(socket, {
onNewEmail: handleNewEmailEvent, onNewEmail: handleNewEmailEvent,
onEmailRead: handleEmailActionEvent, onEmailRead: handleEmailActionEvent,
onEmailDeleted: handleEmailActionEvent, onEmailDeleted: handleEmailActionEvent,
// onMailboxUpdated: handleEmailActionEvent, onEmailSent: handleEmailActionEvent,
}); });
return null return null