Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

UI: settings/people

Aashish-Upadhyay-1018bafe73f04f8
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx
index 4f99fb20..35efec6b 100644
--- a/components/Sidebar.tsx
+++ b/components/Sidebar.tsx
@@ -52,7 +52,7 @@ export default function Sidebar() {
},
{
name: "Settings",
- href: "/settings/domains",
+ href: "/settings/people",
icon: SettingsIcon,
current: router.pathname.includes("settings"),
disabled: false,
@@ -227,7 +227,12 @@ export default function Sidebar() {
</Menu.Item>
<Menu.Item>
<p className="block px-3 py-1 text-sm leading-6 text-muted-foreground">
- Help? <a href="mailto:[email protected]" className="underline hover:text-muted-foreground/80">[email protected]</a>
+ Help?{" "}
+ <a
+ href="mailto:[email protected]"
+ className="underline hover:text-muted-foreground/80">
+ </a>
</p>
</Menu.Item>
<Menu.Item>
diff --git a/components/settings/navbar.tsx b/components/settings/navbar.tsx
index c0ca7c35..f5864fc2 100644
--- a/components/settings/navbar.tsx
+++ b/components/settings/navbar.tsx
@@ -1,15 +1,13 @@
-"use client";
-
import { cn } from "@/lib/utils";
import Link from "next/link";
-
const tabs = [
+ { name: "People", href: "/settings/people" },
{ name: "Domains", href: "/settings/domains" },
{ name: "Billing", href: "/settings/billing" },
];
-export default function Navbar({current}: {current?: string}) {
+export default function Navbar({ current }: { current?: string }) {
return (
<div className="p-4 sm:p-4 sm:m-4">
<div className="flex items-center justify-between mb-4 md:mb-8 lg:mb-12">
@@ -35,8 +33,7 @@ export default function Navbar({current}: {current?: string}) {
: "border-transparent text-muted-foreground hover:border-foreground hover:text-foreground",
"whitespace-nowrap border-b-2 py-4 px-1 text-sm font-medium"
)}
- aria-current={current === tab.name ? 'page' : undefined}
- >
+ aria-current={current === tab.name ? "page" : undefined}>
{tab.name}
</Link>
))}
@@ -45,4 +42,4 @@ export default function Navbar({current}: {current?: string}) {
</div>
</div>
);
-};
+}
diff --git a/lib/swr/use-team.ts b/lib/swr/use-team.ts
new file mode 100644
index 00000000..cbd64a7a
--- /dev/null
+++ b/lib/swr/use-team.ts
@@ -0,0 +1,23 @@
+import useSWR from "swr";
+import { useTeam } from "@/context/team-context";
+import { fetcher } from "@/lib/utils";
+import { TeamDetail } from "@/lib/types";
+
+export function useGetTeam() {
+ const teamInfo = useTeam();
+
+ const { data: team, error } = useSWR<TeamDetail>(
+ `/api/teams/${teamInfo?.currentTeam?.id}`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ dedupingInterval: 20000,
+ }
+ );
+
+ return {
+ team,
+ loading: team ? false : true,
+ error,
+ };
+}
diff --git a/lib/types.ts b/lib/types.ts
index 9511ee00..33c7b2da 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -153,3 +153,23 @@ export interface Team {
id: string;
name: string;
}
+
+export interface TeamDetail {
+ id: string;
+ name: string;
+ documents: {
+ owner: {
+ id: string;
+ name: string;
+ };
+ }[];
+ users: {
+ role: "Admin" | "Member";
+ teamId: string;
+ user: {
+ email: string;
+ name: string;
+ };
+ userId: string;
+ }[];
+}
diff --git a/pages/api/teams/[teamId]/index.ts b/pages/api/teams/[teamId]/index.ts
index 3f7bba17..05eb23ce 100644
--- a/pages/api/teams/[teamId]/index.ts
+++ b/pages/api/teams/[teamId]/index.ts
@@ -23,21 +23,27 @@ export default async function handle(
where: {
id: teamId,
},
- include: {
+ select: {
+ id: true,
+ name: true,
users: {
- include: {
- user: true,
+ select: {
+ role: true,
+ teamId: true,
+ userId: true,
+ user: {
+ select: {
+ email: true,
+ name: true,
+ },
+ },
},
},
documents: {
- include: {
+ select: {
owner: {
select: {
name: true,
- },
- },
- views: {
- select: {
id: true,
},
},
@@ -49,7 +55,7 @@ export default async function handle(
// check that the user is member of the team, otherwise return 403
const teamUsers = team?.users;
const isUserPartOfTeam = teamUsers?.some(
- (team) => team.userId === (session.user as CustomUser).id
+ (user) => user.userId === (session.user as CustomUser).id
);
if (!isUserPartOfTeam) {
return res.status(403).end("Unauthorized to access this team");
diff --git a/pages/documents/[id].tsx b/pages/documents/[id].tsx
index adc3a3b4..ac56e71f 100644
--- a/pages/documents/[id].tsx
+++ b/pages/documents/[id].tsx
@@ -12,7 +12,13 @@ import { useEffect, useRef, useState } from "react";
import { Button } from "@/components/ui/button";
import LoadingSpinner from "@/components/ui/loading-spinner";
import { toast } from "sonner";
-import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
import { useRouter } from "next/router";
import MoreVertical from "@/components/shared/icons/more-vertical";
@@ -20,8 +26,6 @@ export default function DocumentPage() {
const { document: prismaDocument, primaryVersion, error } = useDocument();
const router = useRouter();
- console.log(document, primaryVersion, error);
-
const [isLinkSheetOpen, setIsLinkSheetOpen] = useState<boolean>(false);
const [isEditingName, setIsEditingName] = useState<boolean>(false);
const [isFirstClick, setIsFirstClick] = useState<boolean>(false);
@@ -65,9 +69,8 @@ export default function DocumentPage() {
}
};
-
useEffect(() => {
- function handleClickOutside(event: { target: any; }) {
+ function handleClickOutside(event: { target: any }) {
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
setMenuOpen(false);
setIsFirstClick(false);
@@ -94,15 +97,15 @@ export default function DocumentPage() {
if (response.ok) {
setIsFirstClick(false);
setMenuOpen(false);
- router.push("/documents")
+ router.push("/documents");
toast.success("Document deleted successfully.");
} else {
const { message } = await response.json();
toast.error(message);
}
- }
+ };
- const handleMenuStateChange = (open: boolean ) => {
+ const handleMenuStateChange = (open: boolean) => {
if (isFirstClick) {
setMenuOpen(true); // Keep the dropdown open on the first click
return;
@@ -188,8 +191,7 @@ export default function DocumentPage() {
<div className="flex items-center gap-x-4">
<DropdownMenu
open={menuOpen}
- onOpenChange={handleMenuStateChange}
- >
+ onOpenChange={handleMenuStateChange}>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
@@ -202,8 +204,7 @@ export default function DocumentPage() {
className="text-destructive focus:bg-destructive focus:text-destructive-foreground"
onClick={(event) =>
handleButtonClick(event, prismaDocument.id)
- }
- >
+ }>
{isFirstClick ? "Really delete?" : "Delete document"}
</DropdownMenuItem>
</DropdownMenuContent>
diff --git a/pages/settings/people.tsx b/pages/settings/people.tsx
new file mode 100644
index 00000000..5754bd42
--- /dev/null
+++ b/pages/settings/people.tsx
@@ -0,0 +1,75 @@
+import AppLayout from "@/components/layouts/app";
+import Navbar from "@/components/settings/navbar";
+import { Button } from "@/components/ui/button";
+import MoreVertical from "@/components/shared/icons/more-vertical";
+import Folder from "@/components/shared/icons/folder";
+import { useGetTeam } from "@/lib/swr/use-team";
+
+export default function Billing() {
+ const { team } = useGetTeam();
+
+ const getUserDocumentCount = (userId: string) => {
+ const documents = team?.documents.filter(
+ (document) => document.owner.id === userId
+ );
+ return documents?.length;
+ };
+
+ return (
+ <AppLayout>
+ <Navbar current="People" />
+ <div className="p-4 sm:p-4 sm:m-4">
+ <div className="flex items-center justify-between mb-4 md:mb-8 lg:mb-12">
+ <div className="space-y-1">
+ <h3 className="text-2xl text-foreground font-semibold tracking-tight">
+ Team Members
+ </h3>
+ <p className="text-sm text-muted-foreground">
+ Manage your team members
+ </p>
+ </div>
+ </div>
+ <div>
+ <div className="flex justify-between items-center p-10 rounded-lg border border-border bg-secondary">
+ <div className="flex flex-col space-y-3">
+ <h2 className="text-xl font-medium">People</h2>
+ <p className="text-sm text-secondary-foreground">
+ Teammates that have access to this project.
+ </p>
+ </div>
+ <Button>Invite</Button>
+ </div>
+ </div>
+
+ <ul className="mt-6 border rounded-lg divide-y">
+ {team?.users.map((member) => (
+ <li className="flex py-4 px-10 justify-between items-center">
+ <div className="flex items-center gap-12">
+ <div className="space-y-1">
+ <h4 className="font-semibold text-sm">{member.user.name}</h4>
+ <p className="text-xs text-muted-foreground">
+ {member.user.email}
+ </p>
+ </div>
+ <div className="text-sm">
+ <div className="flex items-center gap-2">
+ <Folder />
+ <span className="text-xs text-foreground">
+ {getUserDocumentCount(member.userId)} documents
+ </span>
+ </div>
+ </div>
+ </div>
+ <div className="flex items-center gap-12">
+ <span className="text-sm text-foreground capitalize">
+ {member.role.toLowerCase()}
+ </span>
+ <MoreVertical className="w-4 h-4" />
+ </div>
+ </li>
+ ))}
+ </ul>
+ </div>
+ </AppLayout>
+ );
+}