Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: update folder modal with logo and color
Marc Seitze8cf47dc8ffa
diff --git a/components/folders/add-folder-modal.tsx b/components/folders/add-folder-modal.tsxindex 36d28295..f56c171a 100644--- a/components/folders/add-folder-modal.tsx+++ b/components/folders/add-folder-modal.tsx@@ -9,6 +9,15 @@ import { toast } from "sonner";import { mutate } from "swr";import { z } from "zod";+import {+ DEFAULT_FOLDER_COLOR,+ DEFAULT_FOLDER_ICON,+ FolderColorId,+ FolderIconId,+} from "@/lib/constants/folder-constants";+import { useAnalytics } from "@/lib/analytics";+import { usePlan } from "@/lib/swr/use-billing";+import { Button } from "@/components/ui/button";import {Dialog,@@ -22,10 +31,8 @@ import {import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";-import { useAnalytics } from "@/lib/analytics";-import { usePlan } from "@/lib/swr/use-billing";-import { UpgradePlanModal } from "../billing/upgrade-plan-modal";+import { FolderIconColorPicker } from "./folder-icon-picker";export function AddFolderModal({// open,@@ -44,6 +51,8 @@ export function AddFolderModal({}) {const router = useRouter();const [folderName, setFolderName] = useState<string>("");+ const [folderIcon, setFolderIcon] = useState<FolderIconId>(DEFAULT_FOLDER_ICON);+ const [folderColor, setFolderColor] = useState<FolderColorId>(DEFAULT_FOLDER_COLOR);const [loading, setLoading] = useState<boolean>(false);const [open, setOpen] = useState<boolean>(false);@@ -60,9 +69,14 @@ export function AddFolderModal({: `/documents/tree/${currentFolderPath ? currentFolderPath?.join("/") : ""}${"/" + slugify(folderName.trim())}`;const addFolderSchema = z.object({- name: z.string().min(3, {- message: "Please provide a folder name with at least 3 characters.",- }),+ name: z+ .string()+ .min(3, {+ message: "Please provide a folder name with at least 3 characters.",+ })+ .max(256, {+ message: "Folder name must be 256 characters or less.",+ }),});const validation = addFolderSchema.safeParse({ name: folderName });@@ -91,6 +105,8 @@ export function AddFolderModal({body: JSON.stringify({name: folderName.trim(),path: currentFolderPath?.join("/"),+ icon: folderIcon,+ color: folderColor,}),},);@@ -106,6 +122,8 @@ export function AddFolderModal({analytics.capture("Folder Added", {folderName: folderName.trim(),+ icon: folderIcon,+ color: folderColor,dataroomId,});toast.success(`Folder added successfully!`, {@@ -130,6 +148,8 @@ export function AddFolderModal({return;} finally {setFolderName("");+ setFolderIcon(DEFAULT_FOLDER_ICON);+ setFolderColor(DEFAULT_FOLDER_COLOR);setLoading(false);setOpen(false);}@@ -156,18 +176,29 @@ export function AddFolderModal({<DialogContent className="sm:max-w-[425px]"><DialogHeader className="text-start"><DialogTitle>Add Folder</DialogTitle>- <DialogDescription>You can easily add a folder.</DialogDescription>+ <DialogDescription>+ Create a new folder with a custom icon and color.+ </DialogDescription></DialogHeader><form onSubmit={handleSubmit}><Label htmlFor="folder-name" className="opacity-80">Folder Name</Label>- <Input- id="folder-name"- placeholder="folder-123"- className="mb-4 mt-1 w-full"- onChange={(e) => setFolderName(e.target.value)}- />+ <div className="mb-4 mt-1 flex items-center gap-2">+ <FolderIconColorPicker+ iconValue={folderIcon}+ colorValue={folderColor}+ onIconChange={setFolderIcon}+ onColorChange={setFolderColor}+ />+ <Input+ id="folder-name"+ placeholder="Choose a helpful name"+ className="flex-1"+ value={folderName}+ onChange={(e) => setFolderName(e.target.value)}+ />+ </div><DialogFooter><Buttontype="submit"@@ -175,7 +206,7 @@ export function AddFolderModal({disabled={!validation.success}loading={loading}>- Add new folder+ Create</Button></DialogFooter></form>diff --git a/components/folders/edit-folder-modal.tsx b/components/folders/edit-folder-modal.tsxindex d4ba6969..a06ce8f8 100644--- a/components/folders/edit-folder-modal.tsx+++ b/components/folders/edit-folder-modal.tsx@@ -10,7 +10,6 @@ import {DEFAULT_FOLDER_ICON,FolderColorId,FolderIconId,- getFolderColorClasses,} from "@/lib/constants/folder-constants";import { useAnalytics } from "@/lib/analytics";@@ -27,8 +26,7 @@ import {import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";-import { FolderColorPicker } from "./folder-color-picker";-import { FolderIconPicker, FolderIconPreview } from "./folder-icon-picker";+import { FolderIconColorPicker } from "./folder-icon-picker";export function EditFolderModal({open,@@ -80,13 +78,11 @@ export function EditFolderModal({.min(3, {message: "Please provide a folder name with at least 3 characters.",})- .max(60, {- message: "Folder name must be 60 characters or less.",+ .max(256, {+ message: "Folder name must be 256 characters or less.",}),});- const colorClasses = getFolderColorClasses(folderColor);-const handleSubmit = async (event: any) => {event.preventDefault();event.stopPropagation();@@ -164,69 +160,37 @@ export function EditFolderModal({return (<Dialog open={open} onOpenChange={setOpen}><DialogTrigger asChild>{children}</DialogTrigger>- <DialogContent className="sm:max-w-[500px]">+ <DialogContent className="sm:max-w-[425px]"><DialogHeader className="text-start"><DialogTitle>Edit Folder</DialogTitle><DialogDescription>- Customize your folder name, icon, and color.+ Update your folder name, icon, and color.</DialogDescription></DialogHeader>- {/* Live Preview */}- <div className="flex items-center gap-3 rounded-lg border bg-muted/30 p-4">- <div className="flex h-12 w-12 items-center justify-center rounded-lg bg-background shadow-sm">- <FolderIconPreview- iconId={folderIcon}- colorClass={colorClasses.iconClass}- size="lg"+ <form onSubmit={handleSubmit}>+ <Label htmlFor="folder-name-update" className="opacity-80">+ Folder Name+ </Label>+ <div className="mb-1 mt-1 flex items-center gap-2">+ <FolderIconColorPicker+ iconValue={folderIcon}+ colorValue={folderColor}+ onIconChange={setFolderIcon}+ onColorChange={setFolderColor}/>- </div>- <div className="flex-1 truncate">- <p className="truncate font-medium">- {folderName.trim() || "Folder name"}- </p>- <p className="text-xs text-muted-foreground">Preview</p>- </div>- </div>-- <form onSubmit={handleSubmit} className="space-y-4">- {/* Folder Name */}- <div>- <Label htmlFor="folder-name-update" className="text-sm font-medium">- Folder Name- </Label><Inputid="folder-name-update"value={folderName}- placeholder="My folder"- className="mt-1.5 w-full"- maxLength={60}+ placeholder="Choose a helpful name"+ className="flex-1"+ maxLength={256}onChange={(e) => setFolderName(e.target.value)}/>- <p className="mt-1 text-xs text-muted-foreground">- {folderName.length}/60 characters- </p>- </div>-- {/* Folder Color */}- <div>- <Label className="text-sm font-medium">Folder Color</Label>- <div className="mt-1.5">- <FolderColorPicker value={folderColor} onChange={setFolderColor} />- </div>- </div>-- {/* Folder Icon */}- <div>- <Label className="text-sm font-medium">Folder Icon</Label>- <div className="mt-1.5">- <FolderIconPicker- value={folderIcon}- onChange={setFolderIcon}- colorClass={colorClasses.iconClass}- />- </div></div>+ <p className="mb-4 text-xs text-muted-foreground">+ {folderName.length}/256 characters+ </p><DialogFooter><Button type="submit" className="h-9 w-full" loading={loading}>diff --git a/components/folders/folder-icon-picker.tsx b/components/folders/folder-icon-picker.tsxindex 691cd5e6..620be76f 100644--- a/components/folders/folder-icon-picker.tsx+++ b/components/folders/folder-icon-picker.tsx@@ -1,12 +1,20 @@-import { useMemo } from "react";+import { useMemo, useState } from "react";import {+ FOLDER_COLORS,FOLDER_ICONS,+ FolderColorId,FolderIconId,+ getFolderColorClasses,getFolderIcon,} from "@/lib/constants/folder-constants";import { cn } from "@/lib/utils";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+} from "@/components/ui/popover";import { ScrollArea } from "@/components/ui/scroll-area";interface FolderIconPickerProps {@@ -45,7 +53,10 @@ export function FolderIconPicker({title={iconOption.label}><IconComponent- className={cn("h-5 w-5", isSelected ? colorClass : "text-muted-foreground")}+ className={cn(+ "h-5 w-5",+ isSelected ? colorClass : "text-muted-foreground",+ )}strokeWidth={1.5}/></button>@@ -85,3 +96,123 @@ export function FolderIconPreview({/>);}++// Color hex values for color picker dots+const COLOR_HEX_VALUES: Record<FolderColorId, string> = {+ gray: "#6b7280",+ red: "#ef4444",+ orange: "#f97316",+ yellow: "#eab308",+ green: "#10b981",+ blue: "#3b82f6",+ black: "#000000",+};++// Combined Icon and Color Picker Popover+interface FolderIconColorPickerProps {+ iconValue: FolderIconId;+ colorValue: FolderColorId;+ onIconChange: (iconId: FolderIconId) => void;+ onColorChange: (colorId: FolderColorId) => void;+}++export function FolderIconColorPicker({+ iconValue,+ colorValue,+ onIconChange,+ onColorChange,+}: FolderIconColorPickerProps) {+ const [open, setOpen] = useState(false);+ const colorClasses = getFolderColorClasses(colorValue);++ return (+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger asChild>+ <button+ type="button"+ className="flex h-10 w-10 shrink-0 items-center justify-center rounded-md border bg-muted/50 transition-colors hover:bg-muted"+ aria-label="Choose folder icon and color"+ >+ <FolderIconPreview+ iconId={iconValue}+ colorClass={colorClasses.iconClass}+ size="md"+ />+ </button>+ </PopoverTrigger>+ <PopoverContent className="w-[280px] p-3" align="start">+ {/* Color Picker Row */}+ <div className="mb-3">+ <p className="mb-2 text-xs font-medium text-muted-foreground">+ Colors+ </p>+ <div className="flex flex-wrap gap-2">+ {FOLDER_COLORS.map((colorOption) => {+ const isSelected = colorValue === colorOption.id;+ const hex = COLOR_HEX_VALUES[colorOption.id as FolderColorId];++ return (+ <button+ key={colorOption.id}+ type="button"+ onClick={() => onColorChange(colorOption.id as FolderColorId)}+ className={cn(+ "flex h-7 w-7 items-center justify-center rounded-full transition-all",+ isSelected+ ? "ring-2 ring-offset-2 ring-offset-background"+ : "hover:scale-110",+ )}+ style={{+ backgroundColor: hex,+ ...(isSelected && { ringColor: hex }),+ }}+ title={colorOption.label}+ aria-label={`Select ${colorOption.label} color`}+ />+ );+ })}+ </div>+ </div>++ {/* Icon Picker Grid */}+ <div>+ <p className="mb-2 text-xs font-medium text-muted-foreground">+ Icons+ </p>+ <ScrollArea className="h-[200px]">+ <div className="m-1 grid grid-cols-7 gap-1.5">+ {FOLDER_ICONS.map((iconOption) => {+ const IconComponent = iconOption.icon;+ const isSelected = iconValue === iconOption.id;++ return (+ <button+ key={iconOption.id}+ type="button"+ onClick={() => onIconChange(iconOption.id)}+ className={cn(+ "flex h-8 w-8 items-center justify-center rounded-md transition-all hover:bg-muted",+ isSelected && "bg-muted ring-1 ring-primary",+ )}+ title={iconOption.label}+ aria-label={`Select ${iconOption.label} icon`}+ >+ <IconComponent+ className={cn(+ "h-5 w-5",+ isSelected+ ? colorClasses.iconClass+ : "text-muted-foreground",+ )}+ strokeWidth={1.5}+ />+ </button>+ );+ })}+ </div>+ </ScrollArea>+ </div>+ </PopoverContent>+ </Popover>+ );+}diff --git a/lib/api/links/link-data.ts b/lib/api/links/link-data.tsindex 553855b4..b6d38aef 100644--- a/lib/api/links/link-data.ts+++ b/lib/api/links/link-data.ts@@ -167,6 +167,8 @@ export async function fetchDataroomLinkData({dataroomId: true,orderIndex: true,hierarchicalIndex: true,+ icon: true,+ color: true,createdAt: true,updatedAt: true,},diff --git a/lib/constants/folder-constants.ts b/lib/constants/folder-constants.tsindex d6055ddd..b6ac04a1 100644--- a/lib/constants/folder-constants.ts+++ b/lib/constants/folder-constants.ts@@ -1,13 +1,19 @@import {ArchiveIcon,+ AwardIcon,+ BellIcon,BookIcon,BookmarkIcon,BoxIcon,BriefcaseIcon,+ CloudIcon,FileIcon,+ FlagIcon,+ FlameIcon,FolderIcon,FolderOpenIcon,GlobeIcon,+ HashIcon,HeartIcon,HomeIcon,ImageIcon,@@ -20,7 +26,9 @@ import {PenToolIcon,SettingsIcon,ShieldIcon,+ SparklesIcon,StarIcon,+ SunIcon,TagIcon,UsersIcon,VideoIcon,@@ -57,6 +65,14 @@ export const FOLDER_ICONS = [{ id: "lightbulb", icon: LightbulbIcon, label: "Ideas" },{ id: "zap", icon: ZapIcon, label: "Quick" },{ id: "wrench", icon: WrenchIcon, label: "Tools" },+ { id: "sparkles", icon: SparklesIcon, label: "Sparkles" },+ { id: "cloud", icon: CloudIcon, label: "Cloud" },+ { id: "flag", icon: FlagIcon, label: "Flag" },+ { id: "award", icon: AwardIcon, label: "Award" },+ { id: "flame", icon: FlameIcon, label: "Fire" },+ { id: "bell", icon: BellIcon, label: "Bell" },+ { id: "sun", icon: SunIcon, label: "Sun" },+ { id: "hash", icon: HashIcon, label: "Hashtag" },] as const;export type FolderIconId = (typeof FOLDER_ICONS)[number]["id"];@@ -112,20 +128,12 @@ export const FOLDER_COLORS = [iconClass: "text-blue-500 dark:text-blue-400",},{- id: "purple",- label: "Purple",+ id: "black",+ label: "Black",text: "text-purple-600",- bg: "bg-purple-100",- border: "border-purple-300",- iconClass: "text-purple-500 dark:text-purple-400",- },- {- id: "pink",- label: "Pink",- text: "text-pink-600",- bg: "bg-pink-100",- border: "border-pink-300",- iconClass: "text-pink-500 dark:text-pink-400",+ bg: "bg-black-100",+ border: "border-black-300",+ iconClass: "text-black-500 dark:text-black-400",},] as const;diff --git a/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/folders/index.tsindex 7cb5148a..e780689f 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts@@ -440,7 +440,12 @@ export default async function handle(id: string;};- const { name, path } = req.body as { name: string; path?: string };+ const { name, path, icon, color } = req.body as {+ name: string;+ path?: string;+ icon?: string;+ color?: string;+ };const parentFolderPath = path ? "/" + path : "/";@@ -516,6 +521,8 @@ export default async function handle(path: childFolderPath,parentId: parentFolder?.id ?? null,dataroomId: dataroomId,+ icon: icon ?? null,+ color: color ?? null,},});diff --git a/pages/api/teams/[teamId]/folders/index.ts b/pages/api/teams/[teamId]/folders/index.tsindex 36cb98b7..f320678d 100644--- a/pages/api/teams/[teamId]/folders/index.ts+++ b/pages/api/teams/[teamId]/folders/index.ts@@ -109,7 +109,12 @@ export default async function handle(const userId = (session.user as CustomUser).id;const { teamId } = req.query as { teamId: string };- const { name, path } = req.body as { name: string; path: string };+ const { name, path, icon, color } = req.body as {+ name: string;+ path: string;+ icon?: string;+ color?: string;+ };const parentFolderPath = path ? "/" + path : "/";@@ -182,6 +187,8 @@ export default async function handle(path: childFolderPath,parentId: parentFolder?.id ?? null,teamId: teamId,+ icon: icon ?? null,+ color: color ?? null,},});