2
0

🚑 Fix can invite new members in workspace bool

Closes #964
This commit is contained in:
Baptiste Arnaud
2023-10-25 17:57:13 +02:00
parent 4b248d554f
commit 53558dc303
6 changed files with 19 additions and 13 deletions

View File

@ -32,9 +32,10 @@ export const UsageProgressBars = ({ workspace }: Props) => {
const workspaceChatsLimit = getChatsLimit(workspace)
const chatsPercentage = Math.round(
(totalChatsUsed / workspaceChatsLimit) * 100
)
const chatsPercentage =
workspaceChatsLimit === 'inf'
? 0
: Math.round((totalChatsUsed / workspaceChatsLimit) * 100)
return (
<Stack spacing={6}>
@ -79,7 +80,7 @@ export const UsageProgressBars = ({ workspace }: Props) => {
</Skeleton>
<Text>
/{' '}
{workspaceChatsLimit === -1
{workspaceChatsLimit === 'inf'
? scopedT('unlimited')
: parseNumberWithCommas(workspaceChatsLimit)}
</Text>

View File

@ -92,9 +92,12 @@ export const MembersList = () => {
const seatsLimit = workspace ? getSeatsLimit(workspace) : undefined
const canInviteNewMember = workspace
? currentMembersCount < (seatsLimit as number)
: false
const canInviteNewMember =
seatsLimit === 'inf'
? true
: seatsLimit
? currentMembersCount < seatsLimit
: false
return (
<Stack w="full" spacing={3}>

View File

@ -36,9 +36,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
where: { workspaceId: workspace.id },
}),
])
const seatsLimit = getSeatsLimit(workspace)
if (
getSeatsLimit(workspace) <=
existingMembersCount + existingInvitationsCount
seatsLimit !== 'inf' &&
seatsLimit <= existingMembersCount + existingInvitationsCount
)
return res.status(400).send('Seats limit reached')
if (existingUser) {

View File

@ -13,7 +13,7 @@ export const getChatsLimit = ({
plan === Plan.LIFETIME ||
plan === Plan.OFFERED
)
return -1
if (plan === Plan.CUSTOM) return customChatsLimit ?? -1
return 'inf'
if (plan === Plan.CUSTOM) return customChatsLimit ?? 'inf'
return chatsLimits[plan]
}

View File

@ -6,7 +6,7 @@ export const getSeatsLimit = ({
plan,
customSeatsLimit,
}: Pick<Workspace, 'plan' | 'customSeatsLimit'>) => {
if (plan === Plan.UNLIMITED) return -1
if (plan === Plan.CUSTOM) return customSeatsLimit ? customSeatsLimit : -1
if (plan === Plan.UNLIMITED) return 'inf'
if (plan === Plan.CUSTOM) return customSeatsLimit ? customSeatsLimit : 'inf'
return seatsLimits[plan]
}

View File

@ -110,6 +110,7 @@ export const checkAndReportChatsUsage = async () => {
workspaceId: result.workspace.id,
subscription,
})
if (chatsLimit === 'inf') continue
if (
chatsLimit > 0 &&
totalChatsUsed >= chatsLimit * LIMIT_EMAIL_TRIGGER_PERCENT &&