mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-23 15:24:21 +00:00
31 lines
865 B
TypeScript
31 lines
865 B
TypeScript
|
import * as React from "react"
|
||
|
import {useAuthorizationContext} from "../../contexts/authorization"
|
||
|
import {useGroupContext} from "../../contexts/group"
|
||
|
|
||
|
|
||
|
export function useGroupMembership(): boolean | undefined {
|
||
|
const authorization = useAuthorizationContext()
|
||
|
const group = useGroupContext()
|
||
|
|
||
|
|
||
|
return React.useMemo(
|
||
|
() => {
|
||
|
if(!authorization) {
|
||
|
return undefined
|
||
|
}
|
||
|
if(!group) {
|
||
|
return undefined
|
||
|
}
|
||
|
if(!authorization.state.token) {
|
||
|
return false
|
||
|
}
|
||
|
if(!(
|
||
|
group.value.members.includes(authorization.state.user.id) || group.value.owner === authorization.state.user.id
|
||
|
)) {
|
||
|
return false
|
||
|
}
|
||
|
return true
|
||
|
},
|
||
|
[authorization, group]
|
||
|
)
|
||
|
}
|