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
|
# 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")
|
||||||
|
|||||||
@ -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>
|
||||||
|
|||||||
@ -36,6 +36,7 @@ export const notificationsStore = defineStore('crm-notifications', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
notifications,
|
||||||
visible,
|
visible,
|
||||||
allNotifications,
|
allNotifications,
|
||||||
unreadNotificationsCount,
|
unreadNotificationsCount,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user