Skip to content

Commit 84c8e86

Browse files
authored
Merge pull request #1529 from AshishViradiya153/171/addUsers
Added button in side bar for add user
2 parents 546638c + ac54fc1 commit 84c8e86

File tree

3 files changed

+60
-21
lines changed

3 files changed

+60
-21
lines changed

components/sidebar/team-switcher.tsx

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import * as React from "react";
44

5-
import { ChevronsUpDown, GalleryVerticalEndIcon, Plus } from "lucide-react";
5+
import { useLimits } from "@/ee/limits/swr-handler";
6+
import { PlanEnum } from "@/ee/stripe/constants";
7+
import { ChevronsUpDown, UserRoundPlusIcon } from "lucide-react";
68

79
import {
810
DropdownMenu,
911
DropdownMenuContent,
1012
DropdownMenuItem,
1113
DropdownMenuLabel,
12-
DropdownMenuSeparator,
13-
DropdownMenuShortcut,
1414
DropdownMenuTrigger,
1515
} from "@/components/ui/dropdown-menu";
1616
import {
@@ -23,6 +23,9 @@ import {
2323
import { Team } from "@/lib/types";
2424
import { cn } from "@/lib/utils";
2525

26+
import { AddSeatModal } from "../billing/add-seat-modal";
27+
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
28+
import { AddTeamMembers } from "../teams/add-team-member-modal";
2629
import { Avatar, AvatarFallback } from "../ui/avatar";
2730

2831
export function TeamSwitcher({
@@ -34,7 +37,12 @@ export function TeamSwitcher({
3437
teams: Team[];
3538
setCurrentTeam: (team: Team) => void;
3639
}) {
40+
const [isTeamMemberInviteModalOpen, setTeamMemberInviteModalOpen] =
41+
React.useState<boolean>(false);
42+
const [isAddSeatModalOpen, setAddSeatModalOpen] =
43+
React.useState<boolean>(false);
3744
const { isMobile } = useSidebar();
45+
const { canAddUsers } = useLimits();
3846

3947
const switchTeam = (team: Team) => {
4048
localStorage.setItem("currentTeamId", team.id);
@@ -44,13 +52,13 @@ export function TeamSwitcher({
4452
if (!activeTeam) return null;
4553

4654
return (
47-
<SidebarMenu>
55+
<SidebarMenu className="flex flex-row items-center gap-1 group-data-[collapsible=icon]:flex-col group-data-[collapsible=icon]:gap-1.5">
4856
<SidebarMenuItem>
4957
<DropdownMenu>
5058
<DropdownMenuTrigger asChild>
5159
<SidebarMenuButton
5260
size="lg"
53-
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground border"
61+
className="border data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
5462
>
5563
<Avatar className="size-8 rounded">
5664
<AvatarFallback className="rounded">
@@ -103,6 +111,42 @@ export function TeamSwitcher({
103111
</DropdownMenuContent>
104112
</DropdownMenu>
105113
</SidebarMenuItem>
114+
<SidebarMenuItem>
115+
{activeTeam.plan?.includes("free") ? (
116+
<UpgradePlanModal
117+
clickedPlan={PlanEnum.Pro}
118+
trigger={"invite_team_members"}
119+
>
120+
<SidebarMenuButton
121+
size="lg"
122+
className="size-12 justify-center border data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground group-data-[collapsible=icon]:hidden"
123+
>
124+
<UserRoundPlusIcon className="!size-5" strokeWidth={1.5} />
125+
</SidebarMenuButton>
126+
</UpgradePlanModal>
127+
) : canAddUsers ? (
128+
<AddTeamMembers
129+
open={isTeamMemberInviteModalOpen}
130+
setOpen={setTeamMemberInviteModalOpen}
131+
>
132+
<SidebarMenuButton
133+
size="lg"
134+
className="size-12 justify-center border data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground group-data-[collapsible=icon]:hidden"
135+
>
136+
<UserRoundPlusIcon className="!size-5" strokeWidth={1.5} />
137+
</SidebarMenuButton>
138+
</AddTeamMembers>
139+
) : (
140+
<AddSeatModal open={isAddSeatModalOpen} setOpen={setAddSeatModalOpen}>
141+
<SidebarMenuButton
142+
size="lg"
143+
className="size-12 justify-center border data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground group-data-[collapsible=icon]:hidden"
144+
>
145+
<UserRoundPlusIcon className="!size-5" strokeWidth={1.5} />
146+
</SidebarMenuButton>
147+
</AddSeatModal>
148+
)}
149+
</SidebarMenuItem>
106150
</SidebarMenu>
107151
);
108152
}

ee/limits/server.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,9 @@ export async function getLimits({
7474
_count: {
7575
select: {
7676
documents: true,
77-
},
78-
},
79-
documents: {
80-
select: {
81-
_count: {
82-
select: {
83-
links: true,
84-
},
85-
},
77+
links: true,
78+
users: true,
79+
invitations: true,
8680
},
8781
},
8882
},
@@ -93,10 +87,8 @@ export async function getLimits({
9387
}
9488

9589
const documentCount = team._count.documents;
96-
const linkCount = team.documents.reduce(
97-
(sum, doc) => sum + doc._count.links,
98-
0,
99-
);
90+
const linkCount = team._count.links;
91+
const userCount = team._count.users + team._count.invitations;
10092

10193
// parse the limits json with zod and return the limits
10294
// {datarooms: 1, users: 1, domains: 1, customDomainOnPro: boolean, customDomainInDataroom: boolean}
@@ -108,7 +100,7 @@ export async function getLimits({
108100
if (isFreePlan(team.plan)) {
109101
return {
110102
...parsedData,
111-
usage: { documents: documentCount, links: linkCount },
103+
usage: { documents: documentCount, links: linkCount, users: userCount },
112104
};
113105
} else {
114106
return {
@@ -117,7 +109,7 @@ export async function getLimits({
117109
links: parsedData.links === 50 ? Infinity : parsedData.links,
118110
documents:
119111
parsedData.documents === 50 ? Infinity : parsedData.documents,
120-
usage: { documents: documentCount, links: linkCount },
112+
usage: { documents: documentCount, links: linkCount, users: userCount },
121113
};
122114
}
123115
} catch (error) {
@@ -127,7 +119,7 @@ export async function getLimits({
127119

128120
return {
129121
...defaultLimits,
130-
usage: { documents: documentCount, links: linkCount },
122+
usage: { documents: documentCount, links: linkCount, users: userCount },
131123
};
132124
}
133125
}

ee/limits/swr-handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type LimitProps = {
1616
usage: {
1717
documents: number;
1818
links: number;
19+
users: number;
1920
};
2021
fileSizeLimits:
2122
| {
@@ -44,11 +45,13 @@ export function useLimits() {
4445
? data?.usage?.documents < data?.documents
4546
: true;
4647
const canAddLinks = data?.links ? data?.usage?.links < data?.links : true;
48+
const canAddUsers = data?.users ? data?.usage?.users < data?.users : true;
4749

4850
return {
4951
limits: data,
5052
canAddDocuments,
5153
canAddLinks,
54+
canAddUsers,
5255
error,
5356
loading: !data && !error,
5457
};

0 commit comments

Comments
 (0)