2022-07-22 17:34:10 +00:00
|
|
|
import { Col } from 'web/components/layout/col'
|
|
|
|
import { Row } from 'web/components/layout/row'
|
|
|
|
import clsx from 'clsx'
|
2022-07-22 22:28:53 +00:00
|
|
|
import { GroupLinkItem } from 'web/pages/groups'
|
2022-07-22 17:34:10 +00:00
|
|
|
import { XIcon } from '@heroicons/react/outline'
|
|
|
|
import { Button } from 'web/components/button'
|
|
|
|
import { GroupSelector } from 'web/components/groups/group-selector'
|
|
|
|
import {
|
|
|
|
addContractToGroup,
|
2022-08-02 03:15:09 +00:00
|
|
|
canModifyGroupContracts,
|
2022-07-22 17:34:10 +00:00
|
|
|
removeContractFromGroup,
|
|
|
|
} from 'web/lib/firebase/groups'
|
|
|
|
import { User } from 'common/user'
|
|
|
|
import { Contract } from 'common/contract'
|
2022-07-22 19:53:19 +00:00
|
|
|
import { SiteLink } from 'web/components/site-link'
|
2022-07-22 22:28:53 +00:00
|
|
|
import { GroupLink } from 'common/group'
|
|
|
|
import { useGroupsWithContract } from 'web/hooks/use-group'
|
2022-07-22 17:34:10 +00:00
|
|
|
|
|
|
|
export function ContractGroupsList(props: {
|
2022-07-22 22:28:53 +00:00
|
|
|
groupLinks: GroupLink[]
|
2022-07-22 17:34:10 +00:00
|
|
|
contract: Contract
|
|
|
|
user: User | null | undefined
|
|
|
|
}) {
|
2022-07-22 22:28:53 +00:00
|
|
|
const { groupLinks, user, contract } = props
|
|
|
|
const groups = useGroupsWithContract(contract)
|
2022-07-22 17:34:10 +00:00
|
|
|
return (
|
|
|
|
<Col className={'gap-2'}>
|
2022-07-22 19:53:19 +00:00
|
|
|
<span className={'text-xl text-indigo-700'}>
|
|
|
|
<SiteLink href={'/groups/'}>Groups</SiteLink>
|
|
|
|
</span>
|
2022-07-22 17:34:10 +00:00
|
|
|
{user && (
|
2022-07-22 19:53:19 +00:00
|
|
|
<Col className={'ml-2 items-center justify-between sm:flex-row'}>
|
|
|
|
<span>Add to: </span>
|
2022-07-22 17:34:10 +00:00
|
|
|
<GroupSelector
|
|
|
|
options={{
|
|
|
|
showSelector: true,
|
|
|
|
showLabel: false,
|
2022-07-22 22:28:53 +00:00
|
|
|
ignoreGroupIds: groupLinks.map((g) => g.groupId),
|
2022-07-22 17:34:10 +00:00
|
|
|
}}
|
2022-07-22 19:53:19 +00:00
|
|
|
setSelectedGroup={(group) =>
|
2022-07-22 22:28:53 +00:00
|
|
|
group && addContractToGroup(group, contract, user.id)
|
2022-07-22 19:53:19 +00:00
|
|
|
}
|
2022-07-22 17:34:10 +00:00
|
|
|
selectedGroup={undefined}
|
|
|
|
creator={user}
|
|
|
|
/>
|
2022-07-22 19:53:19 +00:00
|
|
|
</Col>
|
2022-07-22 17:34:10 +00:00
|
|
|
)}
|
|
|
|
{groups.length === 0 && (
|
|
|
|
<Col className="ml-2 h-full justify-center text-gray-500">
|
|
|
|
No groups yet...
|
|
|
|
</Col>
|
|
|
|
)}
|
|
|
|
{groups.map((group) => (
|
|
|
|
<Row
|
|
|
|
key={group.id}
|
|
|
|
className={clsx('items-center justify-between gap-2 p-2')}
|
|
|
|
>
|
|
|
|
<Row className="line-clamp-1 items-center gap-2">
|
2022-07-22 22:28:53 +00:00
|
|
|
<GroupLinkItem group={group} />
|
2022-07-22 17:34:10 +00:00
|
|
|
</Row>
|
2022-08-02 03:15:09 +00:00
|
|
|
{user && canModifyGroupContracts(group, user.id) && (
|
2022-07-22 17:34:10 +00:00
|
|
|
<Button
|
|
|
|
color={'gray-white'}
|
|
|
|
size={'xs'}
|
2022-08-02 03:15:09 +00:00
|
|
|
onClick={() => removeContractFromGroup(group, contract, user.id)}
|
2022-07-22 17:34:10 +00:00
|
|
|
>
|
|
|
|
<XIcon className="h-4 w-4 text-gray-500" />
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
))}
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|