Skip to content

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

feat: add instructions and toggle for convos

Marc Seitz4b84b3c7dfdd
diff --git a/ee/features/conversations/api/toggle-conversations-route.ts b/ee/features/conversations/api/toggle-conversations-route.ts
new file mode 100644
index 00000000..852a20f6
--- /dev/null
+++ b/ee/features/conversations/api/toggle-conversations-route.ts
@@ -0,0 +1,75 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { getServerSession } from "next-auth";
+import { z } from "zod";
+
+import prisma from "@/lib/prisma";
+import { CustomUser } from "@/lib/types";
+
+// Validation schema for the request body
+const toggleConversationsSchema = z.object({
+ enabled: z.boolean(),
+});
+
+export default async function toggleConversationsRoute(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ // Only allow POST method
+ if (req.method !== "POST") {
+ return res.status(405).json({ error: "Method not allowed" });
+ }
+
+ // Validate the session
+ const session = await getServerSession(req, res, authOptions);
+ if (!session?.user) {
+ return res.status(401).json({ error: "Unauthorized" });
+ }
+
+ const userId = (session.user as CustomUser).id;
+
+ try {
+ // Extract query parameters
+ const { teamId, id: dataroomId } = req.query as {
+ teamId: string;
+ id: string;
+ };
+
+ // Validate request body
+ const validationResult = toggleConversationsSchema.safeParse(req.body);
+ if (!validationResult.success) {
+ return res.status(400).json({
+ error: "Invalid request data",
+ details: validationResult.error.format(),
+ });
+ }
+
+ const { enabled } = validationResult.data;
+
+ // Check if user has access to this dataroom
+ const updatedDataroom = await prisma.dataroom.update({
+ where: {
+ id: dataroomId,
+ team: {
+ id: teamId,
+ users: {
+ some: { userId },
+ },
+ },
+ },
+ data: {
+ conversationsEnabled: enabled,
+ },
+ });
+
+ if (!updatedDataroom) {
+ return res.status(404).json({ error: "Dataroom not found" });
+ }
+
+ return res.status(200).json({ success: true, dataroom: updatedDataroom });
+ } catch (error) {
+ console.error("Error toggling conversations:", error);
+ return res.status(500).json({ error: "Internal server error" });
+ }
+}
diff --git a/ee/features/conversations/components/conversations-not-enabled-banner.tsx b/ee/features/conversations/components/conversations-not-enabled-banner.tsx
new file mode 100644
index 00000000..a5860d8e
--- /dev/null
+++ b/ee/features/conversations/components/conversations-not-enabled-banner.tsx
@@ -0,0 +1,268 @@
+import Link from "next/link";
+
+import { useEffect, useState } from "react";
+
+import { ChevronDown, ChevronUp, X } from "lucide-react";
+import { toast } from "sonner";
+
+import { Button } from "@/components/ui/button";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
+import { Switch } from "@/components/ui/switch";
+
+interface ConversationsNotEnabledBannerProps {
+ dataroomId: string;
+ teamId: string;
+ isConversationsEnabled: boolean;
+ onConversationsToggled?: (enabled: boolean) => void;
+}
+
+export function ConversationsNotEnabledBanner({
+ dataroomId,
+ teamId,
+ isConversationsEnabled,
+ onConversationsToggled,
+}: ConversationsNotEnabledBannerProps) {
+ const [isProcessing, setIsProcessing] = useState(false);
+ const [isLocallyEnabled, setIsLocallyEnabled] = useState(
+ isConversationsEnabled,
+ );
+ const [isCollapsed, setIsCollapsed] = useState(false);
+ const [isDismissed, setIsDismissed] = useState(false);
+
+ // Check if banner should be collapsed or dismissed on initial load
+ useEffect(() => {
+ // Check for dismissed state first
+ const isDismissedLocal =
+ localStorage.getItem(
+ `dataroom-${dataroomId}-conversations-banner-dismissed`,
+ ) === "true";
+ if (isDismissedLocal) {
+ setIsDismissed(true);
+ return;
+ }
+
+ // Check for collapsed state
+ const shouldCollapse =
+ localStorage.getItem(
+ `dataroom-${dataroomId}-conversations-banner-collapsed`,
+ ) === "true";
+ if (shouldCollapse) {
+ setIsCollapsed(true);
+ }
+ }, [dataroomId]);
+
+ // Update local state when prop changes
+ useEffect(() => {
+ setIsLocallyEnabled(isConversationsEnabled);
+ }, [isConversationsEnabled]);
+
+ // Save collapsed state to localStorage
+ useEffect(() => {
+ localStorage.setItem(
+ `dataroom-${dataroomId}-conversations-banner-collapsed`,
+ isCollapsed.toString(),
+ );
+ }, [isCollapsed, dataroomId]);
+
+ const handleToggleConversations = async (newValue: boolean) => {
+ setIsProcessing(true);
+ try {
+ const response = await fetch(
+ `/api/teams/${teamId}/datarooms/${dataroomId}/conversations/toggle-conversations`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ enabled: newValue }),
+ },
+ );
+
+ if (!response.ok)
+ throw new Error(
+ `Failed to ${newValue ? "enable" : "disable"} conversations`,
+ );
+
+ setIsLocallyEnabled(newValue);
+ toast.success(
+ `Conversations ${newValue ? "enabled" : "disabled"} successfully`,
+ );
+
+ // Notify parent component if provided
+ if (onConversationsToggled) {
+ onConversationsToggled(newValue);
+ }
+ } catch (error) {
+ console.error(
+ `Error ${newValue ? "enabling" : "disabling"} conversations:`,
+ error,
+ );
+ toast.error(`Failed to ${newValue ? "enable" : "disable"} conversations`);
+ } finally {
+ setIsProcessing(false);
+ }
+ };
+
+ const handleDismiss = () => {
+ setIsDismissed(true);
+ localStorage.setItem(
+ `dataroom-${dataroomId}-conversations-banner-dismissed`,
+ "true",
+ );
+ };
+
+ if (isDismissed) {
+ return null;
+ }
+
+ // Show collapsed version
+ if (isCollapsed) {
+ return (
+ <Card className="mb-6 border-gray-200 bg-gray-50 dark:border-gray-700 dark:bg-gray-800">
+ <CardHeader className="py-4">
+ <div className="flex items-center justify-between">
+ <CardTitle className="text-sm font-medium">
+ {isLocallyEnabled
+ ? "Conversations are enabled - click to view setup steps"
+ : "Conversations are not enabled for this dataroom - click to expand"}
+ </CardTitle>
+ <div className="flex items-center gap-2">
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-8 w-8 p-0"
+ onClick={() => setIsCollapsed(false)}
+ >
+ <ChevronDown className="h-4 w-4" />
+ <span className="sr-only">Expand</span>
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-8 w-8 p-0"
+ onClick={handleDismiss}
+ >
+ <X className="h-4 w-4" />
+ <span className="sr-only">Dismiss</span>
+ </Button>
+ </div>
+ </div>
+ </CardHeader>
+ </Card>
+ );
+ }
+
+ return (
+ <Card className="mb-6 border-gray-200 bg-gray-50 dark:border-gray-700 dark:bg-gray-800">
+ <CardHeader className="py-4">
+ <div className="flex items-center justify-between">
+ <CardTitle className="text-lg font-medium">
+ {isLocallyEnabled
+ ? "Conversations are enabled for this dataroom"
+ : "Conversations are not enabled for this dataroom"}
+ </CardTitle>
+ <div className="flex items-center gap-2">
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-8 w-8 p-0"
+ onClick={() => setIsCollapsed(true)}
+ >
+ <ChevronUp className="h-4 w-4" />
+ <span className="sr-only">Collapse</span>
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-8 w-8 p-0"
+ onClick={handleDismiss}
+ >
+ <X className="h-4 w-4" />
+ <span className="sr-only">Dismiss</span>
+ </Button>
+ </div>
+ </div>
+ <CardDescription>
+ {isLocallyEnabled
+ ? "You've enabled conversations. Here are the next steps:"
+ : "Follow these steps to set up Q&A conversations for your dataroom:"}
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="space-y-4">
+ {/* Step 1: Toggle Dataroom Conversations */}
+ <div className="rounded-lg border bg-background p-4">
+ <div className="mb-3 flex items-center">
+ <div className="flex h-6 w-6 items-center justify-center rounded-full bg-primary text-xs font-medium text-primary-foreground">
+ 1
+ </div>
+ <h4 className="ml-2 font-medium">
+ {isLocallyEnabled
+ ? "Q&A Conversations are enabled for this dataroom"
+ : "Enable Q&A Conversations for this dataroom"}
+ </h4>
+ </div>
+ <div className="flex items-center justify-between">
+ <p className="text-sm text-muted-foreground">
+ {isLocallyEnabled
+ ? "Toggle to disable conversations for all viewers"
+ : "Allow conversations for all viewers with access to this dataroom"}
+ </p>
+ <Switch
+ checked={isLocallyEnabled}
+ onCheckedChange={handleToggleConversations}
+ disabled={isProcessing}
+ />
+ </div>
+ </div>
+
+ {/* Step 2: Enable for a specific link */}
+ <div className="rounded-lg border bg-background p-4">
+ <div className="mb-3 flex items-center">
+ <div className="flex h-6 w-6 items-center justify-center rounded-full bg-primary text-xs font-medium text-primary-foreground">
+ 2
+ </div>
+ <h4 className="ml-2 font-medium">Enable for a specific link</h4>
+ </div>
+ <div className="flex items-center justify-between">
+ <p className="text-sm text-muted-foreground">
+ Enable Q&A conversations for specific links in your dataroom.
+ Note: Email authentication is required for conversations.
+ </p>
+ <Button variant="outline" size="sm">
+ <Link href={`/datarooms/${dataroomId}/permissions`}>
+ Go to permissions
+ </Link>
+ </Button>
+ </div>
+ </div>
+
+ {/* Step 3: Share the link */}
+ <div className="rounded-lg border bg-background p-4">
+ <div className="mb-3 flex items-center">
+ <div className="flex h-6 w-6 items-center justify-center rounded-full bg-primary text-xs font-medium text-primary-foreground">
+ 3
+ </div>
+ <h4 className="ml-2 font-medium">Share with viewers</h4>
+ </div>
+ <p className="text-sm text-muted-foreground">
+ Share your dataroom link with viewers so they can start
+ conversations about your documents.
+ </p>
+ </div>
+ </CardContent>
+ <CardFooter className="rounded-b-lg border-t bg-gray-200 px-6 py-4 dark:bg-gray-700">
+ <p className="text-sm text-muted-foreground">
+ Enabling conversations allows viewers to ask questions about specific
+ documents or the dataroom in general.
+ </p>
+ </CardFooter>
+ </Card>
+ );
+}
diff --git a/ee/features/conversations/pages/conversation-overview.tsx b/ee/features/conversations/pages/conversation-overview.tsx
index c0112e93..842ef5af 100644
--- a/ee/features/conversations/pages/conversation-overview.tsx
+++ b/ee/features/conversations/pages/conversation-overview.tsx
@@ -1,8 +1,9 @@
import { useRouter } from "next/router";
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { ConversationListItem } from "@/ee/features/conversations/components/conversation-list-item";
+import { ConversationsNotEnabledBanner } from "@/ee/features/conversations/components/conversations-not-enabled-banner";
import { Loader2, MessageSquare, Search } from "lucide-react";
import { toast } from "sonner";
import useSWR from "swr";
@@ -58,6 +59,24 @@ export default function DataroomConversationsPage() {
const [conversationToDelete, setConversationToDelete] = useState<
string | null
>(null);
+ const [localConversationsEnabled, setLocalConversationsEnabled] = useState<
+ boolean | undefined
+ >(undefined);
+ const [isBannerDismissed, setIsBannerDismissed] = useState(false);
+
+ // Initialize local state from dataroom and check banner dismissed state
+ useEffect(() => {
+ if (dataroom) {
+ setLocalConversationsEnabled(dataroom.conversationsEnabled);
+
+ // Check if banner has been dismissed
+ const isDismissed =
+ localStorage.getItem(
+ `dataroom-${dataroom.id}-conversations-banner-dismissed`,
+ ) === "true";
+ setIsBannerDismissed(isDismissed);
+ }
+ }, [dataroom]);
// SWR hook for fetching conversation summaries
const { data: conversations = [], isLoading: isLoadingConversations } =
@@ -68,7 +87,7 @@ export default function DataroomConversationsPage() {
fetcher,
{
revalidateOnFocus: true,
- dedupingInterval: 5000, // 5 seconds
+ dedupingInterval: 10000,
keepPreviousData: true,
onError: (err) => {
console.error("Error fetching conversations:", err);
@@ -125,6 +144,11 @@ export default function DataroomConversationsPage() {
router.push(`/datarooms/${dataroom?.id}/conversations/${conversationId}`);
};
+ // Handle conversations being toggled
+ const handleConversationsToggled = (enabled: boolean) => {
+ setLocalConversationsEnabled(enabled);
+ };
+
if (!dataroom) {
return <div>Loading...</div>;
}
@@ -134,6 +158,11 @@ export default function DataroomConversationsPage() {
router.push(`/datarooms/${dataroom?.id}/documents`);
}
+ const isConversationsEnabled =
+ localConversationsEnabled !== undefined
+ ? localConversationsEnabled
+ : dataroom.conversationsEnabled;
+
return (
<AppLayout>
<div className="relative mx-2 my-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">
@@ -142,6 +171,16 @@ export default function DataroomConversationsPage() {
<DataroomNavigation dataroomId={dataroom.id} />
</header>
+ {/* Show banner unless it's been dismissed */}
+ {!isBannerDismissed && (
+ <ConversationsNotEnabledBanner
+ dataroomId={dataroom.id}
+ teamId={teamId as string}
+ isConversationsEnabled={isConversationsEnabled}
+ onConversationsToggled={handleConversationsToggled}
+ />
+ )}
+
<div className="h-[calc(100vh-16rem)] overflow-hidden rounded-md border">
<div className="flex h-full flex-col md:flex-row">
{/* Sidebar with conversations list */}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/conversations/toggle-conversations.ts b/pages/api/teams/[teamId]/datarooms/[id]/conversations/toggle-conversations.ts
new file mode 100644
index 00000000..3fdaeffb
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/conversations/toggle-conversations.ts
@@ -0,0 +1,10 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import toggleConversationsRoute from "@/ee/features/conversations/api/toggle-conversations-route";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ return toggleConversationsRoute(req, res);
+}