handle email axtion email in websocket
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user