2021-06-23 05:37:08 -04:00
|
|
|
import { useMemo } from 'react'
|
2021-03-12 05:23:46 -05:00
|
|
|
import { Row } from 'react-bootstrap'
|
|
|
|
import AddCollaborators from './add-collaborators'
|
|
|
|
import AddCollaboratorsUpgrade from './add-collaborators-upgrade'
|
2021-06-25 04:13:17 -04:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
export default function SendInvites() {
|
2022-01-10 10:47:10 -05:00
|
|
|
const { members, invites, features } = useProjectContext()
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
// whether the project has not reached the collaborator limit
|
|
|
|
const canAddCollaborators = useMemo(() => {
|
2022-01-10 10:47:10 -05:00
|
|
|
if (!features) {
|
2021-03-12 05:23:46 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-01-10 10:47:10 -05:00
|
|
|
if (features.collaborators === -1) {
|
2021-03-12 05:23:46 -05:00
|
|
|
// infinite collaborators
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-01-10 10:47:10 -05:00
|
|
|
return members.length + invites.length < features.collaborators
|
|
|
|
}, [members, invites, features])
|
2021-03-12 05:23:46 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Row className="invite-controls">
|
|
|
|
{canAddCollaborators ? <AddCollaborators /> : <AddCollaboratorsUpgrade />}
|
|
|
|
</Row>
|
|
|
|
)
|
|
|
|
}
|