fix: made notifications store generic
This commit is contained in:
parent
ace509dd80
commit
a0260bfb41
@ -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()
|
||||
|
||||
@ -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)"
|
||||
>
|
||||
<div class="mt-1 flex items-center gap-2.5">
|
||||
<div
|
||||
@ -120,8 +120,8 @@ function toggleNotificationPanel() {
|
||||
notificationsStore().toggle()
|
||||
}
|
||||
|
||||
function mark_as_read(comment) {
|
||||
notificationsStore().mark_comment_as_read(comment)
|
||||
function mark_as_read(doc) {
|
||||
notificationsStore().mark_doc_as_read(doc)
|
||||
}
|
||||
|
||||
function getRoute(notification) {
|
||||
|
||||
@ -29,8 +29,8 @@ export const notificationsStore = defineStore('crm-notifications', () => {
|
||||
() => 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,
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user