Show group based on most recent creator added group
This commit is contained in:
parent
6706fe7350
commit
c6eac97b64
|
@ -27,7 +27,7 @@ import { Modal } from 'web/components/layout/modal'
|
||||||
import { Col } from 'web/components/layout/col'
|
import { Col } from 'web/components/layout/col'
|
||||||
import { ContractGroupsList } from 'web/components/groups/contract-groups-list'
|
import { ContractGroupsList } from 'web/components/groups/contract-groups-list'
|
||||||
import { SiteLink } from 'web/components/site-link'
|
import { SiteLink } from 'web/components/site-link'
|
||||||
import { groupPath } from 'web/lib/firebase/groups'
|
import { getGroupLinkToDisplay, groupPath } from 'web/lib/firebase/groups'
|
||||||
import { insertContent } from '../editor/utils'
|
import { insertContent } from '../editor/utils'
|
||||||
import { contractMetrics } from 'common/contract-details'
|
import { contractMetrics } from 'common/contract-details'
|
||||||
import { User } from 'common/user'
|
import { User } from 'common/user'
|
||||||
|
@ -52,10 +52,10 @@ export function MiscDetails(props: {
|
||||||
isResolved,
|
isResolved,
|
||||||
createdTime,
|
createdTime,
|
||||||
resolutionTime,
|
resolutionTime,
|
||||||
groupLinks,
|
|
||||||
} = contract
|
} = contract
|
||||||
|
|
||||||
const isNew = createdTime > Date.now() - DAY_MS && !isResolved
|
const isNew = createdTime > Date.now() - DAY_MS && !isResolved
|
||||||
|
const groupToDisplay = getGroupLinkToDisplay(contract)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row className="items-center gap-3 truncate text-sm text-gray-400">
|
<Row className="items-center gap-3 truncate text-sm text-gray-400">
|
||||||
|
@ -83,12 +83,12 @@ export function MiscDetails(props: {
|
||||||
<NewContractBadge />
|
<NewContractBadge />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!hideGroupLink && groupLinks && groupLinks.length > 0 && (
|
{!hideGroupLink && groupToDisplay && (
|
||||||
<SiteLink
|
<SiteLink
|
||||||
href={groupPath(groupLinks[0].slug)}
|
href={groupPath(groupToDisplay.slug)}
|
||||||
className="truncate text-sm text-gray-400"
|
className="truncate text-sm text-gray-400"
|
||||||
>
|
>
|
||||||
{groupLinks[0].name}
|
{groupToDisplay.name}
|
||||||
</SiteLink>
|
</SiteLink>
|
||||||
)}
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
|
@ -148,19 +148,15 @@ export function ContractDetails(props: {
|
||||||
creatorName,
|
creatorName,
|
||||||
creatorUsername,
|
creatorUsername,
|
||||||
creatorId,
|
creatorId,
|
||||||
groupLinks,
|
|
||||||
creatorAvatarUrl,
|
creatorAvatarUrl,
|
||||||
resolutionTime,
|
resolutionTime,
|
||||||
} = contract
|
} = contract
|
||||||
const { volumeLabel, resolvedDate } = contractMetrics(contract)
|
const { volumeLabel, resolvedDate } = contractMetrics(contract)
|
||||||
|
|
||||||
const groupToDisplay =
|
|
||||||
groupLinks?.sort((a, b) => a.createdTime - b.createdTime)[0] ?? null
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const { width } = useWindowSize()
|
const { width } = useWindowSize()
|
||||||
const isMobile = (width ?? 0) < 600
|
const isMobile = (width ?? 0) < 600
|
||||||
|
const groupToDisplay = getGroupLinkToDisplay(contract)
|
||||||
const groupInfo = groupToDisplay ? (
|
const groupInfo = groupToDisplay ? (
|
||||||
<Row
|
<Row
|
||||||
className={clsx(
|
className={clsx(
|
||||||
|
@ -236,11 +232,7 @@ export function ContractDetails(props: {
|
||||||
'max-h-[70vh] min-h-[20rem] overflow-auto rounded bg-white p-6'
|
'max-h-[70vh] min-h-[20rem] overflow-auto rounded bg-white p-6'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<ContractGroupsList
|
<ContractGroupsList contract={contract} user={user} />
|
||||||
groupLinks={groupLinks ?? []}
|
|
||||||
contract={contract}
|
|
||||||
user={user}
|
|
||||||
/>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
|
|
@ -13,15 +13,14 @@ import {
|
||||||
import { User } from 'common/user'
|
import { User } from 'common/user'
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
import { SiteLink } from 'web/components/site-link'
|
import { SiteLink } from 'web/components/site-link'
|
||||||
import { GroupLink } from 'common/group'
|
|
||||||
import { useGroupsWithContract } from 'web/hooks/use-group'
|
import { useGroupsWithContract } from 'web/hooks/use-group'
|
||||||
|
|
||||||
export function ContractGroupsList(props: {
|
export function ContractGroupsList(props: {
|
||||||
groupLinks: GroupLink[]
|
|
||||||
contract: Contract
|
contract: Contract
|
||||||
user: User | null | undefined
|
user: User | null | undefined
|
||||||
}) {
|
}) {
|
||||||
const { groupLinks, user, contract } = props
|
const { user, contract } = props
|
||||||
|
const { groupLinks } = contract
|
||||||
const groups = useGroupsWithContract(contract)
|
const groups = useGroupsWithContract(contract)
|
||||||
return (
|
return (
|
||||||
<Col className={'gap-2'}>
|
<Col className={'gap-2'}>
|
||||||
|
@ -35,7 +34,7 @@ export function ContractGroupsList(props: {
|
||||||
options={{
|
options={{
|
||||||
showSelector: true,
|
showSelector: true,
|
||||||
showLabel: false,
|
showLabel: false,
|
||||||
ignoreGroupIds: groupLinks.map((g) => g.groupId),
|
ignoreGroupIds: groupLinks?.map((g) => g.groupId),
|
||||||
}}
|
}}
|
||||||
setSelectedGroup={(group) =>
|
setSelectedGroup={(group) =>
|
||||||
group && addContractToGroup(group, contract, user.id)
|
group && addContractToGroup(group, contract, user.id)
|
||||||
|
|
|
@ -208,3 +208,17 @@ export function canModifyGroupContracts(group: Group, userId: string) {
|
||||||
group.anyoneCanJoin
|
group.anyoneCanJoin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getGroupLinkToDisplay(contract: Contract) {
|
||||||
|
const { groupLinks } = contract
|
||||||
|
const sortedGroupLinks = groupLinks?.sort(
|
||||||
|
(a, b) => b.createdTime - a.createdTime
|
||||||
|
)
|
||||||
|
const groupCreatorAdded = sortedGroupLinks?.find(
|
||||||
|
(g) => g.userId === contract.creatorId
|
||||||
|
)
|
||||||
|
const groupToDisplay = groupCreatorAdded
|
||||||
|
? groupCreatorAdded
|
||||||
|
: sortedGroupLinks?.[0] ?? null
|
||||||
|
return groupToDisplay
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user