fix: created notifications store to get all notifications
This commit is contained in:
parent
d6b0bee1a6
commit
a9d51f8f8a
18
crm/api/notifications.py
Normal file
18
crm/api/notifications.py
Normal file
@ -0,0 +1,18 @@
|
||||
import frappe
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_notifications():
|
||||
if frappe.session.user == "Guest":
|
||||
frappe.throw("Authentication failed", exc=frappe.AuthenticationError)
|
||||
|
||||
Notification = frappe.qb.DocType("CRM Notification")
|
||||
query = (
|
||||
frappe.qb.from_(Notification)
|
||||
.select("*")
|
||||
.where(Notification.to_user == frappe.session.user)
|
||||
.where(Notification.read == False)
|
||||
.orderby("creation")
|
||||
)
|
||||
notifications = query.run(as_dict=True)
|
||||
return notifications
|
||||
@ -12,7 +12,7 @@
|
||||
label="Notifications"
|
||||
:icon="NotificationsIcon"
|
||||
:isCollapsed="isSidebarCollapsed"
|
||||
@click="() => {}"
|
||||
@click="() => toggleNotificationPanel()"
|
||||
class="mx-2 my-0.5"
|
||||
/>
|
||||
</div>
|
||||
@ -93,10 +93,12 @@ import CollapseSidebar from '@/components/Icons/CollapseSidebar.vue'
|
||||
import NotificationsIcon from '@/components/Icons/NotificationsIcon.vue'
|
||||
import SidebarLink from '@/components/SidebarLink.vue'
|
||||
import { viewsStore } from '@/stores/views'
|
||||
import { notificationsStore } from '@/stores/notifications'
|
||||
import { useStorage } from '@vueuse/core'
|
||||
import { computed } from 'vue'
|
||||
|
||||
const { getPinnedViews, getPublicViews } = viewsStore()
|
||||
const { toggle: toggleNotificationPanel } = notificationsStore()
|
||||
const isSidebarCollapsed = useStorage('sidebar_is_collapsed', false)
|
||||
|
||||
const links = [
|
||||
|
||||
36
frontend/src/stores/notifications.js
Normal file
36
frontend/src/stores/notifications.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { sessionStore } from '@/stores/session'
|
||||
import { createResource } from 'frappe-ui'
|
||||
import { reactive, ref } from 'vue'
|
||||
|
||||
export const notificationsStore = defineStore('crm-notifications', () => {
|
||||
const { user } = sessionStore()
|
||||
|
||||
let visible = ref(false)
|
||||
let unreadNotifications = reactive([])
|
||||
|
||||
const notifications = createResource({
|
||||
url: 'crm.api.notifications.get_notifications',
|
||||
cache: 'crm-notifications',
|
||||
initialData: [],
|
||||
auto: true,
|
||||
transform(data) {
|
||||
unreadNotifications = data
|
||||
return data
|
||||
},
|
||||
})
|
||||
|
||||
function toggle() {
|
||||
visible.value = !visible.value
|
||||
}
|
||||
|
||||
function getUnreadNotifications() {
|
||||
return unreadNotifications || []
|
||||
}
|
||||
|
||||
return {
|
||||
visible,
|
||||
toggle,
|
||||
getUnreadNotifications,
|
||||
}
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user