import { Col } from 'web/components/layout/col' import { Row } from 'web/components/layout/row' import clsx from 'clsx' import { GroupLinkItem } from 'web/pages/groups' import { XIcon } from '@heroicons/react/outline' import { Button } from 'web/components/button' import { GroupSelector } from 'web/components/groups/group-selector' import { addContractToGroup, removeContractFromGroup, } from 'web/lib/firebase/groups' import { User } from 'common/user' import { Contract } from 'common/contract' import { SiteLink } from 'web/components/site-link' import { useGroupsWithContract, useMemberGroupIds } from 'web/hooks/use-group' import { Group } from 'common/group' export function ContractGroupsList(props: { contract: Contract user: User | null | undefined }) { const { user, contract } = props const { groupLinks } = contract const groups = useGroupsWithContract(contract) const memberGroupIds = useMemberGroupIds(user) const canModifyGroupContracts = (group: Group, userId: string) => { return ( group.creatorId === userId || group.anyoneCanJoin || memberGroupIds?.includes(group.id) ) } return ( Groups {user && ( Add to: g.groupId), }} setSelectedGroup={(group) => group && addContractToGroup(group, contract, user.id) } selectedGroup={undefined} creator={user} /> )} {groups.length === 0 && ( No groups yet... )} {groups.map((group) => ( {user && canModifyGroupContracts(group, user.id) && ( )} ))} ) }