Add membership indicators and link to see group
This commit is contained in:
parent
668f30dd55
commit
c16e7c6cfd
|
@ -5,6 +5,7 @@ import {
|
||||||
CheckIcon,
|
CheckIcon,
|
||||||
PlusCircleIcon,
|
PlusCircleIcon,
|
||||||
SelectorIcon,
|
SelectorIcon,
|
||||||
|
UserIcon,
|
||||||
} from '@heroicons/react/outline'
|
} from '@heroicons/react/outline'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { CreateGroupButton } from 'web/components/groups/create-group-button'
|
import { CreateGroupButton } from 'web/components/groups/create-group-button'
|
||||||
|
@ -12,6 +13,7 @@ import { useState } from 'react'
|
||||||
import { useMemberGroups, useOpenGroups } from 'web/hooks/use-group'
|
import { useMemberGroups, useOpenGroups } from 'web/hooks/use-group'
|
||||||
import { User } from 'common/user'
|
import { User } from 'common/user'
|
||||||
import { searchInAny } from 'common/util/parse'
|
import { searchInAny } from 'common/util/parse'
|
||||||
|
import { Row } from 'web/components/layout/row'
|
||||||
|
|
||||||
export function GroupSelector(props: {
|
export function GroupSelector(props: {
|
||||||
selectedGroup: Group | undefined
|
selectedGroup: Group | undefined
|
||||||
|
@ -28,13 +30,26 @@ export function GroupSelector(props: {
|
||||||
const { showSelector, showLabel, ignoreGroupIds } = options
|
const { showSelector, showLabel, ignoreGroupIds } = options
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
const openGroups = useOpenGroups()
|
const openGroups = useOpenGroups()
|
||||||
|
const memberGroups = useMemberGroups(creator?.id)
|
||||||
|
const memberGroupIds = memberGroups?.map((g) => g.id) ?? []
|
||||||
const availableGroups = openGroups
|
const availableGroups = openGroups
|
||||||
.concat(
|
.concat(
|
||||||
(useMemberGroups(creator?.id) ?? []).filter(
|
(memberGroups ?? []).filter(
|
||||||
(g) => !openGroups.map((og) => og.id).includes(g.id)
|
(g) => !openGroups.map((og) => og.id).includes(g.id)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.filter((group) => !ignoreGroupIds?.includes(group.id))
|
.filter((group) => !ignoreGroupIds?.includes(group.id))
|
||||||
|
.sort((a, b) => b.totalContracts - a.totalContracts)
|
||||||
|
// put the groups the user is a member of first
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (memberGroupIds.includes(a.id)) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (memberGroupIds.includes(b.id)) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
})
|
||||||
|
|
||||||
const filteredGroups = availableGroups.filter((group) =>
|
const filteredGroups = availableGroups.filter((group) =>
|
||||||
searchInAny(query, group.name)
|
searchInAny(query, group.name)
|
||||||
|
@ -97,7 +112,7 @@ export function GroupSelector(props: {
|
||||||
value={group}
|
value={group}
|
||||||
className={({ active }) =>
|
className={({ active }) =>
|
||||||
clsx(
|
clsx(
|
||||||
'relative h-12 cursor-pointer select-none py-2 pl-4 pr-6',
|
'relative h-12 cursor-pointer select-none py-2 pr-6',
|
||||||
active ? 'bg-indigo-500 text-white' : 'text-gray-900'
|
active ? 'bg-indigo-500 text-white' : 'text-gray-900'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -120,7 +135,14 @@ export function GroupSelector(props: {
|
||||||
selected && 'font-semibold'
|
selected && 'font-semibold'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span className={'truncate'}>{group.name}</span>
|
<Row className={'items-center gap-1 truncate pl-5'}>
|
||||||
|
{memberGroupIds.includes(group.id) && (
|
||||||
|
<UserIcon
|
||||||
|
className={'text-primary h-4 w-4 shrink-0'}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{group.name}
|
||||||
|
</Row>
|
||||||
<span
|
<span
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'ml-1 w-[1.4rem] shrink-0 rounded-full bg-indigo-500 text-center text-white',
|
'ml-1 w-[1.4rem] shrink-0 rounded-full bg-indigo-500 text-center text-white',
|
||||||
|
|
|
@ -20,7 +20,7 @@ import {
|
||||||
import { formatMoney } from 'common/util/format'
|
import { formatMoney } from 'common/util/format'
|
||||||
import { removeUndefinedProps } from 'common/util/object'
|
import { removeUndefinedProps } from 'common/util/object'
|
||||||
import { ChoicesToggleGroup } from 'web/components/choices-toggle-group'
|
import { ChoicesToggleGroup } from 'web/components/choices-toggle-group'
|
||||||
import { getGroup } from 'web/lib/firebase/groups'
|
import { getGroup, groupPath } from 'web/lib/firebase/groups'
|
||||||
import { Group } from 'common/group'
|
import { Group } from 'common/group'
|
||||||
import { useTracking } from 'web/hooks/use-tracking'
|
import { useTracking } from 'web/hooks/use-tracking'
|
||||||
import { useWarnUnsavedChanges } from 'web/hooks/use-warn-unsaved-changes'
|
import { useWarnUnsavedChanges } from 'web/hooks/use-warn-unsaved-changes'
|
||||||
|
@ -34,6 +34,8 @@ import { Title } from 'web/components/title'
|
||||||
import { SEO } from 'web/components/SEO'
|
import { SEO } from 'web/components/SEO'
|
||||||
import { MultipleChoiceAnswers } from 'web/components/answers/multiple-choice-answers'
|
import { MultipleChoiceAnswers } from 'web/components/answers/multiple-choice-answers'
|
||||||
import { MINUTE_MS } from 'common/util/time'
|
import { MINUTE_MS } from 'common/util/time'
|
||||||
|
import { ExternalLinkIcon } from '@heroicons/react/outline'
|
||||||
|
import { SiteLink } from 'web/components/site-link'
|
||||||
|
|
||||||
export const getServerSideProps = redirectIfLoggedOut('/', async (_, creds) => {
|
export const getServerSideProps = redirectIfLoggedOut('/', async (_, creds) => {
|
||||||
return { props: { auth: await getUserAndPrivateUser(creds.uid) } }
|
return { props: { auth: await getUserAndPrivateUser(creds.uid) } }
|
||||||
|
@ -406,13 +408,19 @@ export function NewContract(props: {
|
||||||
|
|
||||||
<Spacer h={6} />
|
<Spacer h={6} />
|
||||||
|
|
||||||
|
<Row className={'items-end gap-x-2'}>
|
||||||
<GroupSelector
|
<GroupSelector
|
||||||
selectedGroup={selectedGroup}
|
selectedGroup={selectedGroup}
|
||||||
setSelectedGroup={setSelectedGroup}
|
setSelectedGroup={setSelectedGroup}
|
||||||
creator={creator}
|
creator={creator}
|
||||||
options={{ showSelector: showGroupSelector, showLabel: true }}
|
options={{ showSelector: showGroupSelector, showLabel: true }}
|
||||||
/>
|
/>
|
||||||
|
{showGroupSelector && selectedGroup && (
|
||||||
|
<SiteLink href={groupPath(selectedGroup.slug)}>
|
||||||
|
<ExternalLinkIcon className=" ml-1 mb-3 h-5 w-5 text-gray-500" />
|
||||||
|
</SiteLink>
|
||||||
|
)}
|
||||||
|
</Row>
|
||||||
<Spacer h={6} />
|
<Spacer h={6} />
|
||||||
|
|
||||||
<div className="form-control mb-1 items-start">
|
<div className="form-control mb-1 items-start">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user