You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB
JavaScript

import { router } from '@inertiajs/react'
export const filterOpenMenu = (user, item) => {
const isAdmin = user.role === null
if ('items' in item) {
let items = []
if (isAdmin) {
items = item.items
} else {
items = item.items.filter((item) =>
user.role.permissions.find((p) => p.name === item.permission)
? item
: null
)
}
if (items.length > 0) {
let activeItem = items.map((item) => route().current(item.active))
item.open = activeItem.includes(true)
item.items = items.filter((item) => (item.show ? item : null))
return item
}
}
if (isAdmin) {
return item
}
}
export const browserNotification = (title, message, url) => {
if (typeof Notification !== undefined) {
let permission = Notification.permission
if (permission === 'granted') {
let notification = new Notification(title, {
body: message,
})
notification.onclick = () => {
window.parent.focus()
router.visit(url)
}
}
}
}