fix: realtime notifications
This commit is contained in:
parent
a0260bfb41
commit
16d6f3d976
@ -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")
|
||||
|
||||
@ -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(() => {})
|
||||
</script>
|
||||
|
||||
@ -36,6 +36,7 @@ export const notificationsStore = defineStore('crm-notifications', () => {
|
||||
}
|
||||
|
||||
return {
|
||||
notifications,
|
||||
visible,
|
||||
allNotifications,
|
||||
unreadNotificationsCount,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user