1
0
forked from test/crm

fix: realtime notifications

This commit is contained in:
Shariq Ansari 2024-04-25 18:29:39 +05:30
parent a0260bfb41
commit 16d6f3d976
3 changed files with 20 additions and 3 deletions

View File

@ -1,9 +1,10 @@
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors # Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt # For license information, please see license.txt
# import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
class CRMNotification(Document): class CRMNotification(Document):
pass def on_update(self):
frappe.publish_realtime("crm_notification")

View File

@ -98,10 +98,13 @@ import MarkAsDoneIcon from '@/components/Icons/MarkAsDoneIcon.vue'
import NotificationsIcon from '@/components/Icons/NotificationsIcon.vue' import NotificationsIcon from '@/components/Icons/NotificationsIcon.vue'
import UserAvatar from '@/components/UserAvatar.vue' import UserAvatar from '@/components/UserAvatar.vue'
import { notificationsStore } from '@/stores/notifications' import { notificationsStore } from '@/stores/notifications'
import { globalStore } from '@/stores/global'
import { timeAgo } from '@/utils' import { timeAgo } from '@/utils'
import { onClickOutside } from '@vueuse/core' import { onClickOutside } from '@vueuse/core'
import { Tooltip } from 'frappe-ui' import { Tooltip } from 'frappe-ui'
import { ref } from 'vue' import { ref, onMounted, onBeforeUnmount } from 'vue'
const { $socket } = globalStore()
const target = ref(null) const target = ref(null)
onClickOutside( onClickOutside(
@ -124,6 +127,16 @@ function mark_as_read(doc) {
notificationsStore().mark_doc_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) { function getRoute(notification) {
let params = { let params = {
leadId: notification.reference_name, leadId: notification.reference_name,
@ -139,4 +152,6 @@ function getRoute(notification) {
hash: '#' + notification.comment || notification.notification_type_doc, hash: '#' + notification.comment || notification.notification_type_doc,
} }
} }
onMounted(() => {})
</script> </script>

View File

@ -36,6 +36,7 @@ export const notificationsStore = defineStore('crm-notifications', () => {
} }
return { return {
notifications,
visible, visible,
allNotifications, allNotifications,
unreadNotificationsCount, unreadNotificationsCount,