2
0

🐛 (workspace) Fix members invitation when having unlimited plan

Closes #279
This commit is contained in:
Baptiste Arnaud
2023-02-13 11:13:05 +01:00
parent 46e9271aaa
commit 0dba994210
6 changed files with 56 additions and 54 deletions

View File

@ -8,9 +8,8 @@ import {
import { UnlockPlanAlertInfo } from '@/components/UnlockPlanAlertInfo'
import { WorkspaceInvitation, WorkspaceRole } from 'db'
import React from 'react'
import { getSeatsLimit } from 'utils/pricing'
import { getSeatsLimit, isSeatsLimitReached } from 'utils/pricing'
import { AddMemberForm } from './AddMemberForm'
import { checkCanInviteMember } from './helpers'
import { MemberItem } from './MemberItem'
import { useUser } from '@/features/account'
import { useWorkspace } from '../../WorkspaceProvider'
@ -20,6 +19,7 @@ import { updateMemberQuery } from '../../queries/updateMemberQuery'
import { deleteInvitationQuery } from '../../queries/deleteInvitationQuery'
import { updateInvitationQuery } from '../../queries/updateInvitationQuery'
import { Member } from '../../types'
import { isDefined } from 'utils'
export const MembersList = () => {
const { user } = useUser()
@ -88,11 +88,16 @@ export const MembersList = () => {
members.filter((member) => member.role !== WorkspaceRole.GUEST).length +
invitations.length
const canInviteNewMember = checkCanInviteMember({
plan: workspace?.plan,
customSeatsLimit: workspace?.customSeatsLimit,
currentMembersCount,
})
const seatsLimit = workspace ? getSeatsLimit(workspace) : undefined
const canInviteNewMember =
workspace &&
!isSeatsLimitReached({
plan: workspace?.plan,
customSeatsLimit: workspace?.customSeatsLimit,
existingMembersCount: currentMembersCount,
existingInvitationsCount: invitations.length,
})
return (
<Stack w="full" spacing={3}>
@ -104,12 +109,12 @@ export const MembersList = () => {
`}
/>
)}
{workspace && (
{isDefined(seatsLimit) && (
<Heading fontSize="2xl">
Members{' '}
{getSeatsLimit(workspace) === -1
{seatsLimit === -1
? ''
: `(${currentMembersCount}/${getSeatsLimit(workspace)})`}
: `(${currentMembersCount + invitations.length}/${seatsLimit})`}
</Heading>
)}
{workspace?.id && canEdit && (

View File

@ -1,23 +0,0 @@
import { Plan } from 'db'
import { getSeatsLimit } from 'utils/pricing'
export function checkCanInviteMember({
plan,
customSeatsLimit,
currentMembersCount,
}: {
plan?: Plan
customSeatsLimit?: number | null
currentMembersCount?: number
}) {
if (!plan || !currentMembersCount) return false
const seatsLimit = getSeatsLimit({
plan,
customSeatsLimit: customSeatsLimit ?? null,
})
if (seatsLimit === -1) return true
return seatsLimit > currentMembersCount
}