Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat(dataroom): add setting for new document additions
Ashish Viradiyaed08e9520fdd
diff --git a/components/datarooms/settings/notification-settings.tsx b/components/datarooms/settings/notification-settings.tsxnew file mode 100644index 00000000..ed954edf--- /dev/null+++ b/components/datarooms/settings/notification-settings.tsx@@ -0,0 +1,100 @@+import { useTeam } from "@/context/team-context";+import { toast } from "sonner";+import useSWR from "swr";++import { fetcher } from "@/lib/utils";++import {+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+} from "@/components/ui/card";+import { Label } from "@/components/ui/label";+import { Switch } from "@/components/ui/switch";++interface NotificationSettingsProps {+ dataroomId: string;+}++export default function NotificationSettings({+ dataroomId,+}: NotificationSettingsProps) {+ const teamInfo = useTeam();+ const teamId = teamInfo?.currentTeam?.id;++ const { data: features } = useSWR<{ roomChangeNotifications: boolean }>(+ teamInfo?.currentTeam?.id+ ? `/api/feature-flags?teamId=${teamInfo.currentTeam.id}`+ : null,+ fetcher,+ );++ const { data: dataroomData, mutate: mutateDataroom } = useSWR<{+ id: string;+ name: string;+ pId: string;+ notifyOnNewDocument: boolean;+ }>(+ dataroomId ? `/api/teams/${teamId}/datarooms/${dataroomId}` : null,+ fetcher,+ );++ const handleNotificationToggle = async (checked: boolean) => {+ if (!dataroomId || !teamId) return;++ toast.promise(+ fetch(`/api/teams/${teamId}/datarooms/${dataroomId}`, {+ method: "PATCH",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ notifyOnNewDocument: checked,+ }),+ }).then(async (res) => {+ if (!res.ok) {+ throw new Error("Failed to update notification settings");+ }+ await mutateDataroom();+ }),+ {+ loading: "Updating notification settings...",+ success: "Notification settings updated successfully",+ error: "Failed to update notification settings",+ },+ );+ };++ if (!features?.roomChangeNotifications) {+ return null;+ }++ return (+ <Card>+ <CardHeader>+ <CardTitle>Notifications</CardTitle>+ <CardDescription>+ Configure notification settings for this dataroom.+ </CardDescription>+ </CardHeader>+ <CardContent>+ <div className="flex items-center space-x-4">+ <Switch+ id="notify-on-new-document"+ checked={dataroomData?.notifyOnNewDocument ?? true}+ onCheckedChange={handleNotificationToggle}+ />+ <Label htmlFor="notify-on-new-document">+ Notify verified visitors when new documents are added+ </Label>+ </div>+ <p className="mt-2 text-sm text-muted-foreground">+ When enabled, verified visitors will receive an email notification+ when new documents are added to this dataroom.+ </p>+ </CardContent>+ </Card>+ );+}diff --git a/components/datarooms/settings/settings-tabs.tsx b/components/datarooms/settings/settings-tabs.tsxnew file mode 100644index 00000000..7b9be690--- /dev/null+++ b/components/datarooms/settings/settings-tabs.tsx@@ -0,0 +1,44 @@+import Link from "next/link";+import { useRouter } from "next/router";++import { BellIcon, CogIcon } from "lucide-react";++import { cn } from "@/lib/utils";++interface SettingsTabsProps {+ dataroomId: string;+}++export default function SettingsTabs({ dataroomId }: SettingsTabsProps) {+ const router = useRouter();++ return (+ <nav className="grid space-y-1 text-sm">+ <Link+ href={`/datarooms/${dataroomId}/settings`}+ className={cn(+ "flex items-center gap-x-2 rounded-md p-2 text-primary hover:bg-muted",+ {+ "bg-muted font-medium":+ router.pathname === `/datarooms/[id]/settings`,+ },+ )}+ >+ <CogIcon className="h-4 w-4" />+ General+ </Link>+ <Link+ href={`/datarooms/${dataroomId}/settings/notifications`}+ className={cn(+ "flex items-center gap-x-2 rounded-md p-2 text-primary hover:bg-muted",+ {+ "bg-muted font-medium": router.pathname.includes("notifications"),+ },+ )}+ >+ <BellIcon className="h-4 w-4" />+ Notifications+ </Link>+ </nav>+ );+}diff --git a/pages/api/teams/[teamId]/datarooms/[id]/documents/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/documents/index.tsindex 4f7188e5..062b2749 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/documents/index.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/documents/index.ts@@ -154,6 +154,7 @@ export default async function handle(include: {dataroom: {select: {+ notifyOnNewDocument: true,links: {select: { id: true },orderBy: { createdAt: "desc" },@@ -165,10 +166,10 @@ export default async function handle(},});- // Check if the team has the change notification feature flag enabled+ // Check if the team has the change notification feature flag enabled and dataroom notifications are enabledconst featureFlags = await getFeatureFlags({ teamId });- if (featureFlags.roomChangeNotifications) {+ if (featureFlags.roomChangeNotifications && document.dataroom.notifyOnNewDocument) {// Get all delayed and queued runs for this dataroomconst allRuns = await runs.list({taskIdentifier: ["send-dataroom-change-notification"],diff --git a/pages/api/teams/[teamId]/datarooms/[id]/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/index.tsindex 66167216..208badf3 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/index.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/index.ts@@ -64,7 +64,6 @@ export default async function handle(teamId: string;id: string;};- const { name } = req.body as { name: string };const userId = (session.user as CustomUser).id;@@ -85,12 +84,21 @@ export default async function handle(return res.status(401).end("Unauthorized");}+ const { name, notifyOnNewDocument } = req.body as {+ name?: string;+ notifyOnNewDocument?: boolean;+ };+const dataroom = await prisma.dataroom.update({where: {id: dataroomId,- teamId,},- data: { name: name },+ data: {+ ...(name && { name }),+ ...(typeof notifyOnNewDocument === "boolean" && {+ notifyOnNewDocument,+ }),+ },});return res.status(200).json(dataroom);@@ -152,7 +160,7 @@ export default async function handle(errorhandler(error, res);}} else {- // We only allow GET requests+ // We only allow GET, and PATCH requestsres.setHeader("Allow", ["GET", "PATCH"]);return res.status(405).end(`Method ${req.method} Not Allowed`);}diff --git a/pages/datarooms/[id]/settings/index.tsx b/pages/datarooms/[id]/settings/index.tsxindex c56c7e63..9236c2eb 100644--- a/pages/datarooms/[id]/settings/index.tsx+++ b/pages/datarooms/[id]/settings/index.tsx@@ -1,5 +1,3 @@-import Link from "next/link";-import { useState } from "react";import { useTeam } from "@/context/team-context";@@ -14,6 +12,7 @@ import { DataroomHeader } from "@/components/datarooms/dataroom-header";import { DataroomNavigation } from "@/components/datarooms/dataroom-navigation";import DeleteDataroom from "@/components/datarooms/settings/delete-dataroooom";import DuplicateDataroom from "@/components/datarooms/settings/duplicate-dataroom";+import SettingsTabs from "@/components/datarooms/settings/settings-tabs";import AppLayout from "@/components/layouts/app";import { Button } from "@/components/ui/button";import {@@ -26,7 +25,6 @@ import {} from "@/components/ui/card";import { Form } from "@/components/ui/form";import { Input } from "@/components/ui/input";-import { Label } from "@/components/ui/label";export default function Settings() {const { dataroom } = useDataroom();@@ -58,14 +56,7 @@ export default function Settings() {<h1 className="text-2xl font-semibold">Settings</h1></div><div className="mx-auto grid w-full items-start gap-6 md:grid-cols-[180px_1fr] lg:grid-cols-[250px_1fr]">- <nav className="grid gap-2 text-sm text-muted-foreground">- <Link- href={`/datarooms/${dataroom.id}/settings`}- className="rounded-lg bg-muted px-2 py-1 font-semibold text-primary"- >- General- </Link>- </nav>+ <SettingsTabs dataroomId={dataroom.id} /><div className="grid gap-6"><Formtitle="Dataroom Name"diff --git a/pages/datarooms/[id]/settings/notifications.tsx b/pages/datarooms/[id]/settings/notifications.tsxnew file mode 100644index 00000000..cd2e79d6--- /dev/null+++ b/pages/datarooms/[id]/settings/notifications.tsx@@ -0,0 +1,42 @@+import { useDataroom } from "@/lib/swr/use-dataroom";++import { DataroomHeader } from "@/components/datarooms/dataroom-header";+import { DataroomNavigation } from "@/components/datarooms/dataroom-navigation";+import NotificationSettings from "@/components/datarooms/settings/notification-settings";+import SettingsTabs from "@/components/datarooms/settings/settings-tabs";+import AppLayout from "@/components/layouts/app";++export default function Notifications() {+ const { dataroom } = useDataroom();++ if (!dataroom) {+ return <div>Loading...</div>;+ }++ return (+ <AppLayout>+ <main className="relative mx-2 mb-10 mt-4 space-y-8 overflow-hidden px-1 sm:mx-3 md:mx-5 md:mt-5 lg:mx-7 lg:mt-8 xl:mx-10">+ <header>+ <DataroomHeader+ title={dataroom.name}+ description={dataroom.pId}+ actions={[]}+ />++ <DataroomNavigation dataroomId={dataroom.id} />+ </header>++ {/* Settings */}+ <div className="mx-auto grid w-full gap-2">+ <h1 className="text-2xl font-semibold">Settings</h1>+ </div>+ <div className="mx-auto grid w-full items-start gap-6 md:grid-cols-[180px_1fr] lg:grid-cols-[250px_1fr]">+ <SettingsTabs dataroomId={dataroom.id} />+ <div className="grid gap-6">+ <NotificationSettings dataroomId={dataroom.id} />+ </div>+ </div>+ </main>+ </AppLayout>+ );+}diff --git a/prisma/migrations/20250511192249_added_notify_on_new_document/migration.sql b/prisma/migrations/20250511192249_added_notify_on_new_document/migration.sqlnew file mode 100644index 00000000..3ce725e3--- /dev/null+++ b/prisma/migrations/20250511192249_added_notify_on_new_document/migration.sql@@ -0,0 +1,2 @@+-- AlterTable+ALTER TABLE "Dataroom" ADD COLUMN "notifyOnNewDocument" BOOLEAN NOT NULL DEFAULT true;diff --git a/prisma/schema/dataroom.prisma b/prisma/schema/dataroom.prismaindex 8f66829d..32edf25f 100644--- a/prisma/schema/dataroom.prisma+++ b/prisma/schema/dataroom.prisma@@ -23,6 +23,9 @@ model Dataroom {// tagstags TagItem[]+ // notification settings+ notifyOnNewDocument Boolean @default(true)+createdAt DateTime @default(now())updatedAt DateTime @updatedAt