@ -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>
|
||||
|
@ -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}>
|
||||
|
@ -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) {
|
||||
|
@ -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]
|
||||
}
|
||||
|
@ -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]
|
||||
}
|
||||
|
@ -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 &&
|
||||
|
Reference in New Issue
Block a user