Files
zeekayandmarcftone c3ef17f099 feat: Add folder customization with icon and color selection
- Add icon and color columns to Folder and DataroomFolder models
- Create Prisma migration for new columns
- Add folder icon list (27 icons) and color palette (8 colors) constants
- Update API endpoints to validate and persist icon/color fields
- Create FolderIconPicker and FolderColorPicker UI components
- Update EditFolderModal with icon/color selection and live preview
- Update FolderCard components to display custom icons/colors
- Support both regular folders and dataroom folders

Closes PM-466

Co-authored-by: marcftone <[email protected]>
2026-01-20 07:39:33 +00:00

111 lines
2.9 KiB
TypeScript

import { NextApiRequest, NextApiResponse } from "next";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { getServerSession } from "next-auth/next";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
import { folderPathSchema } from "@/lib/zod/schemas/folders";
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method === "GET") {
// GET /api/teams/:teamId/datarooms/:id/folders/:name
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}
const userId = (session.user as CustomUser).id;
const {
teamId,
id: dataroomId,
name,
} = req.query as { teamId: string; id: string; name: string[] };
// Validate that name is an array of strings using shared Zod schema
const nameValidation = folderPathSchema.safeParse(name);
if (!nameValidation.success) {
return res.status(400).json({
error: "Invalid folder path format",
details: nameValidation.error.issues.map((issue) => issue.message),
});
}
const validatedName = nameValidation.data;
const path = "/" + validatedName.join("/"); // construct the materialized path
try {
// Check if the user is part of the team
const team = await prisma.team.findUnique({
where: {
id: teamId,
users: {
some: {
userId: userId,
},
},
},
});
if (!team) {
return res.status(401).end("Unauthorized");
}
const parentFolder = await prisma.dataroomFolder.findUnique({
where: {
dataroomId_path: {
dataroomId,
path,
},
},
select: {
id: true,
parentId: true,
},
});
if (!parentFolder) {
return res.status(404).end("Parent Folder not found");
}
const folders = await prisma.dataroomFolder.findMany({
where: {
dataroomId,
parentId: parentFolder.id,
},
orderBy: {
name: "asc",
},
select: {
id: true,
name: true,
path: true,
parentId: true,
dataroomId: true,
orderIndex: true,
hierarchicalIndex: true,
icon: true,
color: true,
createdAt: true,
updatedAt: true,
_count: {
select: { documents: true, childFolders: true },
},
},
});
return res.status(200).json(folders);
} catch (error) {
console.error("Request error", error);
return res.status(500).json({ error: "Error fetching folders" });
}
} else {
// We only allow POST requests
res.setHeader("Allow", ["GET", "POST"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
}