Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
search bar
Iuliia Shnai02aa247ef7cb
diff --git a/app/api/help/route.ts b/app/api/help/route.tsnew file mode 100644index 00000000..06b41af9--- /dev/null+++ b/app/api/help/route.ts@@ -0,0 +1,43 @@+import { NextResponse } from "next/server";++export async function GET(request: Request) {+ const { searchParams } = new URL(request.url);+ const query = searchParams.get("q");++ try {+ const response = await fetch(+ `${process.env.NEXT_PUBLIC_HELP_CENTER_URL}/api/help`,+ );++ if (!response.ok) {+ const errorText = await response.text();+ console.error("Help center response:", {+ status: response.status,+ statusText: response.statusText,+ body: errorText,+ });+ throw new Error(`Failed to fetch articles: ${response.statusText}`);+ }++ const { articles } = await response.json();++ // Filter articles based on search query if provided+ const filteredArticles = query+ ? articles.filter(+ (article: any) =>+ article.data.title.toLowerCase().includes(query.toLowerCase()) ||+ article.data.description+ ?.toLowerCase()+ .includes(query.toLowerCase()),+ )+ : articles;++ return NextResponse.json({ articles: filteredArticles });+ } catch (error) {+ console.error("Error in help search:", error);+ return NextResponse.json(+ { error: "Failed to fetch articles" },+ { status: 500 },+ );+ }+}diff --git a/components/ search-command.tsx b/components/ search-command.tsxnew file mode 100644index 00000000..38ee7caf--- /dev/null+++ b/components/ search-command.tsx@@ -0,0 +1,92 @@+"use client";++import { useEffect, useState } from "react";++import { DialogProps } from "@radix-ui/react-dialog";+import { FileText } from "lucide-react";++import {+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+} from "@/components/ui/command";+import { Dialog, DialogContent } from "@/components/ui/dialog";++interface Article {+ data: {+ title: string;+ slug: string;+ description?: string;+ };+}++interface SearchCommandProps extends DialogProps {+ articles: Article[];+ locale: string;+ placeholder: string;+ noResultsText: string;+ articlesHeading: string;+ open?: boolean;+ onOpenChange?: (open: boolean) => void;+}++export function SearchCommand({+ articles,+ locale,+ placeholder,+ noResultsText,+ articlesHeading,+ open,+ onOpenChange,+ ...props+}: SearchCommandProps) {+ return (+ <Dialog open={open} onOpenChange={onOpenChange} {...props}>+ <DialogContent className="max-w-[550px] gap-0 overflow-hidden border-none p-0 shadow-lg">+ <Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">+ <CommandInput+ placeholder={placeholder}+ className="h-14 border-none px-4 focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0"+ />+ <CommandList className="max-h-[400px] overflow-y-auto">+ <CommandEmpty className="py-6 text-center text-sm">+ {noResultsText}+ </CommandEmpty>+ <CommandGroup heading={articlesHeading} className="px-4">+ {articles.map((article) => (+ <CommandItem+ key={article.data.slug}+ value={article.data.title}+ onSelect={() => {+ const path =+ locale === "en"+ ? `/help/article/${article.data.slug}`+ : `/${locale}/help/article/${article.data.slug}`;+ window.location.href = `${process.env.NEXT_PUBLIC_HELP_CENTER_URL}${path}`;+ onOpenChange?.(false);+ }}+ className="cursor-pointer rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800"+ >+ <FileText className="mr-2 h-4 w-4 text-[#fb7a00]" />+ <div className="flex flex-col">+ <span className="text-sm font-medium">+ {article.data.title}+ </span>+ {article.data.description && (+ <span className="text-xs text-muted-foreground">+ {article.data.description}+ </span>+ )}+ </div>+ </CommandItem>+ ))}+ </CommandGroup>+ </CommandList>+ </Command>+ </DialogContent>+ </Dialog>+ );+}diff --git a/components/profile-menu.tsx b/components/profile-menu.tsxindex f09f694d..3ab093a4 100644--- a/components/profile-menu.tsx+++ b/components/profile-menu.tsx@@ -1,10 +1,22 @@import Image from "next/image";import Link from "next/link";-import { HelpCircle, LogOut } from "lucide-react";+import { useState } from "react";++import { HelpCircle, LogOut, Search } from "lucide-react";+import { FileText } from "lucide-react";import { signOut, useSession } from "next-auth/react";import ChevronUp from "@/components/shared/icons/chevron-up";+import {+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+} from "@/components/ui/command";+import { Dialog, DialogContent } from "@/components/ui/dialog";import {DropdownMenu,DropdownMenuContent,@@ -16,6 +28,7 @@ import { Skeleton } from "@/components/ui/skeleton";import { cn } from "@/lib/utils";+import { SearchCommand } from "./ search-command";import UserRound from "./shared/icons/user-round";import { ModeToggle } from "./theme-toggle";@@ -24,84 +37,175 @@ type ProfileMenuProps = {size: "large" | "small";};+// Define the Article interface+interface Article {+ data: {+ slug: string;+ title: string;+ description?: string;+ };+}+const ProfileMenu = ({ className, size }: ProfileMenuProps) => {const { data: session, status } = useSession();+ const [searchOpen, setSearchOpen] = useState(false);+ const [articles, setArticles] = useState<Article[]>([]);+ const [loading, setLoading] = useState(false);++ const fetchArticles = async (query?: string) => {+ setLoading(true);+ try {+ const params = new URLSearchParams({+ locale: "en", // or get this from your app's locale+ ...(query && { q: query }),+ });++ console.log("Fetching articles..."); // Debug log+ const res = await fetch(`/api/help?${params}`);+ const data = await res.json();++ console.log("Received data:", data); // Debug log++ if (data.error) {+ throw new Error(data.error);+ }++ setArticles(data.articles || []);+ } catch (error) {+ console.error("Error fetching articles:", error);+ setArticles([]); // Set empty array on error+ } finally {+ setLoading(false);+ }+ };const isSize = size === "large";return (- <div className="flex items-center justify-between space-x-2">- {status === "loading" ? (- <div className="flex w-full items-center gap-x-3 rounded-md p-2">- <Skeleton className="h-8 w-8 rounded-full" />- {isSize && <Skeleton className="h-7 w-[90%]" />}- </div>- ) : (- <DropdownMenu>- <DropdownMenuTrigger asChild className="w-full">- <div className="group flex w-full items-center rounded-full text-sm font-semibold leading-6 text-foreground hover:bg-gray-200 hover:dark:bg-secondary lg:gap-x-3 lg:rounded-md lg:p-2">- {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 rounded-full bg-secondary p-1 ring-1 ring-muted-foreground/50" />- )}- {isSize && (- <span className="flex w-full items-center 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 shrink-0 text-muted-foreground"- aria-hidden="true"+ <>+ <div className="flex items-center justify-between space-x-2">+ {status === "loading" ? (+ <div className="flex w-full items-center gap-x-3 rounded-md p-2">+ <Skeleton className="h-8 w-8 rounded-full" />+ {isSize && <Skeleton className="h-7 w-[90%]" />}+ </div>+ ) : (+ <DropdownMenu>+ <DropdownMenuTrigger asChild className="w-full">+ <div className="group flex w-full items-center rounded-full text-sm font-semibold leading-6 text-foreground hover:bg-gray-200 hover:dark:bg-secondary lg:gap-x-3 lg:rounded-md lg:p-2">+ {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"/>- </span>- )}- </div>- </DropdownMenuTrigger>- <DropdownMenuContent className="mr-2 px-0 pb-2 lg:mr-0 lg:w-[240px] xl:w-[270px]">- {session ? (- <>- <DropdownMenuLabel className="mt-2 truncate !py-[3px] px-3 text-sm text-muted-foreground">- {session?.user?.email}- </DropdownMenuLabel>- <DropdownMenuSeparator className="!my-2" />- <ModeToggle />-- <a- href="mailto:[email protected]"- className="my-1 flex items-center px-3 py-2 text-sm duration-200 hover:bg-gray-200 dark:hover:bg-muted"- >- <HelpCircle className="mr-2 h-4 w-4" />- Need Help?- </a>-- <Link- onClick={() =>- signOut({- callbackUrl: `${window.location.origin}`,- })- }- className="flex items-center px-3 py-2 text-sm duration-200 hover:bg-gray-200 dark:hover:bg-muted"- href={""}- >- <LogOut className="mr-2 h-4 w-4" />- Sign Out- </Link>- </>- ) : null}- </DropdownMenuContent>- </DropdownMenu>- )}- </div>+ ) : (+ <UserRound className="h-7 w-7 rounded-full bg-secondary p-1 ring-1 ring-muted-foreground/50" />+ )}+ {isSize && (+ <span className="flex w-full items-center 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 shrink-0 text-muted-foreground"+ aria-hidden="true"+ />+ </span>+ )}+ </div>+ </DropdownMenuTrigger>+ <DropdownMenuContent className="mr-2 px-0 pb-2 lg:mr-0 lg:w-[240px] xl:w-[270px]">+ {session ? (+ <>+ <DropdownMenuLabel className="mt-2 truncate !py-[3px] px-3 text-sm text-muted-foreground">+ {session?.user?.email}+ </DropdownMenuLabel>+ <DropdownMenuSeparator className="!my-2" />+ <ModeToggle />++ <button+ onClick={() => {+ setSearchOpen(true);+ fetchArticles();+ }}+ className="flex w-full items-center px-3 py-2 text-sm duration-200 hover:bg-gray-200 dark:hover:bg-muted"+ >+ <Search className="mr-2 h-4 w-4" />+ Need help?+ </button>++ <a+ href="mailto:[email protected]"+ className="my-1 flex items-center px-3 py-2 text-sm duration-200 hover:bg-gray-200 dark:hover:bg-muted"+ >+ <HelpCircle className="mr-2 h-4 w-4" />+ Contact us+ </a>++ <Link+ onClick={() =>+ signOut({+ callbackUrl: `${window.location.origin}`,+ })+ }+ className="flex items-center px-3 py-2 text-sm duration-200 hover:bg-gray-200 dark:hover:bg-muted"+ href={""}+ >+ <LogOut className="mr-2 h-4 w-4" />+ Sign Out+ </Link>+ </>+ ) : null}+ </DropdownMenuContent>+ </DropdownMenu>+ )}+ </div>++ <Dialog open={searchOpen} onOpenChange={setSearchOpen}>+ <DialogContent className="max-w-[550px] gap-0 overflow-hidden border-none p-0 shadow-lg">+ <Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">+ <CommandInput+ placeholder="Search help articles..."+ className="h-14 border-none px-4 focus:ring-0 focus-visible:ring-0 focus-visible:ring-offset-0"+ onValueChange={(search) => fetchArticles(search)}+ />+ <CommandList className="max-h-[400px] overflow-y-auto">+ <CommandEmpty>No articles found</CommandEmpty>+ <CommandGroup heading="All Articles">+ {articles.map((article) => (+ <CommandItem+ key={article.data.slug}+ value={article.data.title}+ onSelect={() => {+ window.location.href = `${process.env.NEXT_PUBLIC_HELP_CENTER_URL}/help/article/${article.data.slug}`;+ setSearchOpen(false);+ }}+ >+ <FileText className="mr-2 h-4 w-4 text-[#fb7a00]" />+ <div className="flex flex-col">+ <span className="text-sm font-medium">+ {article.data.title}+ </span>+ {article.data.description && (+ <span className="text-xs text-muted-foreground">+ {article.data.description}+ </span>+ )}+ </div>+ </CommandItem>+ ))}+ </CommandGroup>+ </CommandList>+ </Command>+ </DialogContent>+ </Dialog>+ </>);};diff --git a/components/profile-search-trigger.tsx b/components/profile-search-trigger.tsxnew file mode 100644index 00000000..dcc41d5d--- /dev/null+++ b/components/profile-search-trigger.tsx@@ -0,0 +1,19 @@+"use client";++import { Search } from "lucide-react";++interface ProfileSearchTriggerProps {+ onClick: () => void;+}++export function ProfileSearchTrigger({ onClick }: ProfileSearchTriggerProps) {+ return (+ <button+ onClick={onClick}+ className="flex w-full items-center px-3 py-2 text-sm duration-200 hover:bg-gray-200 dark:hover:bg-muted"+ >+ <Search className="mr-2 h-4 w-4" />+ Search Help Articles+ </button>+ );+}diff --git a/package-lock.json b/package-lock.jsonindex 1599f353..97dc2546 100644--- a/package-lock.json+++ b/package-lock.json@@ -16970,6 +16970,21 @@"peerDependencies": {"zod": "^3.18.0"}+ },+ "node_modules/react-email/node_modules/@next/swc-win32-ia32-msvc": {+ "version": "14.2.20",+ "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.20.tgz",+ "integrity": "sha512-igQW/JWciTGJwj3G1ipalD2V20Xfx3ywQy17IV0ciOUBbFhNfyU1DILWsTi32c8KmqgIDviUEulW/yPb2FF90w==",+ "cpu": [+ "ia32"+ ],+ "optional": true,+ "os": [+ "win32"+ ],+ "engines": {+ "node": ">= 10"+ }}}}