fix: created notifications store to get all notifications

This commit is contained in:
Shariq Ansari 2024-01-29 20:35:33 +05:30
parent d6b0bee1a6
commit a9d51f8f8a
3 changed files with 57 additions and 1 deletions

18
crm/api/notifications.py Normal file
View 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

View File

@ -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 = [

View 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,
}
})