diff --git a/crm/fcrm/doctype/crm_notification/crm_notification.py b/crm/fcrm/doctype/crm_notification/crm_notification.py index 9470101f..28f4ab80 100644 --- a/crm/fcrm/doctype/crm_notification/crm_notification.py +++ b/crm/fcrm/doctype/crm_notification/crm_notification.py @@ -1,9 +1,10 @@ # Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -# import frappe +import frappe from frappe.model.document import Document class CRMNotification(Document): - pass + def on_update(self): + frappe.publish_realtime("crm_notification") diff --git a/frontend/src/components/Notifications.vue b/frontend/src/components/Notifications.vue index 2781d1ec..1d2f6f09 100644 --- a/frontend/src/components/Notifications.vue +++ b/frontend/src/components/Notifications.vue @@ -98,10 +98,13 @@ import MarkAsDoneIcon from '@/components/Icons/MarkAsDoneIcon.vue' import NotificationsIcon from '@/components/Icons/NotificationsIcon.vue' import UserAvatar from '@/components/UserAvatar.vue' import { notificationsStore } from '@/stores/notifications' +import { globalStore } from '@/stores/global' import { timeAgo } from '@/utils' import { onClickOutside } from '@vueuse/core' import { Tooltip } from 'frappe-ui' -import { ref } from 'vue' +import { ref, onMounted, onBeforeUnmount } from 'vue' + +const { $socket } = globalStore() const target = ref(null) onClickOutside( @@ -124,6 +127,16 @@ function mark_as_read(doc) { notificationsStore().mark_doc_as_read(doc) } +onBeforeUnmount(() => { + $socket.off('crm_notification') +}) + +onMounted(() => { + $socket.on('crm_notification', () => { + notificationsStore().notifications.reload() + }) +}) + function getRoute(notification) { let params = { leadId: notification.reference_name, @@ -139,4 +152,6 @@ function getRoute(notification) { hash: '#' + notification.comment || notification.notification_type_doc, } } + +onMounted(() => {}) diff --git a/frontend/src/stores/notifications.js b/frontend/src/stores/notifications.js index dc6eee6e..0f24839d 100644 --- a/frontend/src/stores/notifications.js +++ b/frontend/src/stores/notifications.js @@ -36,6 +36,7 @@ export const notificationsStore = defineStore('crm-notifications', () => { } return { + notifications, visible, allNotifications, unreadNotificationsCount,