2021-10-13 03:21:38 +00:00
|
|
|
import {faUsersCog} from "@fortawesome/free-solid-svg-icons"
|
|
|
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
|
|
|
import {Box, Heading, Idiomatic, ListUnordered, UAnnotation} from "@steffo/bluelib-react"
|
2021-10-12 02:40:48 +00:00
|
|
|
import * as React from "react"
|
2021-10-13 03:21:38 +00:00
|
|
|
import {useAuthorizationContext} from "../../contexts/authorization"
|
2021-10-12 02:40:48 +00:00
|
|
|
import {useCacheContext} from "../../contexts/cache"
|
|
|
|
import {ManagedResource} from "../../hooks/useManagedViewSet"
|
|
|
|
import {SophonResearchGroup} from "../../types/SophonTypes"
|
|
|
|
|
|
|
|
|
|
|
|
export interface GroupMembersBoxProps {
|
|
|
|
resource: ManagedResource<SophonResearchGroup>
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function GroupMembersBox({resource}: GroupMembersBoxProps): JSX.Element | null {
|
2021-10-13 03:21:38 +00:00
|
|
|
const authorization = useAuthorizationContext()
|
2021-10-12 02:40:48 +00:00
|
|
|
const cache = useCacheContext()
|
|
|
|
|
|
|
|
if(!cache) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
if(!cache.users) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
const trueMembers = [...new Set([resource.value.owner, ...resource.value.members])]
|
|
|
|
|
2021-10-13 01:39:38 +00:00
|
|
|
const users = trueMembers.map((id, index) => {
|
|
|
|
const user = cache.getUserById(id)
|
|
|
|
|
|
|
|
if(!user) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2021-10-13 03:21:38 +00:00
|
|
|
const username = id === authorization?.state.user?.id ? <UAnnotation>{user.value.username}</UAnnotation> : user.value.username
|
|
|
|
|
2021-10-13 01:39:38 +00:00
|
|
|
return (
|
|
|
|
<ListUnordered.Item bluelibClassNames={index === 0 ? "color-blue" : ""} key={id}>
|
2021-10-13 03:21:38 +00:00
|
|
|
{username}
|
2021-10-13 01:39:38 +00:00
|
|
|
</ListUnordered.Item>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-10-12 02:40:48 +00:00
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Heading level={3}>
|
2021-10-13 03:21:38 +00:00
|
|
|
<FontAwesomeIcon icon={faUsersCog}/> Members of <Idiomatic>{resource.value.name}</Idiomatic>
|
2021-10-12 02:40:48 +00:00
|
|
|
</Heading>
|
|
|
|
<ListUnordered>
|
2021-10-13 01:39:38 +00:00
|
|
|
{users}
|
2021-10-12 02:40:48 +00:00
|
|
|
</ListUnordered>
|
|
|
|
</Box>
|
|
|
|
)
|
|
|
|
}
|