Skip to content

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

feat: Add folder customization with icon and color selection

Cursor Agent4686c480e66f
diff --git a/components/documents/folder-card.tsx b/components/documents/folder-card.tsx
index c2fc8177..e43fe25d 100644
--- a/components/documents/folder-card.tsx
+++ b/components/documents/folder-card.tsx
@@ -8,7 +8,6 @@ import {
ClipboardCopyIcon,
CopyIcon,
EyeOffIcon,
- FolderIcon,
FolderInputIcon,
FolderPenIcon,
MoreVertical,
@@ -18,6 +17,7 @@ import {
import { toast } from "sonner";
import { mutate } from "swr";
+import { getFolderColorClasses, getFolderIcon } from "@/lib/constants/folder-constants";
import { DataroomFolderWithCount } from "@/lib/swr/use-dataroom";
import { FolderWithCount } from "@/lib/swr/use-documents";
import { timeAgo } from "@/lib/utils";
@@ -200,7 +200,16 @@ export default function FolderCard({
<div className="flex min-w-0 shrink items-center space-x-2 sm:space-x-4">
{!isSelected && !isHovered ? (
<div className="mx-0.5 flex w-8 items-center justify-center text-center sm:mx-1">
- <FolderIcon className="h-8 w-8" strokeWidth={1} />
+ {(() => {
+ const FolderIconComponent = getFolderIcon(folder.icon);
+ const colorClasses = getFolderColorClasses(folder.color);
+ return (
+ <FolderIconComponent
+ className={`h-8 w-8 ${colorClasses.iconClass}`}
+ strokeWidth={1}
+ />
+ );
+ })()}
</div>
) : (
<div className="mx-0.5 w-8 sm:mx-1"></div>
@@ -355,6 +364,8 @@ export default function FolderCard({
setOpen={setOpenFolder}
folderId={folder.id}
name={folder.name}
+ icon={folder.icon}
+ color={folder.color}
isDataroom={isDataroom}
dataroomId={dataroomId}
/>
diff --git a/components/folders/edit-folder-modal.tsx b/components/folders/edit-folder-modal.tsx
index 042b8ed9..d4ba6969 100644
--- a/components/folders/edit-folder-modal.tsx
+++ b/components/folders/edit-folder-modal.tsx
@@ -5,6 +5,15 @@ import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";
+import {
+ DEFAULT_FOLDER_COLOR,
+ DEFAULT_FOLDER_ICON,
+ FolderColorId,
+ FolderIconId,
+ getFolderColorClasses,
+} from "@/lib/constants/folder-constants";
+import { useAnalytics } from "@/lib/analytics";
+
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -18,11 +27,16 @@ 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";
+
export function EditFolderModal({
open,
setOpen,
name,
folderId,
+ icon,
+ color,
onAddition,
isDataroom,
dataroomId,
@@ -32,21 +46,47 @@ export function EditFolderModal({
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
name: string;
folderId: string;
+ icon?: string | null;
+ color?: string | null;
onAddition?: (folderName: string) => void;
isDataroom?: boolean;
dataroomId?: string;
children?: React.ReactNode;
}) {
const [folderName, setFolderName] = useState<string>(name);
+ const [folderIcon, setFolderIcon] = useState<FolderIconId>(
+ (icon as FolderIconId) || DEFAULT_FOLDER_ICON,
+ );
+ const [folderColor, setFolderColor] = useState<FolderColorId>(
+ (color as FolderColorId) || DEFAULT_FOLDER_COLOR,
+ );
const [loading, setLoading] = useState<boolean>(false);
const teamInfo = useTeam();
+ const analytics = useAnalytics();
+
+ // Reset state when modal opens with new folder data
+ useEffect(() => {
+ if (open) {
+ setFolderName(name);
+ setFolderIcon((icon as FolderIconId) || DEFAULT_FOLDER_ICON);
+ setFolderColor((color as FolderColorId) || DEFAULT_FOLDER_COLOR);
+ }
+ }, [open, name, icon, color]);
+
const editFolderSchema = 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(60, {
+ message: "Folder name must be 60 characters or less.",
+ }),
});
+ const colorClasses = getFolderColorClasses(folderColor);
+
const handleSubmit = async (event: any) => {
event.preventDefault();
event.stopPropagation();
@@ -60,6 +100,12 @@ export function EditFolderModal({
const endpointTargetType =
isDataroom && dataroomId ? `datarooms/${dataroomId}/folders` : "folders";
+ // Determine what fields have changed for analytics
+ const changedFields: string[] = [];
+ if (folderName.trim() !== name) changedFields.push("name");
+ if (folderIcon !== (icon || DEFAULT_FOLDER_ICON)) changedFields.push("icon");
+ if (folderColor !== (color || DEFAULT_FOLDER_COLOR)) changedFields.push("color");
+
try {
const response = await fetch(
`/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}/manage`,
@@ -71,6 +117,8 @@ export function EditFolderModal({
body: JSON.stringify({
folderId: folderId,
name: folderName.trim(),
+ icon: folderIcon,
+ color: folderColor,
}),
},
);
@@ -84,7 +132,17 @@ export function EditFolderModal({
const { parentFolderPath } = await response.json();
- toast.success("Folder updated successfully! 🎉");
+ // Track analytics
+ if (changedFields.length > 0) {
+ analytics.capture("folder_updated", {
+ changed: changedFields,
+ icon: folderIcon,
+ color: folderColor,
+ isDataroom,
+ });
+ }
+
+ toast.success("Folder updated successfully!");
mutate(`/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}`);
mutate(
@@ -106,22 +164,70 @@ export function EditFolderModal({
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>{children}</DialogTrigger>
- <DialogContent className="sm:max-w-[425px]">
+ <DialogContent className="sm:max-w-[500px]">
<DialogHeader className="text-start">
<DialogTitle>Edit Folder</DialogTitle>
- <DialogDescription>Enter a new folder name.</DialogDescription>
+ <DialogDescription>
+ Customize your folder name, icon, and color.
+ </DialogDescription>
</DialogHeader>
- <form onSubmit={handleSubmit}>
- <Label htmlFor="folder-name-update" className="opacity-80">
- Folder Name
- </Label>
- <Input
- id="folder-name-update"
- value={folderName}
- placeholder="folder-123"
- className="mb-4 mt-1 w-full"
- onChange={(e) => setFolderName(e.target.value)}
- />
+
+ {/* 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"
+ />
+ </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>
+ <Input
+ id="folder-name-update"
+ value={folderName}
+ placeholder="My folder"
+ className="mt-1.5 w-full"
+ maxLength={60}
+ 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>
+
<DialogFooter>
<Button type="submit" className="h-9 w-full" loading={loading}>
Update folder
diff --git a/components/folders/folder-color-picker.tsx b/components/folders/folder-color-picker.tsx
new file mode 100644
index 00000000..0f43c07a
--- /dev/null
+++ b/components/folders/folder-color-picker.tsx
@@ -0,0 +1,116 @@
+import { useMemo } from "react";
+
+import {
+ FOLDER_COLORS,
+ FolderColorId,
+ getFolderColorClasses,
+} from "@/lib/constants/folder-constants";
+import { cn } from "@/lib/utils";
+
+interface FolderColorPickerProps {
+ value: FolderColorId | null | undefined;
+ onChange: (colorId: FolderColorId) => void;
+}
+
+export function FolderColorPicker({ value, onChange }: FolderColorPickerProps) {
+ const selectedColor = useMemo(() => {
+ return value || "gray";
+ }, [value]);
+
+ return (
+ <div className="flex flex-wrap gap-2">
+ {FOLDER_COLORS.map((colorOption) => {
+ const isSelected = selectedColor === colorOption.id;
+
+ return (
+ <button
+ key={colorOption.id}
+ type="button"
+ onClick={() => onChange(colorOption.id)}
+ className={cn(
+ "flex h-8 items-center gap-2 rounded-full border px-3 text-sm transition-all",
+ colorOption.bg,
+ colorOption.border,
+ colorOption.text,
+ isSelected ? "ring-2 ring-offset-1" : "hover:scale-105",
+ )}
+ style={
+ isSelected
+ ? {
+ ringColor: `var(--${colorOption.id === "gray" ? "slate" : colorOption.id}-500)`,
+ }
+ : undefined
+ }
+ title={colorOption.label}
+ >
+ <span
+ className={cn(
+ "h-3 w-3 rounded-full",
+ colorOption.id === "gray"
+ ? "bg-gray-500"
+ : `bg-${colorOption.id}-500`,
+ )}
+ style={{
+ backgroundColor:
+ colorOption.id === "gray"
+ ? "#6b7280"
+ : colorOption.id === "red"
+ ? "#ef4444"
+ : colorOption.id === "orange"
+ ? "#f97316"
+ : colorOption.id === "yellow"
+ ? "#eab308"
+ : colorOption.id === "green"
+ ? "#10b981"
+ : colorOption.id === "blue"
+ ? "#3b82f6"
+ : colorOption.id === "purple"
+ ? "#a855f7"
+ : colorOption.id === "pink"
+ ? "#ec4899"
+ : "#6b7280",
+ }}
+ />
+ {colorOption.label}
+ </button>
+ );
+ })}
+ </div>
+ );
+}
+
+// Helper component to get color preview dot
+interface FolderColorDotProps {
+ colorId: FolderColorId | null | undefined;
+ className?: string;
+}
+
+export function FolderColorDot({ colorId, className }: FolderColorDotProps) {
+ const colorClasses = getFolderColorClasses(colorId);
+
+ const colorHex =
+ colorId === "gray"
+ ? "#6b7280"
+ : colorId === "red"
+ ? "#ef4444"
+ : colorId === "orange"
+ ? "#f97316"
+ : colorId === "yellow"
+ ? "#eab308"
+ : colorId === "green"
+ ? "#10b981"
+ : colorId === "blue"
+ ? "#3b82f6"
+ : colorId === "purple"
+ ? "#a855f7"
+ : colorId === "pink"
+ ? "#ec4899"
+ : "#6b7280";
+
+ return (
+ <span
+ className={cn("h-3 w-3 rounded-full", className)}
+ style={{ backgroundColor: colorHex }}
+ />
+ );
+}
diff --git a/components/folders/folder-icon-picker.tsx b/components/folders/folder-icon-picker.tsx
new file mode 100644
index 00000000..691cd5e6
--- /dev/null
+++ b/components/folders/folder-icon-picker.tsx
@@ -0,0 +1,87 @@
+import { useMemo } from "react";
+
+import {
+ FOLDER_ICONS,
+ FolderIconId,
+ getFolderIcon,
+} from "@/lib/constants/folder-constants";
+import { cn } from "@/lib/utils";
+
+import { ScrollArea } from "@/components/ui/scroll-area";
+
+interface FolderIconPickerProps {
+ value: FolderIconId | null | undefined;
+ onChange: (iconId: FolderIconId) => void;
+ colorClass?: string;
+}
+
+export function FolderIconPicker({
+ value,
+ onChange,
+ colorClass = "text-gray-600",
+}: FolderIconPickerProps) {
+ const selectedIcon = useMemo(() => {
+ return value || "folder";
+ }, [value]);
+
+ return (
+ <ScrollArea className="h-[200px] rounded-md border p-2">
+ <div className="grid grid-cols-6 gap-2">
+ {FOLDER_ICONS.map((iconOption) => {
+ const IconComponent = iconOption.icon;
+ const isSelected = selectedIcon === iconOption.id;
+
+ return (
+ <button
+ key={iconOption.id}
+ type="button"
+ onClick={() => onChange(iconOption.id)}
+ className={cn(
+ "flex h-10 w-10 items-center justify-center rounded-md border transition-all hover:bg-muted",
+ isSelected
+ ? "border-primary bg-primary/10 ring-2 ring-primary"
+ : "border-transparent",
+ )}
+ title={iconOption.label}
+ >
+ <IconComponent
+ className={cn("h-5 w-5", isSelected ? colorClass : "text-muted-foreground")}
+ strokeWidth={1.5}
+ />
+ </button>
+ );
+ })}
+ </div>
+ </ScrollArea>
+ );
+}
+
+// Preview component for displaying selected icon with color
+interface FolderIconPreviewProps {
+ iconId: FolderIconId | null | undefined;
+ colorClass?: string;
+ className?: string;
+ size?: "sm" | "md" | "lg";
+}
+
+export function FolderIconPreview({
+ iconId,
+ colorClass = "text-gray-600",
+ className,
+ size = "md",
+}: FolderIconPreviewProps) {
+ const IconComponent = getFolderIcon(iconId);
+
+ const sizeClasses = {
+ sm: "h-4 w-4",
+ md: "h-6 w-6",
+ lg: "h-8 w-8",
+ };
+
+ return (
+ <IconComponent
+ className={cn(sizeClasses[size], colorClass, className)}
+ strokeWidth={1.5}
+ />
+ );
+}
diff --git a/components/view/dataroom/folder-card.tsx b/components/view/dataroom/folder-card.tsx
index f7ab2520..acb34b34 100644
--- a/components/view/dataroom/folder-card.tsx
+++ b/components/view/dataroom/folder-card.tsx
@@ -1,9 +1,10 @@
import { useState } from "react";
import { DataroomFolder } from "@prisma/client";
-import { Download, FolderIcon, MoreVerticalIcon } from "lucide-react";
+import { Download, MoreVerticalIcon } from "lucide-react";
import { toast } from "sonner";
+import { getFolderColorClasses, getFolderIcon } from "@/lib/constants/folder-constants";
import { timeAgo } from "@/lib/utils";
import {
HIERARCHICAL_DISPLAY_STYLE,
@@ -103,7 +104,16 @@ export default function FolderCard({
<div className="group/row relative flex items-center justify-between rounded-lg border-0 p-3 ring-1 ring-gray-400 transition-all hover:bg-secondary hover:ring-gray-500 dark:bg-secondary dark:ring-gray-500 hover:dark:ring-gray-400 sm:p-4">
<div className="flex min-w-0 shrink items-center space-x-2 sm:space-x-4">
<div className="mx-0.5 flex w-8 items-center justify-center text-center sm:mx-1">
- <FolderIcon className="h-8 w-8" strokeWidth={1} />
+ {(() => {
+ const FolderIconComponent = getFolderIcon(folder.icon);
+ const colorClasses = getFolderColorClasses(folder.color);
+ return (
+ <FolderIconComponent
+ className={`h-8 w-8 ${colorClasses.iconClass}`}
+ strokeWidth={1}
+ />
+ );
+ })()}
</div>
<div className="flex-col">
diff --git a/lib/constants/folder-constants.ts b/lib/constants/folder-constants.ts
new file mode 100644
index 00000000..d6055ddd
--- /dev/null
+++ b/lib/constants/folder-constants.ts
@@ -0,0 +1,152 @@
+import {
+ ArchiveIcon,
+ BookIcon,
+ BookmarkIcon,
+ BoxIcon,
+ BriefcaseIcon,
+ FileIcon,
+ FolderIcon,
+ FolderOpenIcon,
+ GlobeIcon,
+ HeartIcon,
+ HomeIcon,
+ ImageIcon,
+ LayersIcon,
+ LightbulbIcon,
+ LockIcon,
+ MailIcon,
+ MusicIcon,
+ PaletteIcon,
+ PenToolIcon,
+ SettingsIcon,
+ ShieldIcon,
+ StarIcon,
+ TagIcon,
+ UsersIcon,
+ VideoIcon,
+ WrenchIcon,
+ ZapIcon,
+} from "lucide-react";
+
+// Folder icon definitions
+export const FOLDER_ICONS = [
+ { id: "folder", icon: FolderIcon, label: "Folder" },
+ { id: "folder-open", icon: FolderOpenIcon, label: "Folder Open" },
+ { id: "briefcase", icon: BriefcaseIcon, label: "Briefcase" },
+ { id: "archive", icon: ArchiveIcon, label: "Archive" },
+ { id: "box", icon: BoxIcon, label: "Box" },
+ { id: "file", icon: FileIcon, label: "File" },
+ { id: "book", icon: BookIcon, label: "Book" },
+ { id: "bookmark", icon: BookmarkIcon, label: "Bookmark" },
+ { id: "star", icon: StarIcon, label: "Star" },
+ { id: "heart", icon: HeartIcon, label: "Heart" },
+ { id: "lock", icon: LockIcon, label: "Lock" },
+ { id: "shield", icon: ShieldIcon, label: "Shield" },
+ { id: "users", icon: UsersIcon, label: "Users" },
+ { id: "settings", icon: SettingsIcon, label: "Settings" },
+ { id: "tag", icon: TagIcon, label: "Tag" },
+ { id: "layers", icon: LayersIcon, label: "Layers" },
+ { id: "globe", icon: GlobeIcon, label: "Globe" },
+ { id: "home", icon: HomeIcon, label: "Home" },
+ { id: "mail", icon: MailIcon, label: "Mail" },
+ { id: "image", icon: ImageIcon, label: "Image" },
+ { id: "video", icon: VideoIcon, label: "Video" },
+ { id: "music", icon: MusicIcon, label: "Music" },
+ { id: "palette", icon: PaletteIcon, label: "Palette" },
+ { id: "pen-tool", icon: PenToolIcon, label: "Design" },
+ { id: "lightbulb", icon: LightbulbIcon, label: "Ideas" },
+ { id: "zap", icon: ZapIcon, label: "Quick" },
+ { id: "wrench", icon: WrenchIcon, label: "Tools" },
+] as const;
+
+export type FolderIconId = (typeof FOLDER_ICONS)[number]["id"];
+
+// Folder color palette (using similar colors to tags but with folder-specific styling)
+export const FOLDER_COLORS = [
+ {
+ id: "gray",
+ label: "Gray",
+ text: "text-gray-600",
+ bg: "bg-gray-100",
+ border: "border-gray-300",
+ iconClass: "text-gray-600 dark:text-gray-400",
+ },
+ {
+ id: "red",
+ label: "Red",
+ text: "text-red-600",
+ bg: "bg-red-100",
+ border: "border-red-300",
+ iconClass: "text-red-500 dark:text-red-400",
+ },
+ {
+ id: "orange",
+ label: "Orange",
+ text: "text-orange-600",
+ bg: "bg-orange-100",
+ border: "border-orange-300",
+ iconClass: "text-orange-500 dark:text-orange-400",
+ },
+ {
+ id: "yellow",
+ label: "Yellow",
+ text: "text-yellow-600",
+ bg: "bg-yellow-100",
+ border: "border-yellow-300",
+ iconClass: "text-yellow-500 dark:text-yellow-400",
+ },
+ {
+ id: "green",
+ label: "Green",
+ text: "text-emerald-600",
+ bg: "bg-emerald-100",
+ border: "border-emerald-300",
+ iconClass: "text-emerald-500 dark:text-emerald-400",
+ },
+ {
+ id: "blue",
+ label: "Blue",
+ text: "text-blue-600",
+ bg: "bg-blue-100",
+ border: "border-blue-300",
+ iconClass: "text-blue-500 dark:text-blue-400",
+ },
+ {
+ id: "purple",
+ label: "Purple",
+ 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",
+ },
+] as const;
+
+export type FolderColorId = (typeof FOLDER_COLORS)[number]["id"];
+
+// Allowed values for server-side validation
+export const ALLOWED_FOLDER_ICONS = FOLDER_ICONS.map((icon) => icon.id);
+export const ALLOWED_FOLDER_COLORS = FOLDER_COLORS.map((color) => color.id);
+
+// Default values
+export const DEFAULT_FOLDER_ICON: FolderIconId = "folder";
+export const DEFAULT_FOLDER_COLOR: FolderColorId = "gray";
+
+// Helper to get icon component by ID
+export function getFolderIcon(iconId: string | null | undefined) {
+ const foundIcon = FOLDER_ICONS.find((icon) => icon.id === iconId);
+ return foundIcon?.icon ?? FolderIcon;
+}
+
+// Helper to get color classes by ID
+export function getFolderColorClasses(colorId: string | null | undefined) {
+ const foundColor = FOLDER_COLORS.find((color) => color.id === colorId);
+ return foundColor ?? FOLDER_COLORS[0]; // Default to gray
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/folders/[...name].ts b/pages/api/teams/[teamId]/datarooms/[id]/folders/[...name].ts
index 800d5d82..ae521f72 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/folders/[...name].ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/folders/[...name].ts
@@ -87,6 +87,8 @@ export default async function handle(
dataroomId: true,
orderIndex: true,
hierarchicalIndex: true,
+ icon: true,
+ color: true,
createdAt: true,
updatedAt: true,
_count: {
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts
index f3b40375..7cb5148a 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts
@@ -267,6 +267,8 @@ export default async function handle(
dataroomId: true,
orderIndex: true,
hierarchicalIndex: true,
+ icon: true,
+ color: true,
createdAt: true,
updatedAt: true,
_count: {
@@ -309,6 +311,8 @@ export default async function handle(
dataroomId: true,
orderIndex: true,
hierarchicalIndex: true,
+ icon: true,
+ color: true,
createdAt: true,
updatedAt: true,
documents: {
@@ -361,6 +365,8 @@ export default async function handle(
dataroomId: true,
orderIndex: true,
hierarchicalIndex: true,
+ icon: true,
+ color: true,
createdAt: true,
updatedAt: true,
documents: {
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/folders/manage/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/folders/manage/index.ts
index 8e3e0bd3..84710a89 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/folders/manage/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/folders/manage/index.ts
@@ -4,6 +4,10 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";
import slugify from "@sindresorhus/slugify";
import { getServerSession } from "next-auth/next";
+import {
+ ALLOWED_FOLDER_COLORS,
+ ALLOWED_FOLDER_ICONS,
+} from "@/lib/constants/folder-constants";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
@@ -24,9 +28,33 @@ export default async function handle(
teamId: string;
id: string;
};
- const { folderId, name } = req.body as { folderId: string; name: string };
+ const { folderId, name, icon, color } = req.body as {
+ folderId: string;
+ name: string;
+ icon?: string | null;
+ color?: string | null;
+ };
try {
+ // Validate icon if provided
+ if (icon !== undefined && icon !== null && !ALLOWED_FOLDER_ICONS.includes(icon as any)) {
+ return res.status(400).json({ message: "Invalid folder icon" });
+ }
+
+ // Validate color if provided
+ if (color !== undefined && color !== null && !ALLOWED_FOLDER_COLORS.includes(color as any)) {
+ return res.status(400).json({ message: "Invalid folder color" });
+ }
+
+ // Validate name
+ if (!name || name.trim().length === 0) {
+ return res.status(400).json({ message: "Folder name is required" });
+ }
+
+ if (name.trim().length > 60) {
+ return res.status(400).json({ message: "Folder name must be 60 characters or less" });
+ }
+
const team = await prisma.team.findUnique({
where: {
id: teamId,
@@ -50,6 +78,8 @@ export default async function handle(
select: {
name: true,
path: true,
+ icon: true,
+ color: true,
},
});
@@ -60,21 +90,45 @@ export default async function handle(
// take the old path and replace the last part with the new name
const newPath = folder.path.split("/");
newPath.pop();
- newPath.push(slugify(name));
+ newPath.push(slugify(name.trim()));
+
+ // Build update data object with only changed fields
+ const updateData: {
+ name: string;
+ path: string;
+ icon?: string | null;
+ color?: string | null;
+ } = {
+ name: name.trim(),
+ path: newPath.join("/"),
+ };
+
+ // Only include icon and color in update if they were provided
+ if (icon !== undefined) {
+ updateData.icon = icon;
+ }
+ if (color !== undefined) {
+ updateData.color = color;
+ }
- await prisma.dataroomFolder.update({
+ const updatedFolder = await prisma.dataroomFolder.update({
where: {
id: folderId,
},
- data: {
- name: name,
- path: newPath.join("/"),
- },
+ data: updateData,
});
- return res
- .status(200)
- .json({ message: "Folder name updated successfully" });
+ // Get parent folder path for cache invalidation
+ const parentFolderPath = folder.path.substring(
+ 0,
+ folder.path.lastIndexOf("/"),
+ );
+
+ return res.status(200).json({
+ message: "Folder updated successfully",
+ parentFolderPath: parentFolderPath || "/",
+ folder: updatedFolder,
+ });
} catch (error) {
errorhandler(error, res);
}
diff --git a/pages/api/teams/[teamId]/folders/manage/index.ts b/pages/api/teams/[teamId]/folders/manage/index.ts
index 932119b7..23849f71 100644
--- a/pages/api/teams/[teamId]/folders/manage/index.ts
+++ b/pages/api/teams/[teamId]/folders/manage/index.ts
@@ -4,6 +4,10 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";
import slugify from "@sindresorhus/slugify";
import { getServerSession } from "next-auth/next";
+import {
+ ALLOWED_FOLDER_COLORS,
+ ALLOWED_FOLDER_ICONS,
+} from "@/lib/constants/folder-constants";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
@@ -21,9 +25,33 @@ export default async function handle(
}
const userId = (session.user as CustomUser).id;
const { teamId } = req.query as { teamId: string };
- const { folderId, name } = req.body as { folderId: string; name: string };
+ const { folderId, name, icon, color } = req.body as {
+ folderId: string;
+ name: string;
+ icon?: string | null;
+ color?: string | null;
+ };
try {
+ // Validate icon if provided
+ if (icon !== undefined && icon !== null && !ALLOWED_FOLDER_ICONS.includes(icon as any)) {
+ return res.status(400).json({ message: "Invalid folder icon" });
+ }
+
+ // Validate color if provided
+ if (color !== undefined && color !== null && !ALLOWED_FOLDER_COLORS.includes(color as any)) {
+ return res.status(400).json({ message: "Invalid folder color" });
+ }
+
+ // Validate name
+ if (!name || name.trim().length === 0) {
+ return res.status(400).json({ message: "Folder name is required" });
+ }
+
+ if (name.trim().length > 60) {
+ return res.status(400).json({ message: "Folder name must be 60 characters or less" });
+ }
+
const team = await prisma.team.findUnique({
where: {
id: teamId,
@@ -46,6 +74,8 @@ export default async function handle(
select: {
name: true,
path: true,
+ icon: true,
+ color: true,
},
});
@@ -56,21 +86,45 @@ export default async function handle(
// take the old path and replace the last part with the new name
const newPath = folder.path.split("/");
newPath.pop();
- newPath.push(slugify(name));
+ newPath.push(slugify(name.trim()));
- await prisma.folder.update({
+ // Build update data object with only changed fields
+ const updateData: {
+ name: string;
+ path: string;
+ icon?: string | null;
+ color?: string | null;
+ } = {
+ name: name.trim(),
+ path: newPath.join("/"),
+ };
+
+ // Only include icon and color in update if they were provided
+ if (icon !== undefined) {
+ updateData.icon = icon;
+ }
+ if (color !== undefined) {
+ updateData.color = color;
+ }
+
+ const updatedFolder = await prisma.folder.update({
where: {
id: folderId,
},
- data: {
- name: name,
- path: newPath.join("/"),
- },
+ data: updateData,
});
- return res
- .status(200)
- .json({ message: "Folder name updated successfully" });
+ // Get parent folder path for cache invalidation
+ const parentFolderPath = folder.path.substring(
+ 0,
+ folder.path.lastIndexOf("/"),
+ );
+
+ return res.status(200).json({
+ message: "Folder updated successfully",
+ parentFolderPath: parentFolderPath || "/",
+ folder: updatedFolder,
+ });
} catch (error) {
errorhandler(error, res);
}
diff --git a/prisma/migrations/20260120000000_add_folder_icon_color/migration.sql b/prisma/migrations/20260120000000_add_folder_icon_color/migration.sql
new file mode 100644
index 00000000..42e54a43
--- /dev/null
+++ b/prisma/migrations/20260120000000_add_folder_icon_color/migration.sql
@@ -0,0 +1,7 @@
+-- AlterTable
+ALTER TABLE "Folder" ADD COLUMN "icon" TEXT;
+ALTER TABLE "Folder" ADD COLUMN "color" TEXT;
+
+-- AlterTable
+ALTER TABLE "DataroomFolder" ADD COLUMN "icon" TEXT;
+ALTER TABLE "DataroomFolder" ADD COLUMN "color" TEXT;
diff --git a/prisma/schema/dataroom.prisma b/prisma/schema/dataroom.prisma
index da3c71cf..b59c0d99 100644
--- a/prisma/schema/dataroom.prisma
+++ b/prisma/schema/dataroom.prisma
@@ -86,6 +86,8 @@ model DataroomFolder {
name String
path String // the materialized path to the folder; starts always with "/"
parentId String?
+ icon String? // Icon identifier from predefined icon set (e.g., "folder", "briefcase", "archive")
+ color String? // Color from predefined palette (e.g., "gray", "red", "blue")
documents DataroomDocument[]
childFolders DataroomFolder[] @relation("SubFolders")
parentFolder DataroomFolder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)
diff --git a/prisma/schema/document.prisma b/prisma/schema/document.prisma
index bd111834..ed024596 100644
--- a/prisma/schema/document.prisma
+++ b/prisma/schema/document.prisma
@@ -100,6 +100,8 @@ model Folder {
path String // the materialized path to the folder; starts always with "/"
parentId String?
hiddenInAllDocuments Boolean @default(false) // Indicates if the folder is hidden from All Documents view
+ icon String? // Icon identifier from predefined icon set (e.g., "folder", "briefcase", "archive")
+ color String? // Color from predefined palette (e.g., "gray", "red", "blue")
documents Document[]
childFolders Folder[] @relation("SubFolders")
parentFolder Folder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)