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

View File

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

View File

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

View File

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

View File

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

View File

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