From a0260bfb413638d94eca0fc552333aaac11ba1c8 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Thu, 25 Apr 2024 17:07:11 +0530 Subject: [PATCH] fix: made notifications store generic --- crm/api/notifications.py | 23 +++++++++++++---------- frontend/src/components/Notifications.vue | 6 +++--- frontend/src/stores/notifications.js | 6 +++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/crm/api/notifications.py b/crm/api/notifications.py index f7684e36..972fa58e 100644 --- a/crm/api/notifications.py +++ b/crm/api/notifications.py @@ -31,13 +31,13 @@ def get_notifications(): "notification_text": notification.notification_text, "notification_type_doctype": notification.notification_type_doctype, "notification_type_doc": notification.notification_type_doc, - "reference_doctype": "deal" - if notification.reference_doctype == "CRM Deal" - else "lead", + "reference_doctype": ( + "deal" if notification.reference_doctype == "CRM Deal" else "lead" + ), "reference_name": notification.reference_name, - "route_name": "Deal" - if notification.reference_doctype == "CRM Deal" - else "Lead", + "route_name": ( + "Deal" if notification.reference_doctype == "CRM Deal" else "Lead" + ), } ) @@ -45,12 +45,15 @@ def get_notifications(): @frappe.whitelist() -def mark_as_read(user=None, comment=None): +def mark_as_read(user=None, doc=None): user = user or frappe.session.user filters = {"to_user": user, "read": False} - if comment: - filters["comment"] = comment - for n in frappe.get_all("CRM Notification", filters=filters): + if doc: + or_filters = [ + {"comment": doc}, + {"notification_type_doc": doc}, + ] + for n in frappe.get_all("CRM Notification", filters=filters, or_filters=or_filters): d = frappe.get_doc("CRM Notification", n.name) d.read = True d.save() diff --git a/frontend/src/components/Notifications.vue b/frontend/src/components/Notifications.vue index 9eb8aa22..2781d1ec 100644 --- a/frontend/src/components/Notifications.vue +++ b/frontend/src/components/Notifications.vue @@ -48,7 +48,7 @@ :key="n.comment" :to="getRoute(n)" class="flex cursor-pointer items-start gap-2.5 px-4 py-2.5 hover:bg-gray-100" - @click="mark_as_read(n.comment)" + @click="mark_as_read(n.comment || n.notification_type_doc)" >
{ () => notifications.data?.filter((n) => !n.read).length || 0 ) - function mark_comment_as_read(comment) { - mark_as_read.params = { comment: comment } + function mark_doc_as_read(doc) { + mark_as_read.params = { doc: doc } mark_as_read.reload() toggle() } @@ -40,7 +40,7 @@ export const notificationsStore = defineStore('crm-notifications', () => { allNotifications, unreadNotificationsCount, mark_as_read, - mark_comment_as_read, + mark_doc_as_read, toggle, } })