Skip to content

Commit

Permalink
🚑 Fix can invite new members in workspace bool
Browse files Browse the repository at this point in the history
Closes #964
  • Loading branch information
baptisteArno committed Oct 25, 2023
1 parent 4b248d5 commit 53558dc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down Expand Up @@ -79,7 +80,7 @@ export const UsageProgressBars = ({ workspace }: Props) => {
</Skeleton>
<Text>
/{' '}
{workspaceChatsLimit === -1
{workspaceChatsLimit === 'inf'
? scopedT('unlimited')
: parseNumberWithCommas(workspaceChatsLimit)}
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/billing/getChatsLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
4 changes: 2 additions & 2 deletions packages/lib/billing/getSeatsLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
1 change: 1 addition & 0 deletions packages/scripts/checkAndReportChatsUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 53558dc

Please sign in to comment.