Skip to content

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

enhace: enhaced the documents page by redesigning the components

ashrafchowdury088a5fc1d2f9
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx
index cffa2a5f..f6ad7920 100644
--- a/components/Sidebar.tsx
+++ b/components/Sidebar.tsx
@@ -1,38 +1,67 @@
-import { Fragment, useEffect, useState } from "react";
-import { Menu, Dialog, Transition } from "@headlessui/react";
-import { signOut, useSession } from "next-auth/react";
-import HomeIcon from "@/components/shared/icons/home";
+import { useEffect, useState } from "react";
+import { useSession } from "next-auth/react";
import FolderIcon from "@/components/shared/icons/folder";
import PieChartIcon from "@/components/shared/icons/pie-chart";
import SettingsIcon from "@/components/shared/icons/settings";
import MenuIcon from "@/components/shared/icons/menu";
-import ChevronUp from "@/components/shared/icons/chevron-up";
-import X from "@/components/shared/icons/x";
-import Link from "next/link";
import { cn } from "@/lib/utils";
import { useRouter } from "next/router";
-import { ModeToggle } from "./theme-toggle";
-import LoadingSpinner from "./ui/loading-spinner";
import Banner from "./banner";
import ProBanner from "./billing/pro-banner";
import Cookies from "js-cookie";
import { usePlan } from "@/lib/swr/use-billing";
-import Image from "next/image";
import SelectTeam from "./teams/select-team";
import { TeamContextType, initialState, useTeam } from "@/context/team-context";
-import UserRound from "./shared/icons/user-round";
-import { Skeleton } from "@/components/ui/skeleton";
+import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
+import ProfileMenu from "./profile-menu";
export default function Sidebar() {
+ return (
+ <>
+ {/* Static sidebar for desktop */}
+ <SidebarComponent className="hidden lg:flex" />
+
+ {/* sidebar for mobile */}
+ <nav>
+ <div className="sticky top-0 z-40 mb-1 flex h-14 shrink-0 items-center gap-x-4 border-b border-gray-50/90 bg-gray-50 dark:border-black/10 dark:bg-black/95 px-4 sm:gap-x-6 sm:px-6 lg:px-8 lg:hidden">
+ <Sheet>
+ <SheetTrigger asChild>
+ <button className="-m-2.5 p-2.5 text-muted-foreground lg:hidden">
+ <MenuIcon className="h-6 w-6" aria-hidden="true" />
+ </button>
+ </SheetTrigger>
+ <SheetContent side="left" className="w-[280px] sm:w-[300px] lg:hidden p-0 m-0">
+ <SidebarComponent className="flex" />
+ </SheetContent>
+ </Sheet>
+ <div className="flex flex-1 gap-x-4 self-stretch items-center lg:gap-x-6 justify-end">
+ <ProfileMenu size="small" className="mr-3 mt-1.5" />
+ </div>
+ </div>
+ </nav>
+ </>
+ );
+}
+
+export const SidebarComponent = ({ className }: { className?: string }) => {
+ const [showProBanner, setShowProBanner] = useState<boolean | null>(null);
const { data: session, status } = useSession();
const { plan, loading } = usePlan();
- const [sidebarOpen, setSidebarOpen] = useState<boolean>(false);
- const [showProBanner, setShowProBanner] = useState<boolean | null>(null);
- const router = useRouter();
+ const router = useRouter();
const { currentTeam, teams, isLoading }: TeamContextType =
useTeam() || initialState;
+ useEffect(() => {
+ if (Cookies.get("hideProBanner") !== "pro-banner") {
+ setShowProBanner(true);
+ } else {
+ setShowProBanner(false);
+ }
+ }, []);
+
+ const userPlan = plan && plan.plan;
+
const navigation = [
// {
// name: "Overview",
@@ -64,373 +93,74 @@ export default function Sidebar() {
},
];
- useEffect(() => {
- if (Cookies.get("hideProBanner") !== "pro-banner") {
- setShowProBanner(true);
- } else {
- setShowProBanner(false);
- }
- }, []);
-
- if (status === "loading" && loading) return <Sidebar.Skeleton />;
-
- const userPlan = plan && plan.plan;
-
return (
- <>
- <Transition.Root show={sidebarOpen} as={Fragment}>
- <Dialog
- as="div"
- className="relative z-50 xl:hidden"
- onClose={setSidebarOpen}
- >
- <Transition.Child
- as={Fragment}
- enter="transition-opacity ease-linear duration-300"
- enterFrom="opacity-0"
- enterTo="opacity-100"
- leave="transition-opacity ease-linear duration-300"
- leaveFrom="opacity-100"
- leaveTo="opacity-0"
- >
- <div className="fixed inset-0 bg-background/80" />
- </Transition.Child>
-
- <div className="fixed inset-0 flex">
- <Transition.Child
- as={Fragment}
- enter="transition ease-in-out duration-300 transform"
- enterFrom="-translate-x-full"
- enterTo="translate-x-0"
- leave="transition ease-in-out duration-300 transform"
- leaveFrom="translate-x-0"
- leaveTo="-translate-x-full"
- >
- <Dialog.Panel className="relative mr-16 flex w-full max-w-xs flex-1">
- <Transition.Child
- as={Fragment}
- enter="ease-in-out duration-300"
- enterFrom="opacity-0"
- enterTo="opacity-100"
- leave="ease-in-out duration-300"
- leaveFrom="opacity-100"
- leaveTo="opacity-0"
- >
- <div className="absolute left-full top-0 flex w-16 justify-center pt-5">
- <button
- type="button"
- className="-m-2.5 p-2.5"
- onClick={() => setSidebarOpen(false)}
- >
- <span className="sr-only">Close sidebar</span>
- <X
- className="h-6 w-6 text-foreground"
- aria-hidden="true"
- />
- </button>
- </div>
- </Transition.Child>
- {/* Sidebar for mobile component, swap this element with another sidebar if you like */}
- <div className="flex grow flex-col gap-y-5 overflow-y-auto bg-gray-50 dark:bg-black px-6 ring-1 ring-foreground/10">
- <div className="flex h-16 shrink-0 items-center">
- <p className="text-2xl font-bold tracking-tighter text-black dark:text-white flex items-center">
- Papermark{" "}
- {userPlan == "pro" ? (
- <span className="bg-background text-foreground ring-1 ring-gray-800 rounded-full px-2.5 py-1 text-xs ml-4">
- Pro
- </span>
- ) : null}
- </p>
- </div>
- <nav className="flex flex-1 flex-col">
- <SelectTeam
- currentTeam={currentTeam}
- teams={teams}
- isLoading={isLoading}
- setCurrentTeam={() => {}}
- />
- <ul role="list" className="flex flex-1 flex-col gap-y-7">
- <li>
- <ul role="list" className="-mx-2 space-y-1">
- {navigation.map((item) => (
- <li key={item.name}>
- <button
- onClick={() => router.push(item.href)}
- className={cn(
- item.current
- ? "bg-gray-200 dark:bg-secondary text-secondary-foreground font-semibold"
- : "text-muted-foreground hover:text-foreground hover:bg-gray-200 hover:dark:bg-muted",
- "group flex gap-x-3 items-center rounded-md p-2 text-sm leading-6 w-full disabled:hover:bg-transparent disabled:text-muted-foreground disabled:cursor-default",
- )}
- disabled={item.disabled}
- >
- <item.icon
- className="h-5 w-5 shrink-0"
- aria-hidden="true"
- />
- {item.name}
- </button>
- </li>
- ))}
- </ul>
- </li>
- </ul>
- </nav>
- </div>
- </Dialog.Panel>
- </Transition.Child>
- </div>
- </Dialog>
- </Transition.Root>
-
- {/* Static sidebar for desktop */}
- <div className="hidden lg:fixed lg:inset-y-0 lg:z-50 lg:flex lg:w-72 lg:flex-col">
- {/* Sidebar component, swap this element with another sidebar if you like */}
- <div className="flex grow flex-col gap-y-5 overflow-y-auto bg-gray-50 dark:bg-black px-6">
- <div className="flex h-16 shrink-0 items-center">
- <p className="text-2xl font-bold tracking-tighter text-black dark:text-white flex items-center">
- Papermark{" "}
- {userPlan == "pro" ? (
- <span className="bg-background text-foreground ring-1 ring-gray-800 rounded-full px-2.5 py-1 text-xs ml-4">
- Pro
- </span>
- ) : null}
- </p>
- </div>
- <nav className="flex flex-1 flex-col">
- <SelectTeam
- currentTeam={currentTeam}
- teams={teams}
- isLoading={isLoading}
- setCurrentTeam={() => {}}
- />
- <ul role="list" className="flex flex-1 flex-col gap-y-7">
- <li>
- <ul role="list" className="-mx-2 space-y-1">
- {navigation.map((item) => (
- <li key={item.name}>
- <button
- onClick={() => router.push(item.href)}
- className={cn(
- item.current
- ? "bg-gray-200 dark:bg-secondary text-secondary-foreground font-semibold"
- : "text-muted-foreground hover:text-foreground hover:bg-gray-200 hover:dark:bg-muted",
- "group flex gap-x-3 items-center rounded-md p-2 text-sm leading-6 w-full disabled:hover:bg-transparent disabled:text-muted-foreground disabled:cursor-default",
- )}
- disabled={item.disabled}
- >
- <item.icon
- className="h-5 w-5 shrink-0"
- aria-hidden="true"
- />
- {item.name}
- </button>
- </li>
- ))}
- </ul>
- </li>
- <li className="-mx-2 mt-auto mb-4">
- {/* if user is on trial show banner,
- * if user is pro show nothing,
- * if user is free and showProBanner is true show pro banner
- */}
- {userPlan === "trial" && session ? (
- <Banner session={session} />
- ) : null}
- {userPlan === "pro" && null}
- {userPlan === "free" && showProBanner ? (
- <ProBanner setShowProBanner={setShowProBanner} />
- ) : null}
- <div className="flex justify-between items-center space-x-2">
- <Menu as="div" className="relative grow">
- <Menu.Button className="flex items-center group rounded-md gap-x-3 p-2 w-full text-sm font-semibold leading-6 text-foreground hover:bg-gray-200 hover:dark:bg-secondary">
- {session?.user?.image ? (
- <Image
- className="h-8 w-8 rounded-full bg-secondary"
- src={session?.user?.image}
- width={32}
- height={32}
- alt={`Profile picture of ${session?.user?.name}`}
- />
- ) : (
- <div className="">
- <UserRound className="h-8 w-8 p-1 rounded-full ring-1 ring-muted-foreground/50 bg-secondary" />
- </div>
- )}
- <span className="flex items-center w-full justify-between">
- <span className="sr-only">Your profile</span>
- <span aria-hidden="true" className="line-clamp-2">
- {session?.user?.name
- ? session?.user?.name
- : session?.user?.email?.split("@")[0]}
- </span>
- <ChevronUp
- className="ml-2 h-5 w-5 text-muted-foreground shrink-0"
- aria-hidden="true"
- />
- </span>
- </Menu.Button>
- <Transition
- as={Fragment}
- enter="transition ease-out duration-100"
- enterFrom="transform opacity-0 scale-95"
- enterTo="transform opacity-100 scale-100"
- leave="transition ease-in duration-75"
- leaveFrom="transform opacity-100 scale-100"
- leaveTo="transform opacity-0 scale-95"
- >
- <Menu.Items className="absolute left-0 z-10 bottom-0 mb-14 w-full origin-bottom-left rounded-md bg-gray-100 dark:bg-primary-foreground py-2 focus:outline-none">
- {session ? (
- <>
- <Menu.Item>
- <div className="w-full">
- <p className="block px-3 py-1 text-sm leading-6 text-muted-foreground">
- {session?.user?.email}
- </p>
- </div>
- </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"
- >
- </a>
- </p>
- </Menu.Item>
- <Menu.Item>
- <Link
- onClick={() =>
- signOut({
- callbackUrl: `${window.location.origin}`,
- })
- }
- className="block px-3 py-1 text-sm leading-6 text-foreground hover:bg-gray-200 hover:dark:bg-muted"
- href={""}
- >
- Sign Out
- </Link>
- </Menu.Item>
- </>
- ) : null}
- </Menu.Items>
- </Transition>
- </Menu>
- <ModeToggle />
- </div>
- </li>
- </ul>
- </nav>
+ <aside
+ className={cn("w-full lg:w-[380px] flex flex-col relative", className)}
+ >
+ {/* Sidebar component, swap this element with another sidebar if you like */}
+ <div className="flex grow flex-col gap-y-4 overflow-y-auto bg-gray-50 dark:bg-black px-4 lg:px-6 pt-4 lg:pt-6">
+ <div className="flex h-16 shrink-0 items-center space-x-3">
+ <p className="text-2xl font-bold tracking-tighter text-black dark:text-white flex items-center">
+ Papermark{" "}
+ {userPlan == "pro" ? (
+ <span className="bg-background text-foreground ring-1 ring-gray-800 rounded-full px-2.5 py-1 text-xs ml-4">
+ Pro
+ </span>
+ ) : null}
+ </p>
</div>
- </div>
- <div className="lg:pl-72">
- {/* Navbar */}
- <div className="sticky top-0 z-40 mb-1 flex h-14 shrink-0 items-center gap-x-4 border-b border-gray-50/90 bg-gray-50 dark:border-black/10 dark:bg-black/95 px-4 sm:gap-x-6 sm:px-6 lg:px-8 lg:hidden">
- <button
- type="button"
- className="-m-2.5 p-2.5 text-muted-foreground lg:hidden"
- onClick={() => setSidebarOpen(true)}
- >
- <span className="sr-only">Open sidebar</span>
- <MenuIcon className="h-6 w-6" aria-hidden="true" />
- </button>
+ <nav className="flex flex-1 flex-col">
+ <SelectTeam
+ currentTeam={currentTeam}
+ teams={teams}
+ isLoading={isLoading}
+ setCurrentTeam={() => {}}
+ />
- <div className="flex flex-1 gap-x-4 self-stretch items-center lg:gap-x-6 justify-end">
- <div className="flex items-center gap-x-4 lg:gap-x-6">
- {/* Profile dropdown */}
- <Menu as="div" className="relative">
- <Menu.Button className="-m-1.5 flex items-center p-1.5">
- <span className="sr-only">Open user menu</span>
- {session?.user?.image ? (
- <Image
- className="h-8 w-8 rounded-full bg-secondary"
- src={session?.user?.image}
- width={32}
- height={32}
- alt={`Profile picture of ${session?.user?.name}`}
- />
- ) : (
- <div className="">
- <UserRound className="h-8 w-8 p-1 rounded-full ring-1 ring-muted-foreground/50 bg-secondary" />
- </div>
+ <section className="flex flex-1 flex-col gap-y-7 !mt-5">
+ <div className="space-y-2">
+ {navigation.map((item) => (
+ <button
+ key={item.name}
+ onClick={() => router.push(item.href)}
+ disabled={item.disabled}
+ className={cn(
+ item.current
+ ? "bg-gray-200 dark:bg-secondary text-secondary-foreground font-semibold"
+ : "text-muted-foreground hover:text-foreground hover:bg-gray-200 hover:dark:bg-muted duration-200",
+ "group flex gap-x-3 items-center rounded-md px-3 py-2 text-sm leading-6 w-full disabled:hover:bg-transparent disabled:text-muted-foreground disabled:cursor-default",
)}
- </Menu.Button>
- <Transition
- as={Fragment}
- enter="transition ease-out duration-100"
- enterFrom="transform opacity-0 scale-95"
- enterTo="transform opacity-100 scale-100"
- leave="transition ease-in duration-75"
- leaveFrom="transform opacity-100 scale-100"
- leaveTo="transform opacity-0 scale-95"
>
- <Menu.Items className="absolute right-0 z-10 mt-2.5 w-fit origin-top-right rounded-md bg-primary-foreground shadow-lg py-2 ring-1 ring-primary-foreground/5 focus:outline-none">
- {session ? (
- <>
- <Menu.Item>
- <p className="block px-3 py-1 text-sm leading-6 text-muted-foreground">
- {session?.user?.email}
- </p>
- </Menu.Item>
- <Menu.Item>
- <Link
- onClick={() =>
- signOut({
- callbackUrl: `${window.location.origin}`,
- })
- }
- className="block px-3 py-1 text-sm leading-6 text-foreground hover:bg-gray-200 hover:dark:bg-muted"
- href={""}
- >
- Sign Out
- </Link>
- </Menu.Item>
- </>
- ) : null}
- </Menu.Items>
- </Transition>
- </Menu>
- <ModeToggle />
+ <item.icon className="h-5 w-5 shrink-0" aria-hidden="true" />
+ {item.name}
+ </button>
+ ))}
</div>
- </div>
- </div>
- </div>
- </>
- );
-}
-Sidebar.Skeleton = function SidebarSkeleton() {
- return (
- <div className="hidden lg:fixed lg:inset-y-0 lg:z-50 lg:flex lg:w-72 lg:flex-col">
- <div className="flex grow flex-col gap-y-6 overflow-y-auto bg-gray-50 dark:bg-black px-6">
- <div className="flex h-16 shrink-0 items-center">
- <Skeleton className="w-40 h-9" />
- </div>
- <div className="flex flex-1 flex-col space-y-7">
- <div className="space-y-2">
- <Skeleton className="w-24 h-6" />
- <Skeleton className="w-52 h-9" />
- </div>
- <div className="mt-4 flex flex-1 flex-col gap-y-7 mx-2">
- <div>
- <div className="-mx-2 space-y-3">
- <Skeleton className="w-4/5 h-9" />
- <Skeleton className="w-4/5 h-9" />
- <Skeleton className="w-4/5 h-9" />
- <Skeleton className="w-4/5 h-9" />
- </div>
- </div>
<div className="-mx-2 mt-auto mb-4">
- <div className="flex justify-between items-center space-x-2">
- <Skeleton className="w-full h-9" />
+ {/* if user is on trial show banner,
+ * if user is pro show nothing,
+ * if user is free and showProBanner is true show pro banner
+ */}
+ {userPlan === "trial" && session ? (
+ <Banner session={session} />
+ ) : null}
+ {userPlan === "pro" && null}
+ {userPlan === "free" && showProBanner ? (
+ <ProBanner setShowProBanner={setShowProBanner} />
+ ) : null}
+
+ <div className="w-full hidden lg:block">
+ <ProfileMenu
+ size="large"
+ className="lg:w-[240px] xl:w-[270px]"
+ />
</div>
</div>
- </div>
- </div>
+ </section>
+ </nav>
</div>
- </div>
+ </aside>
);
};
diff --git a/components/documents/document-card.tsx b/components/documents/document-card.tsx
index fadf8d48..32252ec3 100644
--- a/components/documents/document-card.tsx
+++ b/components/documents/document-card.tsx
@@ -1,19 +1,32 @@
import { copyToClipboard, nFormatter, timeAgo } from "@/lib/utils";
import Link from "next/link";
import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
-import Copy from "@/components/shared/icons/copy";
+import { TeamContextType } from "@/context/team-context";
import BarChart from "@/components/shared/icons/bar-chart";
import Image from "next/image";
import NotionIcon from "@/components/shared/icons/notion";
import PapermarkSparkle from "../shared/icons/papermark-sparkle";
import { toast } from "sonner";
import { useRouter } from "next/router";
+import { Button } from "../ui/button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "../ui/dropdown-menu";
+import { TrashIcon, Link as LinkIcon, MoreVertical } from "lucide-react";
+type DocumentsCardProps = {
+ document: DocumentWithLinksAndLinkCountAndViewCount;
+ teamInfo: TeamContextType | null;
+};
export default function DocumentsCard({
document,
-}: {
- document: DocumentWithLinksAndLinkCountAndViewCount;
-}) {
+ teamInfo,
+}: DocumentsCardProps) {
const router = useRouter();
function handleCopyToClipboard(id: string) {
@@ -49,10 +62,26 @@ export default function DocumentsCard({
}
};
+ const handleDeleteDocument = async (documentId: string) => {
+ const response = await fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/documents/${documentId}`,
+ {
+ method: "DELETE",
+ },
+ );
+
+ if (response.ok) {
+ toast.success("Document deleted successfully.");
+ } else {
+ const { message } = await response.json();
+ toast.error(message);
+ }
+ };
+
return (
<li className="group/row relative rounded-lg p-3 border-0 dark:bg-secondary ring-1 ring-gray-200 dark:ring-gray-700 transition-all hover:ring-gray-400 hover:dark:ring-gray-500 hover:bg-secondary sm:p-4 flex justify-between items-center">
- <div className="min-w-0 flex shrink items-center space-x-4">
- <div className="w-8 mx-1 text-center flex justify-center items-center">
+ <div className="min-w-0 flex shrink items-center space-x-2 sm:space-x-4">
+ <div className="w-8 mx-0.5 sm:mx-1 text-center flex justify-center items-center">
{document.type === "notion" ? (
<NotionIcon className="w-8 h-8" />
) : (
@@ -65,33 +94,35 @@ export default function DocumentsCard({
/>
)}
</div>
+
<div className="flex-col">
<div className="flex items-center">
- <h2 className="min-w-0 text-sm font-semibold leading-6 text-foreground truncate max-w-[240px] sm:max-w-md">
- <Link href={`/documents/${document.id}`}>
- <span className="">{document.name}</span>
+ <h2 className="min-w-0 text-sm font-semibold leading-6 text-foreground truncate max-w-[150px] sm:max-w-md">
+ <Link
+ href={`/documents/${document.id}`}
+ className="truncate w-full"
+ >
+ <span>{document.name}</span>
<span className="absolute inset-0" />
</Link>
</h2>
<div className="flex ml-2">
<button
- className="group rounded-full bg-gray-200 dark:bg-gray-700 z-10 p-1.5 transition-all duration-75 hover:scale-105 hover:bg-emerald-100 hover:dark:bg-emerald-200 active:scale-95"
+ className="group rounded-md bg-gray-200 dark:bg-gray-700 z-10 p-1 transition-all duration-75 hover:scale-105 hover:bg-emerald-100 hover:dark:bg-emerald-200 active:scale-95"
onClick={() => handleCopyToClipboard(document.links[0].id)}
title="Copy to clipboard"
>
- <Copy
- className="text-gray-400 group-hover:text-emerald-700"
- aria-hidden="true"
- />
+ <LinkIcon className="w-3 h-3 text-gray-400 group-hover:text-emerald-700" />
</button>
</div>
</div>
<div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-muted-foreground">
<p className="truncate">{timeAgo(document.createdAt)}</p>
<p>•</p>
- <p className="truncate">{`${document._count.links} ${
- document._count.links === 1 ? "Link" : "Links"
- }`}</p>
+ <p className="truncate">
+ {document._count.links}{" "}
+ {document._count.links === 1 ? "Link" : "Links"}
+ </p>
{document._count.versions > 1 ? (
<>
<p>•</p>
@@ -109,7 +140,7 @@ export default function DocumentsCard({
e.stopPropagation();
activateOrRedirectAssistant();
}}
- className="group/button flex items-center z-10 space-x-1 rounded-md ring-1 ring-gray-200 dark:ring-gray-700 px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-95"
+ className="group/button flex items-center z-10 space-x-1 rounded-md ring-1 ring-gray-200 dark:ring-gray-700 px-1 sm:px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-95"
>
<PapermarkSparkle className="h-4 w-4 text-gray-400 group-hover/row:text-foreground group-hover/row:animate-pulse group-hover/button:text-foreground group-hover/button:animate-none" />
<span className="whitespace-nowrap text-sm ml-1 hidden sm:inline-block text-gray-400 group-hover/button:text-foreground">
@@ -123,14 +154,39 @@ export default function DocumentsCard({
e.stopPropagation();
}}
href={`/documents/${document.id}`}
- className="flex items-center z-10 space-x-1 rounded-md bg-gray-200 dark:bg-gray-700 px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
+ className="flex items-center z-10 space-x-1 rounded-md bg-gray-200 dark:bg-gray-700 px-1.5 sm:px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
>
- <BarChart className="h-4 w-4 text-muted-foreground" />
- <p className="whitespace-nowrap text-sm text-muted-foreground">
+ <BarChart className="h-3 sm:h-4 w-3 sm:w-4 text-muted-foreground" />
+ <p className="whitespace-nowrap text-xs sm:text-sm text-muted-foreground">
{nFormatter(document._count.views)}
<span className="ml-1 hidden sm:inline-block">views</span>
</p>
</Link>
+
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ size="icon"
+ variant="ghost"
+ className="w-6 sm:w-7 h-6 sm:h-7 z-10 hover:bg-background duration-200 focus:!outline-none"
+ >
+ <MoreVertical className="w-4 h-4 text-gray-400" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className="w-36 !rounded-md" align="end">
+ <DropdownMenuLabel className="text-sm text-gray-500 !py-[3px]">
+ Menu
+ </DropdownMenuLabel>
+ <DropdownMenuSeparator />
+
+ <DropdownMenuItem
+ onClick={() => handleDeleteDocument(document.id)}
+ className="flex items-center hover:!bg-red-500 hover:opacity-80 duration-200 cursor-pointer"
+ >
+ <TrashIcon className="w-4 h-4 mr-2" /> Delete Doc
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
</div>
</li>
);
diff --git a/components/layouts/app.tsx b/components/layouts/app.tsx
index b5e19975..4d2a19b8 100644
--- a/components/layouts/app.tsx
+++ b/components/layouts/app.tsx
@@ -5,7 +5,7 @@ export default function AppLayout({ children }: { children: React.ReactNode }) {
<div>
<div className="flex flex-col lg:flex-row min-h-screen bg-gray-50 dark:bg-black">
<Sidebar />
- <main className="lg:m-2 grow w-full bg-white dark:bg-gray-900 rounded-xl ring-1 ring-gray-200 dark:ring-gray-800">
+ <main className="grow w-full bg-white dark:bg-gray-900 ring-gray-200 dark:ring-gray-800">
{children}
</main>
</div>
diff --git a/components/profile-menu.tsx b/components/profile-menu.tsx
new file mode 100644
index 00000000..fe2341fa
--- /dev/null
+++ b/components/profile-menu.tsx
@@ -0,0 +1,102 @@
+import { signOut, useSession } from "next-auth/react";
+import ChevronUp from "@/components/shared/icons/chevron-up";
+import Link from "next/link";
+import Image from "next/image";
+import UserRound from "./shared/icons/user-round";
+import { Skeleton } from "@/components/ui/skeleton";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { HelpCircle, LogOut } from "lucide-react";
+import { cn } from "@/lib/utils";
+
+type ProfileMenuProps = {
+ className?: string;
+ size: "large" | "small";
+};
+
+const ProfileMenu = ({ className, size }: ProfileMenuProps) => {
+ const { data: session, status } = useSession();
+
+ const isSize = size === "large";
+ return (
+ <div className="flex justify-between items-center space-x-2">
+ {status === "loading" ? (
+ <div className="w-full flex items-center rounded-md gap-x-3 p-2">
+ <Skeleton className="h-8 w-9 rounded-full" />
+ {isSize && <Skeleton className="h-7 w-full" />}
+ </div>
+ ) : (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild className="w-full">
+ <div className="w-full flex items-center group rounded-full lg:rounded-md lg:gap-x-3 lg:p-2 text-sm font-semibold leading-6 text-foreground hover:bg-gray-200 hover:dark:bg-secondary">
+ {session?.user?.image ? (
+ <Image
+ className="h-7 w-7 rounded-full bg-secondary"
+ src={session?.user?.image}
+ width={30}
+ height={30}
+ alt={`Profile picture of ${session?.user?.name}`}
+ loading="lazy"
+ />
+ ) : (
+ <UserRound className="h-7 w-7 p-1 rounded-full ring-1 ring-muted-foreground/50 bg-secondary" />
+ )}
+ {isSize && (
+ <span className="flex items-center w-full justify-between">
+ <span className="sr-only">Your profile</span>
+ <span aria-hidden="true" className="line-clamp-2">
+ {session?.user?.name
+ ? session?.user?.name
+ : session?.user?.email?.split("@")[0]}
+ </span>
+ <ChevronUp
+ className="ml-2 h-5 w-5 text-muted-foreground shrink-0"
+ aria-hidden="true"
+ />
+ </span>
+ )}
+ </div>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className={cn("p-0 pb-2", className)}>
+ {session ? (
+ <>
+ <DropdownMenuLabel className="px-3 !py-[3px] mt-2 text-sm text-muted-foreground truncate">
+ {session?.user?.email}
+ </DropdownMenuLabel>
+ <DropdownMenuSeparator className="!my-2" />
+
+ <a
+ href="mailto:[email protected]"
+ className="flex items-center px-3 py-2 mb-1 text-sm hover:bg-muted duration-200"
+ >
+ <HelpCircle className="w-4 h-4 mr-2" />
+ Need Help?
+ </a>
+
+ <Link
+ onClick={() =>
+ signOut({
+ callbackUrl: `${window.location.origin}`,
+ })
+ }
+ className="flex items-center px-3 py-2 text-sm hover:bg-muted duration-200"
+ href={""}
+ >
+ <LogOut className="w-4 h-4 mr-2" />
+ Sign Out
+ </Link>
+ </>
+ ) : null}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
+ </div>
+ );
+};
+
+export default ProfileMenu;
diff --git a/components/teams/select-team.tsx b/components/teams/select-team.tsx
index d53c0d7b..fbcdf7c3 100644
--- a/components/teams/select-team.tsx
+++ b/components/teams/select-team.tsx
@@ -1,33 +1,22 @@
-import React, { useEffect, useRef, useState } from "react";
import { Check, Loader, PlusIcon } from "lucide-react";
import { TeamContextType, useTeam } from "@/context/team-context";
import { ChevronUpDownIcon } from "@heroicons/react/20/solid";
import { Team } from "@/lib/types";
import { useRouter } from "next/router";
import Link from "next/link";
+import { Avatar, AvatarFallback } from "@/components/ui/avatar";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { cn } from "@/lib/utils";
const SelectTeam = ({ teams, currentTeam, isLoading }: TeamContextType) => {
- const [selectTeamOpen, setSelectTeamOpen] = useState<boolean>(false);
- const ref = useRef<HTMLDivElement>(null);
const router = useRouter();
const userTeam = useTeam();
- useEffect(() => {
- function handleDocumentClick(event: MouseEvent) {
- if (ref.current && !ref.current.contains(event?.target as Node)) {
- setSelectTeamOpen(false);
- }
- }
-
- document.addEventListener("click", handleDocumentClick);
-
- return () => {
- document.removeEventListener("click", handleDocumentClick);
- };
- }, []);
-
const switchTeam = (team: Team) => {
- setSelectTeamOpen(false);
localStorage.setItem("currentTeamId", team.id);
userTeam?.setCurrentTeam(team);
router.push("/documents");
@@ -36,64 +25,63 @@ const SelectTeam = ({ teams, currentTeam, isLoading }: TeamContextType) => {
return (
<>
{isLoading ? (
- <h2 className="flex items-center gap-2 mb-6 text-sm">
+ <div className="flex items-center gap-2 mb-6 text-sm">
<Loader className="animate-spin h-5 w-5" /> Loading teams...
- </h2>
+ </div>
) : (
- <>
- <h4 className="text-sm font-semibold my-2 mx-3">Your team</h4>
- <div
- className="relative h-10 mb-6 w-full rounded-md border border-input bg-background text-sm ring-offset-background select-none"
- ref={ref}
- >
- <div
- className="flex items-center justify-between cursor-pointer px-3 py-2"
- onClick={() => setSelectTeamOpen(!selectTeamOpen)}
- >
- {currentTeam?.name}
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <div className="w-full py-2 px-[10px] border rounded-md flex opacity-90 items-center justify-between mb-5 cursor-pointer hover:bg-muted duration-200">
+ <div className="flex items-center space-x-2">
+ <Avatar className="w-[25px] h-[25px] text-[10px]">
+ <AvatarFallback>
+ {currentTeam?.name?.slice(0, 2).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+
+ <p className="text-sm">{currentTeam?.name}</p>
+ </div>
<ChevronUpDownIcon className="h-4 w-4" />
</div>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent className="w-[250px] sm:w-[270px] lg:w-[240px] xl:w-[270px] px-0 pt-2 pb-1.5">
+ {teams.map((team) => (
+ <div
+ key={team.id}
+ onClick={() => switchTeam(team)}
+ className={cn(
+ `w-full flex items-center justify-between px-3 py-2 hover:bg-gray-200 hover:dark:bg-gray-800 cursor-pointer transition-all duration-75 truncate text-sm font-normal `,
+ team.id === currentTeam?.id && "font-medium",
+ )}
+ >
+ <div className="flex items-center space-x-2">
+ <Avatar className="w-7 h-7 text-xs">
+ <AvatarFallback>
+ {team.name?.slice(0, 2).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+
+ <p>{team.name}</p>
+ </div>
- {selectTeamOpen && (
- <div className="z-50 bg-popover text-popover-foreground shadow-md absolute top-12 left-0 max-h-72 w-full space-y-0.5 border overflow-auto rounded-md text-base sm:w-60 sm:text-sm sm:shadow-lg">
- {teams.map((team) => (
- <div
- key={team.id}
- className={`relative flex w-full items-center space-x-2 rounded-md px-4 py-2 hover:bg-gray-200 hover:dark:bg-gray-800 duration-100 cursor-pointer ${
- team.id === currentTeam?.id ? "font-medium" : ""
- } transition-all duration-75`}
- onClick={() => switchTeam(team)}
- >
- <span
- className={`block truncate text-sm ${
- team.id === currentTeam?.id
- ? "font-medium"
- : "font-normal"
- }`}
- >
- {team.name}
- </span>
- {team.id === currentTeam?.id ? (
- <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">
- <Check
- className="h-5 w-5 dark:text-white"
- aria-hidden="true"
- />
- </span>
- ) : null}
- </div>
- ))}
- <Link
- href="/settings/people"
- className="flex mt-1 gap-2 items-center border-t p-3 text-sm hover:bg-gray-200 hover:dark:bg-gray-800 duration-100 hover:cursor-pointer"
- >
- <PlusIcon className="h-5 w-5" />
- Invite Members
- </Link>
+ {team.id === currentTeam?.id && (
+ <Check
+ className="h-4 w-4 dark:text-white text-black"
+ aria-hidden="true"
+ />
+ )}
</div>
- )}
- </div>
- </>
+ ))}
+
+ <Link
+ href="/settings/people"
+ className="w-[92%] mx-auto mb-1 mt-3 flex items-center text-sm rounded-sm border px-[10px] py-2 hover:bg-gray-200 hover:dark:bg-gray-800 duration-100 hover:cursor-pointer"
+ >
+ <PlusIcon className="h-4 w-4 mr-2" />
+ Invite Members
+ </Link>
+ </DropdownMenuContent>
+ </DropdownMenu>
)}
</>
);
diff --git a/pages/documents/index.tsx b/pages/documents/index.tsx
index c97b20f2..89103b14 100644
--- a/pages/documents/index.tsx
+++ b/pages/documents/index.tsx
@@ -1,4 +1,5 @@
import useDocuments from "@/lib/swr/use-documents";
+import { useTeam } from "@/context/team-context";
import DocumentCard from "@/components/documents/document-card";
import Skeleton from "@/components/Skeleton";
import { PlusIcon } from "@heroicons/react/24/solid";
@@ -6,30 +7,47 @@ import { AddDocumentModal } from "@/components/documents/add-document-modal";
import { Separator } from "@/components/ui/separator";
import AppLayout from "@/components/layouts/app";
import { Button } from "@/components/ui/button";
+import { Files } from "lucide-react";
export default function Documents() {
const { documents } = useDocuments();
+ const teamInfo = useTeam();
return (
<AppLayout>
- <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="p-4 sm:py-4 sm:px-10 sm:m-4">
+ <section className="flex items-center justify-between mb-4 md:mb-8 lg:mb-12">
<div className="space-y-1">
- <h2 className="text-2xl text-foreground font-semibold tracking-tight">
- Documents
+ <h2 className="text-xl sm:text-2xl text-foreground font-semibold tracking-tight">
+ All Documents
</h2>
- <p className="text-sm text-muted-foreground">
- Manage your documents
+ <p className="text-xs sm:text-sm text-muted-foreground">
+ Manage all your documents in one place.
</p>
</div>
- <ul className="flex items-center justify-between gap-4">
+ <div className="flex items-center justify-between gap-4">
<AddDocumentModal>
- <Button>Add New Document</Button>
+ <Button
+ size="icon"
+ className="fixed bottom-6 right-5 z-30 sm:bottom-0 sm:right-0 sm:relative w-10 sm:w-44 h-10 sm:h-10"
+ >
+ <span className="hidden sm:block">Add New Document</span>
+ <span className="block sm:hidden">
+ <PlusIcon className="w-6 h-6" />
+ </span>
+ </Button>
</AddDocumentModal>
- </ul>
- </div>
+ </div>
+ </section>
+
+ {documents && documents.length > 0 ? (
+ <p className="text-sm text-gray-400 mt-8 sm:mt-5 mb-2 flex items-center">
+ <Files className="w-[16px] h-[16px] mr-1" /> Total documents{" "}
+ {documents.length}
+ </p>
+ ) : null}
- <Separator className="my-6 bg-gray-200 dark:bg-gray-800" />
+ <Separator className="mb-5 bg-gray-200 dark:bg-gray-800" />
{documents && documents.length === 0 && (
<div className="flex items-center justify-center h-96">
@@ -41,15 +59,28 @@ export default function Documents() {
<ul role="list" className="space-y-4">
{documents
? documents.map((document) => {
- return <DocumentCard key={document.id} document={document} />;
+ return (
+ <DocumentCard
+ key={document.id}
+ document={document}
+ teamInfo={teamInfo}
+ />
+ );
})
: Array.from({ length: 3 }).map((_, i) => (
<li
key={i}
- className="flex flex-col space-y-4 px-4 py-4 sm:px-6 lg:px-8"
+ className="relative w-full py-5 px-4 border rounded-lg flex items-center space-x-3 sm:px-6 lg:px-6"
>
- <Skeleton key={i} className="h-5 w-20" />
- <Skeleton key={i} className="mt-3 h-3 w-10" />
+ <Skeleton key={i} className="h-9 w-9" />
+ <div>
+ <Skeleton key={i} className="h-4 w-32" />
+ <Skeleton key={i} className="mt-2 h-3 w-12" />
+ </div>
+ <Skeleton
+ key={i}
+ className="h-5 w-20 absolute top-[50%] transform -translate-y-[50%] right-5"
+ />
</li>
))}
</ul>