frontend initiatewith shadcn uis
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
'use client'
|
||||
|
||||
import { useAuth } from '@/contexts/auth-context'
|
||||
|
||||
export function usePermission(permission: string): boolean {
|
||||
const { permissions } = useAuth()
|
||||
return permissions.includes('*') || permissions.includes(permission)
|
||||
}
|
||||
|
||||
export function usePermissions(codes: string[]): boolean[] {
|
||||
const { permissions } = useAuth()
|
||||
const isAdmin = permissions.includes('*')
|
||||
return codes.map((code) => isAdmin || permissions.includes(code))
|
||||
}
|
||||
|
||||
export function useHasAnyPermission(codes: string[]): boolean {
|
||||
const { permissions } = useAuth()
|
||||
if (permissions.includes('*')) return true
|
||||
return codes.some((code) => permissions.includes(code))
|
||||
}
|
||||
Reference in New Issue
Block a user