From fc0e3782b1915b6b247f7ef4901098d0a6a9ac0e Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 11 Jul 2023 18:14:23 +0200 Subject: [PATCH] :bug: (workspace) Fix members list limit bug --- .../features/workspace/components/MembersList.tsx | 3 +-- .../api/workspaces/[workspaceId]/invitations.ts | 4 ++-- packages/lib/pricing.ts | 13 +++++-------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/apps/builder/src/features/workspace/components/MembersList.tsx b/apps/builder/src/features/workspace/components/MembersList.tsx index d4e6f3e2b..2050bb79d 100644 --- a/apps/builder/src/features/workspace/components/MembersList.tsx +++ b/apps/builder/src/features/workspace/components/MembersList.tsx @@ -97,8 +97,7 @@ export const MembersList = () => { !isSeatsLimitReached({ plan: workspace?.plan, customSeatsLimit: workspace?.customSeatsLimit, - existingMembersCount: currentMembersCount, - existingInvitationsCount: invitations.length, + existingMembersAndInvitationsCount: currentMembersCount, }) return ( diff --git a/apps/builder/src/pages/api/workspaces/[workspaceId]/invitations.ts b/apps/builder/src/pages/api/workspaces/[workspaceId]/invitations.ts index e75cf08b5..016f85ded 100644 --- a/apps/builder/src/pages/api/workspaces/[workspaceId]/invitations.ts +++ b/apps/builder/src/pages/api/workspaces/[workspaceId]/invitations.ts @@ -38,8 +38,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { ]) if ( isSeatsLimitReached({ - existingMembersCount, - existingInvitationsCount, + existingMembersAndInvitationsCount: + existingMembersCount + existingInvitationsCount, ...workspace, }) ) diff --git a/packages/lib/pricing.ts b/packages/lib/pricing.ts index 08c5f029a..91deac6ee 100644 --- a/packages/lib/pricing.ts +++ b/packages/lib/pricing.ts @@ -180,18 +180,15 @@ export const getSeatsLimit = ({ } export const isSeatsLimitReached = ({ - existingMembersCount, - existingInvitationsCount, + existingMembersAndInvitationsCount, plan, customSeatsLimit, -}: { existingMembersCount: number; existingInvitationsCount: number } & Pick< - Workspace, - 'plan' | 'customSeatsLimit' ->) => { +}: { + existingMembersAndInvitationsCount: number +} & Pick) => { const seatsLimit = getSeatsLimit({ plan, customSeatsLimit }) return ( - seatsLimit !== infinity && - seatsLimit <= existingMembersCount + existingInvitationsCount + seatsLimit !== infinity && seatsLimit <= existingMembersAndInvitationsCount ) }