Skip to content

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

feat: data room from templates

Marc Seitz1b6e746d5664
diff --git a/components/datarooms/add-dataroom-modal.tsx b/components/datarooms/add-dataroom-modal.tsx
index 94315fc2..a7277185 100644
--- a/components/datarooms/add-dataroom-modal.tsx
+++ b/components/datarooms/add-dataroom-modal.tsx
@@ -4,25 +4,39 @@ import { useState } from "react";
import { useTeam } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
+import { XIcon } from "lucide-react";
import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";
+import { useAnalytics } from "@/lib/analytics";
+import { usePlan } from "@/lib/swr/use-billing";
+
import { Button } from "@/components/ui/button";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
import {
Dialog,
DialogContent,
DialogDescription,
- DialogFooter,
- DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
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 {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
@@ -39,21 +53,55 @@ export function AddDataroomModal({
const [dataroomName, setDataroomName] = useState<string>("");
const [loading, setLoading] = useState<boolean>(false);
const [open, setOpen] = useState<boolean>(openModal);
+ const [activeTab, setActiveTab] = useState<string>("create");
+ const [dataroomType, setDataroomType] = useState<string>("");
const teamInfo = useTeam();
const { isFree, isPro } = usePlan();
const analytics = useAnalytics();
+
+ const useTemplate = activeTab === "generate";
+
const dataroomSchema = z.object({
name: z.string().trim().min(3, {
message: "Please provide a dataroom name with at least 3 characters.",
}),
+ type: z.string().optional(),
+ });
+
+ const dataroomSchemaWithType = z.object({
+ name: z.string().trim().min(3, {
+ message: "Please provide a dataroom name with at least 3 characters.",
+ }),
+ type: z.enum(
+ [
+ "startup-fundraising",
+ "raising-first-fund",
+ "ma-acquisition",
+ "series-a-plus",
+ "real-estate-transaction",
+ "fund-management",
+ "portfolio-management",
+ "project-management",
+ "sales-dataroom",
+ ],
+ {
+ errorMap: () => ({ message: "Please select a dataroom type." }),
+ },
+ ),
});
const handleSubmit = async (event: any) => {
event.preventDefault();
event.stopPropagation();
- const validation = dataroomSchema.safeParse({ name: dataroomName });
+ // Validate based on whether template is enabled
+ const schema = useTemplate ? dataroomSchemaWithType : dataroomSchema;
+ const validation = schema.safeParse({
+ name: dataroomName,
+ type: useTemplate ? dataroomType : undefined,
+ });
+
if (!validation.success) {
return toast.error(validation.error.errors[0].message);
}
@@ -61,18 +109,22 @@ export function AddDataroomModal({
setLoading(true);
try {
- const response = await fetch(
- `/api/teams/${teamInfo?.currentTeam?.id}/datarooms`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- name: dataroomName.trim(),
- }),
+ // Use different endpoint based on whether template is enabled
+ const endpoint = useTemplate
+ ? `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/generate`
+ : `/api/teams/${teamInfo?.currentTeam?.id}/datarooms`;
+
+ const body = useTemplate
+ ? { name: dataroomName.trim(), type: dataroomType }
+ : { name: dataroomName.trim() };
+
+ const response = await fetch(endpoint, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
},
- );
+ body: JSON.stringify(body),
+ });
if (!response.ok) {
const { message } = await response.json();
@@ -83,10 +135,20 @@ export function AddDataroomModal({
const { dataroom } = await response.json();
- analytics.capture("Dataroom Created", { dataroomName: dataroomName });
+ analytics.capture(
+ useTemplate ? "Dataroom Generated" : "Dataroom Created",
+ {
+ dataroomName: dataroomName,
+ ...(useTemplate && { dataroomType: dataroomType }),
+ },
+ );
mutate(`/api/teams/${teamInfo?.currentTeam?.id}/datarooms`);
- toast.success("Dataroom successfully created! πŸŽ‰");
+ toast.success(
+ useTemplate
+ ? "Dataroom successfully generated! πŸŽ‰"
+ : "Dataroom successfully created! πŸŽ‰",
+ );
router.push(`/datarooms/${dataroom.id}/documents`);
} catch (error) {
setLoading(false);
@@ -116,6 +178,9 @@ export function AddDataroomModal({
const onOpenChange = (open: boolean) => {
if (!open) {
setOpen(false);
+ setDataroomName("");
+ setActiveTab("create");
+ setDataroomType("");
} else {
setOpen(true);
}
@@ -125,29 +190,134 @@ export function AddDataroomModal({
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogTrigger asChild>{children}</DialogTrigger>
- <DialogContent className="sm:max-w-[425px]">
- <DialogHeader className="text-start">
- <DialogTitle>Create dataroom</DialogTitle>
- <DialogDescription>
- Start creating a dataroom with a name.
- </DialogDescription>
- </DialogHeader>
- <form onSubmit={handleSubmit}>
- <Label htmlFor="dataroom-name" className="opacity-80">
- Dataroom Name
- </Label>
- <Input
- id="dataroom-name"
- placeholder="ACME Aquisition"
- className="mb-4 mt-1 w-full"
- onChange={(e) => setDataroomName(e.target.value)}
- />
- <DialogFooter>
- <Button type="submit" className="h-9 w-full" loading={loading}>
- Add new dataroom
- </Button>
- </DialogFooter>
- </form>
+ <DialogContent className="border-none bg-transparent text-foreground shadow-none sm:max-w-[500px] [&>button]:hidden">
+ <DialogTitle className="sr-only">Create Dataroom</DialogTitle>
+ <DialogDescription className="sr-only">
+ Create a new dataroom or generate one with pre-configured folders
+ </DialogDescription>
+
+ <Tabs value={activeTab} onValueChange={setActiveTab}>
+ <TabsList className="grid w-full grid-cols-2">
+ <TabsTrigger value="create">Create from scratch</TabsTrigger>
+ <TabsTrigger value="generate">Generate with template</TabsTrigger>
+ </TabsList>
+
+ <TabsContent value="create">
+ <Card className="relative">
+ <button
+ onClick={() => onOpenChange(false)}
+ className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"
+ >
+ <XIcon className="h-4 w-4" />
+ <span className="sr-only">Close</span>
+ </button>
+ <CardHeader className="space-y-3">
+ <CardTitle>Create dataroom</CardTitle>
+ <CardDescription>
+ Start creating a dataroom with a name.
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="space-y-2">
+ <form
+ onSubmit={handleSubmit}
+ className="flex flex-col space-y-4"
+ >
+ <div className="space-y-1">
+ <Label htmlFor="dataroom-name-create">Dataroom Name</Label>
+ <Input
+ id="dataroom-name-create"
+ placeholder="ACME Aquisition"
+ value={dataroomName}
+ onChange={(e) => setDataroomName(e.target.value)}
+ />
+ </div>
+ <Button type="submit" className="w-full" loading={loading}>
+ Add new dataroom
+ </Button>
+ </form>
+ </CardContent>
+ </Card>
+ </TabsContent>
+
+ <TabsContent value="generate">
+ <Card className="relative">
+ <button
+ onClick={() => onOpenChange(false)}
+ className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"
+ >
+ <XIcon className="h-4 w-4" />
+ <span className="sr-only">Close</span>
+ </button>
+ <CardHeader className="space-y-3">
+ <CardTitle>Create dataroom</CardTitle>
+ <CardDescription>
+ Generate a dataroom with pre-configured folder structure.
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="space-y-2">
+ <form
+ onSubmit={handleSubmit}
+ className="flex flex-col space-y-4"
+ >
+ <div className="space-y-1">
+ <Label htmlFor="dataroom-name-generate">
+ Dataroom Name
+ </Label>
+ <Input
+ id="dataroom-name-generate"
+ placeholder="ACME Aquisition"
+ value={dataroomName}
+ onChange={(e) => setDataroomName(e.target.value)}
+ />
+ </div>
+ <div className="space-y-1">
+ <Label htmlFor="dataroom-type">Dataroom Type</Label>
+ <Select
+ value={dataroomType}
+ onValueChange={setDataroomType}
+ >
+ <SelectTrigger id="dataroom-type">
+ <SelectValue placeholder="Select a type" />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value="startup-fundraising">
+ Startup Fundraising (Early stage)
+ </SelectItem>
+ <SelectItem value="series-a-plus">
+ Series A+ Fundraising
+ </SelectItem>
+ <SelectItem value="raising-first-fund">
+ Raising a Fund (GP/LP)
+ </SelectItem>
+ <SelectItem value="ma-acquisition">
+ M&A / Acquisition
+ </SelectItem>
+ <SelectItem value="sales-dataroom">
+ Sales Data Room
+ </SelectItem>
+ <SelectItem value="real-estate-transaction">
+ Real Estate Transaction
+ </SelectItem>
+ <SelectItem value="fund-management">
+ Fund Management (LP reporting)
+ </SelectItem>
+ <SelectItem value="portfolio-management">
+ Portfolio Management
+ </SelectItem>
+ <SelectItem value="project-management">
+ Project Management
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ </div>
+ <Button type="submit" className="w-full" loading={loading}>
+ Generate new dataroom
+ </Button>
+ </form>
+ </CardContent>
+ </Card>
+ </TabsContent>
+ </Tabs>
</DialogContent>
</Dialog>
);
diff --git a/pages/api/teams/[teamId]/datarooms/generate.ts b/pages/api/teams/[teamId]/datarooms/generate.ts
new file mode 100644
index 00000000..75779674
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/generate.ts
@@ -0,0 +1,742 @@
+import type { NextApiRequest, NextApiResponse } from "next";
+
+import { getLimits } from "@/ee/limits/server";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import slugify from "@sindresorhus/slugify";
+import { getServerSession } from "next-auth/next";
+
+import { newId } from "@/lib/id-helper";
+import prisma from "@/lib/prisma";
+import { CustomUser } from "@/lib/types";
+
+// Define folder templates for each dataroom type
+interface FolderTemplate {
+ name: string;
+ subfolders?: FolderTemplate[];
+}
+
+const DATAROOM_TEMPLATES: Record<
+ string,
+ { name: string; folders: FolderTemplate[] }
+> = {
+ "startup-fundraising": {
+ name: "Startup Fundraising",
+ folders: [
+ { name: "Corporate or Investment Memo" },
+ {
+ name: "Corporate Documents",
+ subfolders: [
+ { name: "Company Registration" },
+ { name: "Group Structure" },
+ { name: "Shareholder Overview" },
+ ],
+ },
+ {
+ name: "Financial Forecast and Actuals",
+ subfolders: [{ name: "Forecasts" }, { name: "Actuals" }],
+ },
+ {
+ name: "Legal and Tax Documents",
+ subfolders: [
+ { name: "Contracts" },
+ { name: "IP Agreements" },
+ { name: "Capitalization Table" },
+ ],
+ },
+ {
+ name: "Go-to-Market and Marketing Strategy",
+ subfolders: [
+ { name: "Business Plan" },
+ { name: "Organizational Chart" },
+ ],
+ },
+ { name: "Product Roadmap" },
+ { name: "Pitch Deck" },
+ ],
+ },
+ "raising-first-fund": {
+ name: "Raising First Fund",
+ folders: [
+ {
+ name: "1 Introduction",
+ subfolders: [{ name: "Presentations" }],
+ },
+ {
+ name: "2 Team",
+ subfolders: [{ name: "CVs & References" }],
+ },
+ {
+ name: "3 Track Record",
+ subfolders: [{ name: "Track record & portfolio references" }],
+ },
+ {
+ name: "4 Fund Model",
+ subfolders: [{ name: "XLSX grantular track record" }],
+ },
+ {
+ name: "5 Legal",
+ subfolders: [{ name: "Executed LPA, bylaws" }],
+ },
+ {
+ name: "6 Portfolio",
+ subfolders: [{ name: "Investment memos of portfolio companies" }],
+ },
+ ],
+ },
+ "ma-acquisition": {
+ name: "M&A / Acquisition",
+ folders: [
+ {
+ name: "1 Executive Summary",
+ subfolders: [
+ { name: "Transaction Overview" },
+ { name: "Investment Highlights" },
+ ],
+ },
+ {
+ name: "2 Corporate Structure & Governance",
+ subfolders: [
+ { name: "Corporate Documents" },
+ { name: "Board Materials" },
+ { name: "Shareholder Agreements" },
+ ],
+ },
+ {
+ name: "3 Financial Information",
+ subfolders: [
+ { name: "Historical Financials" },
+ { name: "Audited Statements" },
+ { name: "Management Accounts" },
+ { name: "Financial Projections" },
+ ],
+ },
+ {
+ name: "4 Legal & Compliance",
+ subfolders: [
+ { name: "Material Contracts" },
+ { name: "Litigation & Disputes" },
+ { name: "Regulatory Compliance" },
+ { name: "Permits & Licenses" },
+ ],
+ },
+ {
+ name: "5 Intellectual Property",
+ subfolders: [
+ { name: "Patents & Trademarks" },
+ { name: "Licenses & Assignments" },
+ { name: "IP Agreements" },
+ ],
+ },
+ {
+ name: "6 Contracts & Agreements",
+ subfolders: [
+ { name: "Customer Contracts" },
+ { name: "Supplier Agreements" },
+ { name: "Partnership Agreements" },
+ ],
+ },
+ {
+ name: "7 Human Resources",
+ subfolders: [
+ { name: "Employee List" },
+ { name: "Employment Agreements" },
+ { name: "Benefits & Compensation" },
+ { name: "Organization Chart" },
+ ],
+ },
+ {
+ name: "8 Tax Documents",
+ subfolders: [{ name: "Tax Returns" }, { name: "Tax Assessments" }],
+ },
+ {
+ name: "9 Assets & Liabilities",
+ subfolders: [
+ { name: "Real Estate" },
+ { name: "Equipment & Inventory" },
+ { name: "Debt & Obligations" },
+ ],
+ },
+ {
+ name: "10 Insurance",
+ subfolders: [
+ { name: "Insurance Policies" },
+ { name: "Claims History" },
+ ],
+ },
+ ],
+ },
+ "series-a-plus": {
+ name: "Series A+ Fundraising",
+ folders: [
+ {
+ name: "1 Investment Memorandum",
+ subfolders: [{ name: "Executive Summary" }, { name: "Pitch Deck" }],
+ },
+ {
+ name: "2 Financial Information",
+ subfolders: [
+ { name: "Historical Financials" },
+ { name: "Financial Projections" },
+ { name: "Unit Economics" },
+ { name: "KPI Dashboard" },
+ ],
+ },
+ {
+ name: "3 Corporate Documents",
+ subfolders: [
+ { name: "Incorporation Documents" },
+ { name: "Board Materials" },
+ { name: "Shareholder Agreements" },
+ ],
+ },
+ {
+ name: "4 Cap Table & Term Sheets",
+ subfolders: [
+ { name: "Capitalization Table" },
+ { name: "Previous Rounds" },
+ { name: "Stock Option Pool" },
+ ],
+ },
+ {
+ name: "5 Product & Technology",
+ subfolders: [
+ { name: "Product Roadmap" },
+ { name: "Technical Documentation" },
+ { name: "Product Demos" },
+ ],
+ },
+ {
+ name: "6 Market & Traction",
+ subfolders: [
+ { name: "Market Analysis" },
+ { name: "Customer Data" },
+ { name: "Growth Metrics" },
+ { name: "Case Studies" },
+ ],
+ },
+ {
+ name: "7 Team & Organization",
+ subfolders: [
+ { name: "Team Bios" },
+ { name: "Organizational Chart" },
+ { name: "Advisory Board" },
+ { name: "Key Hires Plan" },
+ ],
+ },
+ {
+ name: "8 Legal & IP",
+ subfolders: [
+ { name: "IP Portfolio" },
+ { name: "Material Contracts" },
+ { name: "Compliance Documents" },
+ ],
+ },
+ {
+ name: "9 Competitive Analysis",
+ subfolders: [
+ { name: "Competitive Landscape" },
+ { name: "Differentiation" },
+ ],
+ },
+ {
+ name: "10 Use of Funds",
+ subfolders: [{ name: "Budget Allocation" }, { name: "Milestones" }],
+ },
+ ],
+ },
+ "real-estate-transaction": {
+ name: "Real Estate Transaction",
+ folders: [
+ {
+ name: "1 Property Information",
+ subfolders: [
+ { name: "Property Overview" },
+ { name: "Location & Site Plans" },
+ { name: "Building Specifications" },
+ ],
+ },
+ {
+ name: "2 Title & Ownership",
+ subfolders: [
+ { name: "Title Documents" },
+ { name: "Ownership Structure" },
+ { name: "Deed & Transfer Documents" },
+ ],
+ },
+ {
+ name: "3 Legal Documents",
+ subfolders: [
+ { name: "Purchase Agreements" },
+ { name: "Easements & Restrictions" },
+ { name: "Zoning & Permits" },
+ ],
+ },
+ {
+ name: "4 Financial Information",
+ subfolders: [
+ { name: "Operating Statements" },
+ { name: "Rent Roll" },
+ { name: "Expense Reports" },
+ { name: "Tax Assessments" },
+ ],
+ },
+ {
+ name: "5 Leases & Tenancies",
+ subfolders: [
+ { name: "Tenant Leases" },
+ { name: "Tenant Correspondence" },
+ { name: "Lease Abstracts" },
+ ],
+ },
+ {
+ name: "6 Property Surveys & Plans",
+ subfolders: [
+ { name: "Survey Reports" },
+ { name: "Floor Plans" },
+ { name: "As-Built Drawings" },
+ ],
+ },
+ {
+ name: "7 Environmental Reports",
+ subfolders: [
+ { name: "Environmental Assessments" },
+ { name: "Soil Reports" },
+ { name: "Remediation Documents" },
+ ],
+ },
+ {
+ name: "8 Building Inspections",
+ subfolders: [
+ { name: "Structural Inspections" },
+ { name: "Engineering Reports" },
+ { name: "Maintenance Records" },
+ ],
+ },
+ {
+ name: "9 Property Management",
+ subfolders: [
+ { name: "Management Agreements" },
+ { name: "Vendor Contracts" },
+ { name: "Service Agreements" },
+ ],
+ },
+ {
+ name: "10 Insurance & Warranties",
+ subfolders: [
+ { name: "Insurance Policies" },
+ { name: "Warranties" },
+ { name: "Claims History" },
+ ],
+ },
+ ],
+ },
+ "fund-management": {
+ name: "Fund Management",
+ folders: [
+ {
+ name: "1 Fund Documents",
+ subfolders: [
+ { name: "Fund Formation Documents" },
+ { name: "LPA & Side Letters" },
+ { name: "Fund Policies" },
+ ],
+ },
+ {
+ name: "2 LP Relations",
+ subfolders: [
+ { name: "LP Commitments" },
+ { name: "Capital Calls" },
+ { name: "Distribution Notices" },
+ { name: "LP Communications" },
+ ],
+ },
+ {
+ name: "3 Financial Reporting",
+ subfolders: [
+ { name: "Quarterly Reports" },
+ { name: "Annual Reports" },
+ { name: "NAV Statements" },
+ { name: "Cash Flow Reports" },
+ ],
+ },
+ {
+ name: "4 Compliance & Legal",
+ subfolders: [
+ { name: "Regulatory Filings" },
+ { name: "Audit Reports" },
+ { name: "Tax Documents" },
+ { name: "Legal Opinions" },
+ ],
+ },
+ {
+ name: "5 Investment Activities",
+ subfolders: [
+ { name: "Investment Memos" },
+ { name: "Deal Pipeline" },
+ { name: "Investment Committee Materials" },
+ ],
+ },
+ {
+ name: "6 Portfolio Monitoring",
+ subfolders: [
+ { name: "Portfolio Company Updates" },
+ { name: "Board Materials" },
+ { name: "Valuations" },
+ ],
+ },
+ {
+ name: "7 Operations",
+ subfolders: [
+ { name: "Fund Administration" },
+ { name: "Service Provider Agreements" },
+ { name: "Policies & Procedures" },
+ ],
+ },
+ {
+ name: "8 Investor Communications",
+ subfolders: [
+ { name: "Investor Letters" },
+ { name: "Meeting Materials" },
+ { name: "AGM Documents" },
+ ],
+ },
+ ],
+ },
+ "portfolio-management": {
+ name: "Portfolio Management",
+ folders: [
+ {
+ name: "1 Portfolio Overview",
+ subfolders: [
+ { name: "Portfolio Summary" },
+ { name: "Portfolio Strategy" },
+ { name: "Performance Dashboard" },
+ ],
+ },
+ {
+ name: "2 Portfolio Companies",
+ subfolders: [
+ { name: "Company Profiles" },
+ { name: "Investment Theses" },
+ { name: "Ownership Information" },
+ ],
+ },
+ {
+ name: "3 Financial Performance",
+ subfolders: [
+ { name: "Company Financials" },
+ { name: "KPI Reports" },
+ { name: "Valuations" },
+ { name: "Return Analysis" },
+ ],
+ },
+ {
+ name: "4 Board & Governance",
+ subfolders: [
+ { name: "Board Decks" },
+ { name: "Meeting Minutes" },
+ { name: "Board Observer Rights" },
+ ],
+ },
+ {
+ name: "5 Operational Support",
+ subfolders: [
+ { name: "Value Creation Plans" },
+ { name: "Strategic Initiatives" },
+ { name: "Operational Reviews" },
+ ],
+ },
+ {
+ name: "6 Deal Documents",
+ subfolders: [
+ { name: "Investment Agreements" },
+ { name: "Shareholder Agreements" },
+ { name: "Cap Tables" },
+ ],
+ },
+ {
+ name: "7 Follow-on & Exits",
+ subfolders: [
+ { name: "Follow-on Analysis" },
+ { name: "Exit Planning" },
+ { name: "M&A Materials" },
+ ],
+ },
+ {
+ name: "8 Portfolio Monitoring",
+ subfolders: [
+ { name: "Monthly Updates" },
+ { name: "Risk Assessments" },
+ { name: "Action Items" },
+ ],
+ },
+ ],
+ },
+ "project-management": {
+ name: "Project Management",
+ folders: [
+ {
+ name: "1 Project Overview",
+ subfolders: [
+ { name: "Project Charter" },
+ { name: "Scope & Objectives" },
+ { name: "Project Plan" },
+ ],
+ },
+ {
+ name: "2 Requirements & Specifications",
+ subfolders: [
+ { name: "Requirements Documentation" },
+ { name: "Technical Specifications" },
+ { name: "User Stories" },
+ ],
+ },
+ {
+ name: "3 Project Planning",
+ subfolders: [
+ { name: "Work Breakdown Structure" },
+ { name: "Timeline & Milestones" },
+ { name: "Resource Plan" },
+ { name: "Budget" },
+ ],
+ },
+ {
+ name: "4 Team & Stakeholders",
+ subfolders: [
+ { name: "Team Directory" },
+ { name: "Roles & Responsibilities" },
+ { name: "Stakeholder Matrix" },
+ ],
+ },
+ {
+ name: "5 Project Execution",
+ subfolders: [
+ { name: "Sprint Plans" },
+ { name: "Task Tracking" },
+ { name: "Deliverables" },
+ ],
+ },
+ {
+ name: "6 Communication",
+ subfolders: [
+ { name: "Status Reports" },
+ { name: "Meeting Notes" },
+ { name: "Stakeholder Updates" },
+ ],
+ },
+ {
+ name: "7 Risk & Issues",
+ subfolders: [
+ { name: "Risk Register" },
+ { name: "Issue Log" },
+ { name: "Change Requests" },
+ ],
+ },
+ {
+ name: "8 Quality & Testing",
+ subfolders: [
+ { name: "Quality Standards" },
+ { name: "Test Plans" },
+ { name: "Acceptance Criteria" },
+ ],
+ },
+ {
+ name: "9 Documentation",
+ subfolders: [
+ { name: "Process Documentation" },
+ { name: "User Guides" },
+ { name: "Training Materials" },
+ ],
+ },
+ {
+ name: "10 Project Closure",
+ subfolders: [
+ { name: "Final Reports" },
+ { name: "Lessons Learned" },
+ { name: "Handover Documents" },
+ ],
+ },
+ ],
+ },
+ "sales-dataroom": {
+ name: "Sales Data Room",
+ folders: [
+ {
+ name: "1 Sales Materials",
+ subfolders: [
+ { name: "Sales Decks" },
+ { name: "Product Brochures" },
+ { name: "One Pagers" },
+ ],
+ },
+ {
+ name: "2 Proposals & Quotes",
+ subfolders: [{ name: "Proposals" }, { name: "Pricing" }],
+ },
+ {
+ name: "3 Contracts & Agreements",
+ subfolders: [
+ { name: "Master Service Agreements" },
+ { name: "NDAs" },
+ { name: "Terms & Conditions" },
+ ],
+ },
+ {
+ name: "4 Product Information",
+ subfolders: [
+ { name: "Product Specs" },
+ { name: "Demo Videos" },
+ { name: "Case Studies" },
+ ],
+ },
+ {
+ name: "5 Customer References",
+ subfolders: [{ name: "Testimonials" }, { name: "Reference Letters" }],
+ },
+ {
+ name: "6 Security & Compliance",
+ subfolders: [
+ { name: "Security Documentation" },
+ { name: "Compliance Certificates" },
+ { name: "Insurance Certificates" },
+ ],
+ },
+ ],
+ },
+};
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "POST") {
+ // POST /api/teams/:teamId/datarooms/generate
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ res.status(401).end("Unauthorized");
+ return;
+ }
+
+ const userId = (session.user as CustomUser).id;
+
+ const { teamId } = req.query as { teamId: string };
+ const { name, type } = req.body as { name: string; type: string };
+
+ // Validate the type
+ if (!type || !DATAROOM_TEMPLATES[type]) {
+ return res.status(400).json({
+ message: "Invalid dataroom type. Please select a valid type.",
+ });
+ }
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ plan: {
+ // exclude all teams not on `business`, `datarooms`, `datarooms-plus`, `business+old`, `datarooms+old`, `datarooms-plus+old` plan
+ in: [
+ "business",
+ "datarooms",
+ "datarooms-plus",
+ "business+old",
+ "datarooms+old",
+ "datarooms-plus+old",
+ "datarooms+drtrial",
+ "business+drtrial",
+ "datarooms-plus+drtrial",
+ ],
+ },
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ // Limits: Check if the user has reached the limit of datarooms in the team
+ const dataroomCount = await prisma.dataroom.count({
+ where: {
+ teamId: teamId,
+ },
+ });
+
+ const limits = await getLimits({ teamId, userId });
+
+ if (limits && dataroomCount >= limits.datarooms) {
+ return res
+ .status(403)
+ .json({ message: "You have reached the limit of datarooms" });
+ }
+
+ const pId = newId("dataroom");
+
+ // Create the dataroom
+ const dataroom = await prisma.dataroom.create({
+ data: {
+ name: name,
+ teamId: teamId,
+ pId: pId,
+ },
+ });
+
+ // Create folders based on the selected template
+ const template = DATAROOM_TEMPLATES[type];
+
+ // Helper function to create folders recursively
+ const createFolders = async (
+ folders: FolderTemplate[],
+ parentPath: string = "",
+ parentId: string | null = null,
+ ): Promise<void> => {
+ for (const folder of folders) {
+ const folderPath = parentPath + "/" + slugify(folder.name);
+
+ // Create the folder
+ const createdFolder = await prisma.dataroomFolder.create({
+ data: {
+ name: folder.name,
+ path: folderPath,
+ parentId: parentId,
+ dataroomId: dataroom.id,
+ },
+ });
+
+ // If the folder has subfolders, create them recursively
+ if (folder.subfolders && folder.subfolders.length > 0) {
+ await createFolders(
+ folder.subfolders,
+ folderPath,
+ createdFolder.id,
+ );
+ }
+ }
+ };
+
+ await createFolders(template.folders);
+
+ const dataroomWithCount = {
+ ...dataroom,
+ _count: { documents: 0 },
+ };
+
+ res.status(201).json({
+ dataroom: dataroomWithCount,
+ message: "Dataroom generated successfully",
+ });
+ } catch (error) {
+ console.error("Error generating dataroom:", error);
+ return res.status(500).json({ error: "Error generating dataroom" });
+ }
+ } else {
+ // We only allow POST requests
+ res.setHeader("Allow", ["POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}