Skip to content

Commit af17057

Browse files
committed
refactor: fetch push notification settings status from API instead of boot
1 parent b4729c6 commit af17057

File tree

7 files changed

+32
-17
lines changed

7 files changed

+32
-17
lines changed

frontend/public/frappe-push-notification.js

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ class FrappePushNotification {
1212
return window.frappe?.boot.push_relay_server_url
1313
}
1414

15-
static get isNotificationRelayEnabled() {
16-
return window.frappe?.boot.push_notifications_enabled
17-
}
18-
1915
// Type definitions
2016
/**
2117
* Web Config

frontend/src/data/notifications.js

+6
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ export const notifications = createListResource({
2727
unreadNotificationsCount.reload()
2828
},
2929
})
30+
31+
export const arePushNotificationsEnabled = createResource({
32+
url: "hrms.api.are_push_notifications_enabled",
33+
cache: "hrms:push_notifications_enabled",
34+
auto: true,
35+
})

frontend/src/views/AppSettings.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import { FeatherIcon, Switch, toast, LoadingIndicator } from "frappe-ui"
5555
5656
import { computed, ref } from "vue"
5757
58+
import { arePushNotificationsEnabled } from "@/data/notifications"
59+
5860
const router = useRouter()
5961
const pushNotificationState = ref(
6062
window.frappePushNotification?.isNotificationEnabled()
@@ -63,8 +65,10 @@ const isLoading = ref(false)
6365
6466
const disablePushSetting = computed(() => {
6567
return (
66-
!(window.push_relay_server_url && window.push_notifications_enabled) ||
67-
isLoading.value
68+
!(
69+
window.frappe?.boot.push_relay_server_url &&
70+
arePushNotificationsEnabled.data
71+
) || isLoading.value
6872
)
6973
})
7074

frontend/src/views/Notifications.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,20 @@ import { computed, inject } from "vue"
9696
import EmployeeAvatar from "@/components/EmployeeAvatar.vue"
9797
import EmptyState from "@/components/EmptyState.vue"
9898
99-
import { unreadNotificationsCount, notifications } from "@/data/notifications"
99+
import {
100+
unreadNotificationsCount,
101+
notifications,
102+
arePushNotificationsEnabled,
103+
} from "@/data/notifications"
100104
101105
const user = inject("$user")
102106
const dayjs = inject("$dayjs")
103107
const router = useRouter()
104108
105109
const allowPushNotifications = computed(
106-
() => window.push_relay_server_url && window.push_notifications_enabled
110+
() =>
111+
window.frappe?.boot.push_relay_server_url &&
112+
arePushNotificationsEnabled.data
107113
)
108114
109115
const markAllAsRead = createResource({

frontend/src/views/Profile.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ import { formatCurrency } from "@/utils/formatters"
147147
148148
import ProfileInfoModal from "@/components/ProfileInfoModal.vue"
149149
150+
import { arePushNotificationsEnabled } from "@/data/notifications"
151+
150152
const DOCTYPE = "Employee"
151153
152154
const socket = inject("$socket")
@@ -214,7 +216,9 @@ const isInfoModalOpen = ref(false)
214216
const selectedItem = ref(null)
215217
216218
const allowPushNotifications = computed(
217-
() => window.push_relay_server_url && window.push_notifications_enabled
219+
() =>
220+
window.frappe?.boot.push_relay_server_url &&
221+
arePushNotificationsEnabled.data
218222
)
219223
220224
const openInfoModal = async (request) => {

hrms/api/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def get_all_employees() -> list[dict]:
7575
)
7676

7777

78+
# Notifications
7879
@frappe.whitelist()
7980
def get_unread_notifications_count() -> int:
8081
return frappe.db.count(
@@ -94,6 +95,11 @@ def mark_all_notifications_as_read() -> None:
9495
)
9596

9697

98+
@frappe.whitelist()
99+
def are_push_notifications_enabled() -> bool:
100+
return frappe.db.get_single_value("Push Notification Settings", "enable_push_notification_relay")
101+
102+
97103
# Leaves and Holidays
98104
@frappe.whitelist()
99105
def get_leave_applications(

hrms/www/hrms.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,4 @@ def get_context_for_dev():
2020

2121

2222
def get_boot():
23-
return frappe._dict(
24-
{
25-
"push_notifications_enabled": frappe.db.get_single_value(
26-
"Push Notification Settings", "enable_push_notification_relay"
27-
),
28-
"push_relay_server_url": frappe.conf.get("push_relay_server_url"),
29-
}
30-
)
23+
return frappe._dict({"push_relay_server_url": frappe.conf.get("push_relay_server_url")})

0 commit comments

Comments
 (0)