Skip to content

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

feat(ee): add dashboard faq conversations

Marc Seitz57aa2ed2f34c
diff --git a/ee/features/conversations/api/team-faqs-route.ts b/ee/features/conversations/api/team-faqs-route.ts
new file mode 100644
index 00000000..66dbe722
--- /dev/null
+++ b/ee/features/conversations/api/team-faqs-route.ts
@@ -0,0 +1,413 @@
+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 { validateContent } from "@/lib/utils/sanitize-html";
+
+export interface PublishFAQInput {
+ title?: string;
+ editedQuestion: string;
+ originalQuestion?: string;
+ answer: string;
+ description?: string;
+ linkId?: string;
+ dataroomDocumentId?: string;
+ sourceConversationId?: string;
+ questionMessageId?: string;
+ answerMessageId?: string;
+ visibilityMode: "PUBLIC_DATAROOM" | "PUBLIC_LINK" | "PUBLIC_DOCUMENT";
+ status?: "DRAFT" | "PUBLISHED" | "ARCHIVED";
+ isAnonymized?: boolean;
+ tags?: string[];
+ documentPageNumber?: number;
+ documentVersionNumber?: number;
+}
+
+// Route mapping object to handle different paths
+const routeHandlers = {
+ // POST /api/teams/[teamId]/datarooms/[dataroomId]/faq
+ "POST /": async (req: NextApiRequest, res: NextApiResponse) => {
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).json({ error: "Unauthorized" });
+ }
+
+ const { teamId, id: dataroomId } = req.query as {
+ teamId: string;
+ id: string;
+ };
+
+ const userId = (session.user as CustomUser).id;
+ const data = req.body as PublishFAQInput;
+
+ try {
+ // Verify team access to dataroom
+ const dataroom = await prisma.dataroom.findUnique({
+ where: {
+ id: dataroomId,
+ team: {
+ id: teamId,
+ users: { some: { userId } },
+ },
+ },
+ select: {
+ id: true,
+ teamId: true,
+ },
+ });
+
+ if (!dataroom) {
+ return res.status(404).json({ error: "Dataroom not found" });
+ }
+
+ // Validate required fields
+ if (!data.editedQuestion || !data.answer) {
+ return res.status(400).json({
+ error: "Question and answer are required",
+ });
+ }
+
+ // Validate visibility mode and related fields
+ if (data.visibilityMode === "PUBLIC_LINK" && !data.linkId) {
+ return res.status(400).json({
+ error: "Link ID is required for link visibility",
+ });
+ }
+
+ if (
+ data.visibilityMode === "PUBLIC_DOCUMENT" &&
+ !data.dataroomDocumentId
+ ) {
+ return res.status(400).json({
+ error: "Document ID is required for document visibility",
+ });
+ }
+
+ // Verify link belongs to dataroom if specified
+ if (data.linkId) {
+ const link = await prisma.link.findFirst({
+ where: {
+ id: data.linkId,
+ dataroomId: dataroomId,
+ },
+ });
+
+ if (!link) {
+ return res.status(400).json({
+ error: "Invalid link for this dataroom",
+ });
+ }
+ }
+
+ // Verify document belongs to dataroom if specified
+ if (data.dataroomDocumentId) {
+ const dataroomDocument = await prisma.dataroomDocument.findFirst({
+ where: {
+ id: data.dataroomDocumentId,
+ dataroomId: dataroomId,
+ },
+ });
+
+ if (!dataroomDocument) {
+ return res.status(400).json({
+ error: "Invalid document for this dataroom",
+ });
+ }
+ }
+
+ // Sanitize content
+ const sanitizedQuestion = validateContent(data.editedQuestion);
+ const sanitizedAnswer = validateContent(data.answer);
+
+ // Create the published FAQ
+ const publishedFAQ = await prisma.dataroomFaqItem.create({
+ data: {
+ title: data.title,
+ editedQuestion: sanitizedQuestion,
+ originalQuestion: data.originalQuestion
+ ? validateContent(data.originalQuestion)
+ : null,
+ answer: sanitizedAnswer,
+ description: data.description
+ ? validateContent(data.description)
+ : null,
+ dataroomId,
+ linkId: data.linkId,
+ dataroomDocumentId: data.dataroomDocumentId,
+ sourceConversationId: data.sourceConversationId,
+ questionMessageId: data.questionMessageId,
+ answerMessageId: data.answerMessageId,
+ teamId,
+ publishedByUserId: userId,
+ visibilityMode: data.visibilityMode,
+ isAnonymized: data.isAnonymized ?? true,
+ tags: data.tags || [],
+ documentPageNumber: data.documentPageNumber,
+ documentVersionNumber: data.documentVersionNumber,
+ },
+ include: {
+ dataroom: {
+ select: { name: true },
+ },
+ link: {
+ select: { name: true },
+ },
+ dataroomDocument: {
+ include: {
+ document: {
+ select: { name: true },
+ },
+ },
+ },
+ publishedByUser: {
+ select: { name: true, email: true },
+ },
+ },
+ });
+
+ return res.status(201).json(publishedFAQ);
+ } catch (error) {
+ console.error("Error publishing FAQ:", error);
+ return res.status(500).json({ error: "Internal server error" });
+ }
+ },
+
+ // GET /api/teams/[teamId]/datarooms/[id]/faq
+ "GET /": async (req: NextApiRequest, res: NextApiResponse) => {
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).json({ error: "Unauthorized" });
+ }
+
+ const { teamId, id: dataroomId } = req.query as {
+ teamId: string;
+ id: string;
+ };
+
+ const userId = (session.user as CustomUser).id;
+
+ try {
+ // Verify team access to dataroom
+ const dataroom = await prisma.dataroom.findUnique({
+ where: {
+ id: dataroomId,
+ team: {
+ id: teamId,
+ users: { some: { userId } },
+ },
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ if (!dataroom) {
+ return res.status(404).json({ error: "Dataroom not found" });
+ }
+
+ // Get published FAQs for this dataroom
+ const faqs = await prisma.dataroomFaqItem.findMany({
+ where: {
+ dataroomId,
+ },
+ include: {
+ dataroom: {
+ select: { name: true },
+ },
+ link: {
+ select: { name: true },
+ },
+ dataroomDocument: {
+ include: {
+ document: {
+ select: { name: true },
+ },
+ },
+ },
+ publishedByUser: {
+ select: { name: true, email: true },
+ },
+ sourceConversation: {
+ select: { id: true },
+ },
+ questionMessage: {
+ select: { id: true, content: true },
+ },
+ answerMessage: {
+ select: { id: true, content: true },
+ },
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ });
+
+ return res.status(200).json(faqs);
+ } catch (error) {
+ console.error("Error fetching FAQs:", error);
+ return res.status(500).json({ error: "Internal server error" });
+ }
+ },
+
+ // PUT /api/teams/[teamId]/datarooms/[id]/faq/[faqId]
+ "PUT /[faqId]": async (req: NextApiRequest, res: NextApiResponse) => {
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).json({ error: "Unauthorized" });
+ }
+
+ const {
+ teamId,
+ id: dataroomId,
+ faqId,
+ } = req.query as {
+ teamId: string;
+ id: string;
+ faqId: string;
+ };
+
+ const userId = (session.user as CustomUser).id;
+ const data = req.body as Partial<PublishFAQInput>;
+
+ try {
+ // Verify team access and FAQ ownership
+ const existingFAQ = await prisma.dataroomFaqItem.findFirst({
+ where: {
+ id: faqId,
+ dataroomId,
+ dataroom: {
+ team: {
+ id: teamId,
+ users: { some: { userId } },
+ },
+ },
+ },
+ });
+
+ if (!existingFAQ) {
+ return res.status(404).json({ error: "FAQ not found" });
+ }
+
+ // Prepare update data
+ const updateData: any = {};
+
+ if (data.title !== undefined) updateData.title = data.title;
+ if (data.editedQuestion)
+ updateData.editedQuestion = validateContent(data.editedQuestion);
+ if (data.answer) updateData.answer = validateContent(data.answer);
+ if (data.description !== undefined)
+ updateData.description = data.description
+ ? validateContent(data.description)
+ : null;
+ if (data.status !== undefined) updateData.status = data.status;
+ if (data.visibilityMode !== undefined)
+ updateData.visibilityMode = data.visibilityMode;
+ if (data.tags !== undefined) updateData.tags = data.tags;
+
+ // Update the FAQ
+ const updatedFAQ = await prisma.dataroomFaqItem.update({
+ where: { id: faqId },
+ data: updateData,
+ include: {
+ dataroom: {
+ select: { name: true },
+ },
+ link: {
+ select: { name: true },
+ },
+ dataroomDocument: {
+ include: {
+ document: {
+ select: { name: true },
+ },
+ },
+ },
+ publishedByUser: {
+ select: { name: true, email: true },
+ },
+ },
+ });
+
+ return res.status(200).json(updatedFAQ);
+ } catch (error) {
+ console.error("Error updating FAQ:", error);
+ return res.status(500).json({ error: "Internal server error" });
+ }
+ },
+
+ // DELETE /api/teams/[teamId]/datarooms/[id]/faq/[faqId]
+ "DELETE /[faqId]": async (req: NextApiRequest, res: NextApiResponse) => {
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).json({ error: "Unauthorized" });
+ }
+
+ const {
+ teamId,
+ id: dataroomId,
+ faqId,
+ } = req.query as {
+ teamId: string;
+ id: string;
+ faqId: string;
+ };
+
+ const userId = (session.user as CustomUser).id;
+
+ try {
+ // Verify team access and FAQ ownership
+ const existingFAQ = await prisma.dataroomFaqItem.findFirst({
+ where: {
+ id: faqId,
+ dataroomId,
+ dataroom: {
+ team: {
+ id: teamId,
+ users: { some: { userId } },
+ },
+ },
+ },
+ });
+
+ if (!existingFAQ) {
+ return res.status(404).json({ error: "FAQ not found" });
+ }
+
+ // Delete the FAQ (cascade will handle votes)
+ await prisma.dataroomFaqItem.delete({
+ where: { id: faqId },
+ });
+
+ return res.status(200).json({ message: "FAQ deleted successfully" });
+ } catch (error) {
+ console.error("Error deleting FAQ:", error);
+ return res.status(500).json({ error: "Internal server error" });
+ }
+ },
+};
+
+// Main handler function that routes to appropriate handler based on method and path
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ const method = req.method;
+ let path = "/";
+
+ // Extract path from query parameters for nested routes
+ if (req.query.faqId) {
+ path = `/[faqId]`;
+ }
+
+ const handlerKey = `${method} ${path}`;
+ const handler = routeHandlers[handlerKey as keyof typeof routeHandlers];
+
+ if (handler) {
+ await handler(req, res);
+ } else {
+ return res.status(405).json({ error: "Method not allowed" });
+ }
+}
diff --git a/ee/features/conversations/components/dashboard/edit-faq-modal.tsx b/ee/features/conversations/components/dashboard/edit-faq-modal.tsx
new file mode 100644
index 00000000..54b6d48d
--- /dev/null
+++ b/ee/features/conversations/components/dashboard/edit-faq-modal.tsx
@@ -0,0 +1,283 @@
+import React, { useEffect, useState } from "react";
+
+import { BookOpen, Check, FileText, Link2 } from "lucide-react";
+import { toast } from "sonner";
+
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import { Label } from "@/components/ui/label";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { Textarea } from "@/components/ui/textarea";
+
+import { PublishedFAQ } from "../../pages/faq-overview";
+
+interface EditFAQModalProps {
+ faq: PublishedFAQ;
+ dataroomId: string;
+ teamId: string;
+ isOpen: boolean;
+ onClose: () => void;
+ onSuccess: () => void;
+}
+
+interface EditFAQFormData {
+ editedQuestion: string;
+ answer: string;
+ visibilityMode: "PUBLIC_DATAROOM" | "PUBLIC_LINK" | "PUBLIC_DOCUMENT";
+}
+
+const visibilityOptions = [
+ {
+ value: "PUBLIC_DATAROOM" as const,
+ label: "Entire Dataroom",
+ description: "Visible to all dataroom visitors",
+ icon: BookOpen,
+ },
+ {
+ value: "PUBLIC_LINK" as const,
+ label: "Specific Link",
+ description: "Visible only to visitors from this link",
+ icon: Link2,
+ },
+ {
+ value: "PUBLIC_DOCUMENT" as const,
+ label: "Specific Document",
+ description: "Visible only when viewing this document",
+ icon: FileText,
+ },
+];
+
+export function EditFAQModal({
+ faq,
+ dataroomId,
+ teamId,
+ isOpen,
+ onClose,
+ onSuccess,
+}: EditFAQModalProps) {
+ const [isUpdating, setIsUpdating] = useState(false);
+ const [formData, setFormData] = useState<EditFAQFormData>({
+ editedQuestion: faq.editedQuestion,
+ answer: faq.answer,
+ visibilityMode: faq.visibilityMode,
+ });
+
+ // Update form data when FAQ changes
+ useEffect(() => {
+ if (faq) {
+ setFormData({
+ editedQuestion: faq.editedQuestion,
+ answer: faq.answer,
+ visibilityMode: faq.visibilityMode,
+ });
+ }
+ }, [faq]);
+
+ const handleInputChange = (field: keyof EditFAQFormData, value: string) => {
+ setFormData((prev) => ({
+ ...prev,
+ [field]: value,
+ }));
+ };
+
+ const handleUpdate = async (e: React.FormEvent) => {
+ e.preventDefault();
+
+ // Basic validation
+ if (
+ !formData.editedQuestion.trim() ||
+ formData.editedQuestion.length < 10
+ ) {
+ toast.error("Question must be at least 10 characters");
+ return;
+ }
+
+ if (!formData.answer.trim() || formData.answer.length < 10) {
+ toast.error("Answer must be at least 10 characters");
+ return;
+ }
+
+ setIsUpdating(true);
+ try {
+ const payload = {
+ ...formData,
+ };
+
+ const response = await fetch(
+ `/api/teams/${teamId}/datarooms/${dataroomId}/faq/${faq.id}`,
+ {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(payload),
+ },
+ );
+
+ if (!response.ok) {
+ const error = await response.json();
+ throw new Error(error.error || "Failed to update FAQ");
+ }
+
+ toast.success("FAQ updated successfully!");
+ onSuccess();
+ onClose();
+ } catch (error) {
+ console.error("Error updating FAQ:", error);
+ toast.error(
+ error instanceof Error ? error.message : "Failed to update FAQ",
+ );
+ } finally {
+ setIsUpdating(false);
+ }
+ };
+
+ return (
+ <Dialog open={isOpen} onOpenChange={onClose}>
+ <DialogContent className="max-h-[90vh] overflow-hidden sm:max-w-5xl md:w-full">
+ <DialogHeader>
+ <DialogTitle>Edit FAQ</DialogTitle>
+ <DialogDescription>
+ Update the question and answer content. You can see the original
+ messages below.
+ </DialogDescription>
+ </DialogHeader>
+
+ <form onSubmit={handleUpdate} className="space-y-6">
+ <div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
+ {/* Original Messages Preview */}
+ <div className="space-y-4">
+ <div>
+ <label className="text-sm font-medium text-gray-700">
+ Original Question
+ </label>
+ <div className="mt-2 rounded-lg border border-blue-200 bg-blue-50/50 p-3">
+ <div className="flex items-start justify-between">
+ <p className="flex-1 text-sm">
+ {faq.questionMessage?.content ||
+ faq.originalQuestion ||
+ "No original question available"}
+ </p>
+ <Check className="ml-2 h-4 w-4 text-blue-600" />
+ </div>
+ <p className="mt-1 text-xs text-gray-500">
+ Original visitor message
+ </p>
+ </div>
+ </div>
+
+ <div>
+ <label className="text-sm font-medium text-gray-700">
+ Original Answer
+ </label>
+ <div className="mt-2 rounded-lg border border-green-200 bg-green-50/50 p-3">
+ <div className="flex items-start justify-between">
+ <p className="flex-1 text-sm">
+ {faq.answerMessage?.content ||
+ "No original answer available"}
+ </p>
+ <Check className="ml-2 h-4 w-4 text-green-600" />
+ </div>
+ <p className="mt-1 text-xs text-gray-500">
+ Original admin response
+ </p>
+ </div>
+ </div>
+ </div>
+
+ {/* FAQ Details */}
+ <div className="space-y-4">
+ <div className="space-y-2">
+ <Label htmlFor="editedQuestion">Question *</Label>
+ <Textarea
+ id="editedQuestion"
+ placeholder="Edit the question for clarity..."
+ className="min-h-[80px]"
+ value={formData.editedQuestion}
+ onChange={(e) =>
+ handleInputChange("editedQuestion", e.target.value)
+ }
+ />
+ <p className="text-sm text-gray-500">
+ You can edit the question to make it clearer for visitors.
+ </p>
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="answer">Answer *</Label>
+ <Textarea
+ id="answer"
+ placeholder="Edit the answer if needed..."
+ className="min-h-[80px]"
+ value={formData.answer}
+ onChange={(e) => handleInputChange("answer", e.target.value)}
+ />
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="visibilityMode">Visibility</Label>
+ <Select
+ value={formData.visibilityMode}
+ onValueChange={(value) =>
+ handleInputChange(
+ "visibilityMode",
+ value as EditFAQFormData["visibilityMode"],
+ )
+ }
+ >
+ <SelectTrigger className="h-12">
+ <SelectValue placeholder="Select visibility scope" />
+ </SelectTrigger>
+ <SelectContent>
+ {visibilityOptions.map((option) => (
+ <SelectItem
+ key={option.value}
+ value={option.value}
+ disabled={
+ option.value === "PUBLIC_DOCUMENT" &&
+ !faq.dataroomDocument
+ }
+ >
+ <div className="flex items-center space-x-4">
+ <option.icon className="h-4 w-4" />
+ <div className="flex flex-col items-start">
+ <div className="font-medium">{option.label}</div>
+ <div className="text-xs text-gray-500">
+ {option.description}
+ </div>
+ </div>
+ </div>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+ </div>
+ </div>
+
+ <DialogFooter>
+ <Button type="button" variant="outline" onClick={onClose}>
+ Cancel
+ </Button>
+ <Button type="submit" variant="default" disabled={isUpdating}>
+ {isUpdating ? "Updating..." : "Update FAQ"}
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/ee/features/conversations/components/dashboard/publish-faq-modal.tsx b/ee/features/conversations/components/dashboard/publish-faq-modal.tsx
new file mode 100644
index 00000000..80b7f063
--- /dev/null
+++ b/ee/features/conversations/components/dashboard/publish-faq-modal.tsx
@@ -0,0 +1,350 @@
+import React, { useState } from "react";
+
+import { BookOpen, Check, FileText, Link2 } from "lucide-react";
+import { toast } from "sonner";
+
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import { Label } from "@/components/ui/label";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { Textarea } from "@/components/ui/textarea";
+
+interface Message {
+ id: string;
+ content: string;
+ createdAt: string;
+ userId: string | null;
+ viewerId: string | null;
+}
+
+interface Conversation {
+ id: string;
+ title: string | null;
+ messages: Message[];
+ dataroomDocument?: {
+ id?: string;
+ document: {
+ name: string;
+ };
+ };
+ linkId?: string;
+ link?: {
+ id: string;
+ name: string;
+ };
+}
+
+interface PublishFAQModalProps {
+ conversation: Conversation;
+ dataroomId: string;
+ teamId: string;
+ isOpen: boolean;
+ onClose: () => void;
+ onSuccess: () => void;
+ selectedQuestionMessage?: Message;
+ selectedAnswerMessage?: Message;
+}
+
+interface PublishFAQFormData {
+ editedQuestion: string;
+ answer: string;
+ visibilityMode: "PUBLIC_DATAROOM" | "PUBLIC_LINK" | "PUBLIC_DOCUMENT";
+ questionMessageId: string;
+ answerMessageId: string;
+}
+
+const visibilityOptions = [
+ {
+ value: "PUBLIC_DATAROOM" as const,
+ label: "Entire Dataroom",
+ description: "Visible to all dataroom visitors",
+ icon: BookOpen,
+ },
+ {
+ value: "PUBLIC_LINK" as const,
+ label: "Specific Link",
+ description: "Visible only to visitors from this link",
+ icon: Link2,
+ },
+ {
+ value: "PUBLIC_DOCUMENT" as const,
+ label: "Specific Document",
+ description: "Visible only when viewing this document",
+ icon: FileText,
+ },
+];
+
+export function PublishFAQModal({
+ conversation,
+ dataroomId,
+ teamId,
+ isOpen,
+ onClose,
+ onSuccess,
+ selectedQuestionMessage,
+ selectedAnswerMessage,
+}: PublishFAQModalProps) {
+ const [isPublishing, setIsPublishing] = useState(false);
+ const [formData, setFormData] = useState<PublishFAQFormData>({
+ editedQuestion: selectedQuestionMessage?.content || "",
+ answer: selectedAnswerMessage?.content || "",
+ visibilityMode: "PUBLIC_DATAROOM",
+ questionMessageId: selectedQuestionMessage?.id || "",
+ answerMessageId: selectedAnswerMessage?.id || "",
+ });
+
+ // Update form data when selected messages change
+ React.useEffect(() => {
+ if (selectedQuestionMessage && selectedAnswerMessage) {
+ setFormData((prev) => ({
+ ...prev,
+ editedQuestion: selectedQuestionMessage.content,
+ answer: selectedAnswerMessage.content,
+ questionMessageId: selectedQuestionMessage.id,
+ answerMessageId: selectedAnswerMessage.id,
+ }));
+ }
+ }, [selectedQuestionMessage, selectedAnswerMessage]);
+
+ const handleInputChange = (
+ field: keyof PublishFAQFormData,
+ value: string,
+ ) => {
+ setFormData((prev) => ({
+ ...prev,
+ [field]: value,
+ }));
+ };
+
+ const handlePublish = async (e: React.FormEvent) => {
+ e.preventDefault();
+
+ // Basic validation
+ if (!selectedQuestionMessage || !selectedAnswerMessage) {
+ toast.error("Please select both a question and an answer");
+ return;
+ }
+
+ if (
+ !formData.editedQuestion.trim() ||
+ formData.editedQuestion.length < 10
+ ) {
+ toast.error("Question must be at least 10 characters");
+ return;
+ }
+
+ if (!formData.answer.trim() || formData.answer.length < 10) {
+ toast.error("Answer must be at least 10 characters");
+ return;
+ }
+
+ setIsPublishing(true);
+ try {
+ const payload = {
+ ...formData,
+ sourceConversationId: conversation.id,
+ linkId: conversation.linkId,
+ dataroomDocumentId: conversation.dataroomDocument?.id || null,
+ isAnonymized: true, // Always anonymize published FAQs
+ };
+
+ const response = await fetch(
+ `/api/teams/${teamId}/datarooms/${dataroomId}/faq`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(payload),
+ },
+ );
+
+ if (!response.ok) {
+ const error = await response.json();
+ throw new Error(error.error || "Failed to publish FAQ");
+ }
+
+ toast.success("FAQ published successfully!");
+ onSuccess();
+ onClose();
+ // Reset form
+ setFormData({
+ editedQuestion: selectedQuestionMessage?.content || "",
+ answer: selectedAnswerMessage?.content || "",
+ visibilityMode: "PUBLIC_DATAROOM",
+ questionMessageId: selectedQuestionMessage?.id || "",
+ answerMessageId: selectedAnswerMessage?.id || "",
+ });
+ } catch (error) {
+ console.error("Error publishing FAQ:", error);
+ toast.error(
+ error instanceof Error ? error.message : "Failed to publish FAQ",
+ );
+ } finally {
+ setIsPublishing(false);
+ }
+ };
+
+ return (
+ <Dialog open={isOpen} onOpenChange={onClose}>
+ <DialogContent className="max-h-[90vh] overflow-hidden sm:max-w-5xl md:w-full">
+ <DialogHeader>
+ <DialogTitle>Publish FAQ from Conversation</DialogTitle>
+ <DialogDescription>
+ Review and edit the selected question and answer before publishing
+ as a FAQ
+ </DialogDescription>
+ </DialogHeader>
+
+ <form onSubmit={handlePublish} className="space-y-6">
+ <div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
+ {/* Selected Messages Preview */}
+ <div className="space-y-4">
+ <div>
+ <label className="text-sm font-medium text-gray-700">
+ Selected Question
+ </label>
+ <div className="mt-2 rounded-lg border border-blue-200 bg-blue-50/50 p-3">
+ <div className="flex items-start justify-between">
+ <p className="flex-1 text-sm">
+ {selectedQuestionMessage?.content}
+ </p>
+ <Check className="ml-2 h-4 w-4 text-blue-600" />
+ </div>
+ <p className="mt-1 text-xs text-gray-500">
+ Visitor •{" "}
+ {selectedQuestionMessage &&
+ new Date(
+ selectedQuestionMessage.createdAt,
+ ).toLocaleString()}
+ </p>
+ </div>
+ </div>
+
+ <div>
+ <label className="text-sm font-medium text-gray-700">
+ Selected Answer
+ </label>
+ <div className="mt-2 rounded-lg border border-green-200 bg-green-50/50 p-3">
+ <div className="flex items-start justify-between">
+ <p className="flex-1 text-sm">
+ {selectedAnswerMessage?.content}
+ </p>
+ <Check className="ml-2 h-4 w-4 text-green-600" />
+ </div>
+ <p className="mt-1 text-xs text-gray-500">
+ Admin •{" "}
+ {selectedAnswerMessage &&
+ new Date(
+ selectedAnswerMessage.createdAt,
+ ).toLocaleString()}
+ </p>
+ </div>
+ </div>
+ </div>
+
+ {/* FAQ Details */}
+ <div className="space-y-4">
+ <div className="space-y-2">
+ <Label htmlFor="editedQuestion">Question *</Label>
+ <Textarea
+ id="editedQuestion"
+ placeholder="Edit the question for clarity..."
+ className="min-h-[80px]"
+ value={formData.editedQuestion}
+ onChange={(e) =>
+ handleInputChange("editedQuestion", e.target.value)
+ }
+ />
+ <p className="text-sm text-gray-500">
+ You can edit the question to make it clearer for other
+ visitors.
+ </p>
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="answer">Answer *</Label>
+ <Textarea
+ id="answer"
+ placeholder="Edit the answer if needed..."
+ className="min-h-[80px]"
+ value={formData.answer}
+ onChange={(e) => handleInputChange("answer", e.target.value)}
+ />
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="visibilityMode">Visibility</Label>
+ <Select
+ value={formData.visibilityMode}
+ onValueChange={(value) =>
+ handleInputChange(
+ "visibilityMode",
+ value as PublishFAQFormData["visibilityMode"],
+ )
+ }
+ >
+ <SelectTrigger className="h-12">
+ <SelectValue placeholder="Select visibility scope" />
+ </SelectTrigger>
+ <SelectContent>
+ {visibilityOptions.map((option) => (
+ <SelectItem
+ key={option.value}
+ value={option.value}
+ disabled={
+ option.value === "PUBLIC_DOCUMENT" &&
+ !conversation.dataroomDocument
+ }
+ >
+ <div className="flex items-center space-x-4">
+ <option.icon className="h-4 w-4" />
+ <div className="flex flex-col items-start">
+ <div className="font-medium">{option.label}</div>
+ <div className="text-xs text-gray-500">
+ {option.description}
+ </div>
+ </div>
+ </div>
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+ </div>
+ </div>
+
+ <DialogFooter>
+ <Button type="button" variant="outline" onClick={onClose}>
+ Cancel
+ </Button>
+ <Button
+ type="submit"
+ variant="default"
+ disabled={
+ isPublishing ||
+ !selectedQuestionMessage ||
+ !selectedAnswerMessage
+ }
+ >
+ {isPublishing ? "Publishing..." : "Publish FAQ"}
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/ee/features/conversations/pages/conversation-detail.tsx b/ee/features/conversations/pages/conversation-detail.tsx
index 4bbc144c..227731ac 100644
--- a/ee/features/conversations/pages/conversation-detail.tsx
+++ b/ee/features/conversations/pages/conversation-detail.tsx
@@ -1,11 +1,21 @@
+import Link from "next/link";
import { useRouter } from "next/router";
-import { useState } from "react";
+import React, { useEffect, useState } from "react";
import { ConversationListItem } from "@/ee/features/conversations/components/dashboard/conversation-list-item";
+import { PublishFAQModal } from "@/ee/features/conversations/components/dashboard/publish-faq-modal";
import { ConversationDocumentContext } from "@/ee/features/conversations/components/shared/conversation-document-context";
import { ConversationMessage } from "@/ee/features/conversations/components/shared/conversation-message";
-import { Loader2, SearchIcon, Send, Trash2 } from "lucide-react";
+import {
+ BookOpenCheckIcon,
+ Loader2,
+ MessageSquare,
+ SearchIcon,
+ Send,
+ Trash2,
+ X,
+} from "lucide-react";
import { useSession } from "next-auth/react";
import { toast } from "sonner";
import useSWR, { mutate } from "swr";
@@ -31,7 +41,16 @@ import {
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { ScrollArea } from "@/components/ui/scroll-area";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
+
+import { PublishedFAQ } from "./faq-overview";
// Types for conversation
interface Message {
@@ -88,11 +107,66 @@ export default function ConversationDetailPage() {
const { data: session } = useSession();
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
+ const [isPublishFAQModalOpen, setIsPublishFAQModalOpen] = useState(false);
+ const [selectedQuestionId, setSelectedQuestionId] = useState<string | null>(
+ null,
+ );
+ const [selectedAnswerId, setSelectedAnswerId] = useState<string | null>(null);
const { conversationId, id: dataroomId } = router.query;
const teamId = router.query.teamId || dataroom?.teamId;
const [searchQuery, setSearchQuery] = useState("");
+ // Clear selections when switching conversations
+ useEffect(() => {
+ setSelectedQuestionId(null);
+ setSelectedAnswerId(null);
+ }, [conversationId]);
+
+ // Auto-select latest question and answer
+ const autoSelectLatestQA = () => {
+ if (!conversation) return;
+
+ // Find latest visitor message (question)
+ const visitorMessages = conversation.messages.filter(
+ (msg) => msg.viewerId !== null,
+ );
+ const latestQuestion = visitorMessages[visitorMessages.length - 1];
+
+ // Find latest admin message (answer)
+ const adminMessages = conversation.messages.filter(
+ (msg) => msg.userId !== null,
+ );
+ const latestAnswer = adminMessages[adminMessages.length - 1];
+
+ if (latestQuestion) setSelectedQuestionId(latestQuestion.id);
+ if (latestAnswer) setSelectedAnswerId(latestAnswer.id);
+ };
+
+ // Handle message selection for FAQ publishing
+ const handleMessageSelect = (messageId: string, isVisitor: boolean) => {
+ if (isVisitor) {
+ // Selecting/deselecting a question
+ setSelectedQuestionId((prev) => (prev === messageId ? null : messageId));
+ } else {
+ // Selecting/deselecting an answer
+ setSelectedAnswerId((prev) => (prev === messageId ? null : messageId));
+ }
+ };
+
+ const getSelectedMessages = () => {
+ if (!conversation || !selectedQuestionId || !selectedAnswerId) return null;
+
+ const questionMessage = conversation.messages.find(
+ (m) => m.id === selectedQuestionId,
+ );
+ const answerMessage = conversation.messages.find(
+ (m) => m.id === selectedAnswerId,
+ );
+
+ return { questionMessage, answerMessage };
+ };
+
// SWR hook for fetching the conversation with messages
const { data: conversation, isLoading } = useSWR<Conversation>(
conversationId && dataroomId && teamId
@@ -136,6 +210,19 @@ export default function ConversationDetailPage() {
},
);
+ // Fetch published FAQs
+ const { data: faqs = [] } = useSWR<PublishedFAQ[]>(
+ dataroom && teamId
+ ? `/api/teams/${teamId}/datarooms/${dataroom.id}/faq`
+ : null,
+ fetcher,
+ {
+ revalidateOnFocus: true,
+ dedupingInterval: 10000,
+ keepPreviousData: true,
+ },
+ );
+
// Filter conversations based on search query
const filteredConversations = conversations.filter((conversation) => {
if (!searchQuery) return true;
@@ -153,6 +240,10 @@ export default function ConversationDetailPage() {
);
});
+ const isPublishFAQDisabled =
+ !conversation?.messages.some((msg) => msg.viewerId !== null) ||
+ !conversation?.messages.some((msg) => msg.userId !== null);
+
// Mark messages as read
const markMessagesAsRead = async (conversationId: string) => {
if (!dataroomId || !teamId) return;
@@ -277,145 +368,267 @@ export default function ConversationDetailPage() {
<DataroomNavigation dataroomId={dataroom.id} />
</header>
- <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 */}
- <div className="flex h-full w-full flex-col border-r md:w-96">
- <div className="flex items-center justify-between p-4">
- <h2 className="text-lg font-semibold">Conversations</h2>
- <Badge variant="secondary">{conversations.length}</Badge>
- </div>
-
- <div className="flex items-center px-4 pb-4">
- <div className="relative w-full">
- <SearchIcon className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
- <Input
- placeholder="Search conversations..."
- className="pl-8"
- value={searchQuery}
- onChange={(e) => setSearchQuery(e.target.value)}
- />
- </div>
- </div>
+ <Tabs value="conversations" className="space-y-6">
+ <TabsList>
+ <TabsTrigger
+ value="conversations"
+ className="flex items-center gap-2"
+ >
+ <MessageSquare className="h-4 w-4" />
+ Conversations
+ <Badge variant="notification">{conversations.length}</Badge>
+ </TabsTrigger>
+ <TabsTrigger value="faqs" asChild>
+ <Link
+ href={`/datarooms/${dataroom.id}/conversations/faqs`}
+ className="flex items-center gap-2"
+ >
+ <BookOpenCheckIcon className="h-4 w-4" />
+ Published FAQs
+ <Badge variant="notification">{faqs.length}</Badge>
+ </Link>
+ </TabsTrigger>
+ </TabsList>
+
+ <TabsContent value="conversations" className="space-y-0">
+ <div className="h-[calc(100vh-20rem)] overflow-hidden rounded-md border">
+ <div className="flex h-full flex-col md:flex-row">
+ {/* Sidebar with conversations list */}
+ <div className="flex h-full w-full flex-col border-r md:w-96">
+ {/* <div className="flex items-center justify-between p-4">
+ <h2 className="text-lg font-semibold">Conversations</h2>
+ <Badge variant="secondary">{conversations.length}</Badge>
+ </div> */}
+
+ <div className="flex items-center p-4">
+ <div className="relative w-full">
+ <SearchIcon className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
+ <Input
+ placeholder="Search conversations..."
+ className="pl-8"
+ value={searchQuery}
+ onChange={(e) => setSearchQuery(e.target.value)}
+ />
+ </div>
+ </div>
- <div className="flex h-[calc(100%-7.5rem)] flex-col">
- <div className="m-0 flex-1 overflow-hidden">
- <ScrollArea className="h-full">
- <div className="flex flex-col gap-2 p-4 pt-0">
- {isLoadingConversations ? (
- <div className="flex h-20 items-center justify-center">
- <Loader2 className="h-6 w-6 animate-spin text-primary" />
- </div>
- ) : filteredConversations.length === 0 ? (
- <div className="flex h-20 items-center justify-center">
- <p className="text-sm text-muted-foreground">
- No conversations found
- </p>
+ <div className="flex h-[calc(100%-7.5rem)] flex-col">
+ <div className="m-0 flex-1 overflow-hidden">
+ <ScrollArea className="h-full">
+ <div className="flex flex-col gap-2 p-4 pt-0">
+ {isLoadingConversations ? (
+ <div className="flex h-20 items-center justify-center">
+ <Loader2 className="h-6 w-6 animate-spin text-primary" />
+ </div>
+ ) : filteredConversations.length === 0 ? (
+ <div className="flex h-20 items-center justify-center">
+ <p className="text-sm text-muted-foreground">
+ No conversations found
+ </p>
+ </div>
+ ) : (
+ // Sort by most recent first
+ [...filteredConversations]
+ .sort(
+ (a, b) =>
+ new Date(b.updatedAt).getTime() -
+ new Date(a.updatedAt).getTime(),
+ )
+ .map((conversation) => (
+ <ConversationListItem
+ key={conversation.id}
+ navigateToConversation={
+ navigateToConversation
+ }
+ conversation={conversation}
+ isActive={conversation.id === conversationId}
+ />
+ ))
+ )}
</div>
- ) : (
- // Sort by most recent first
- [...filteredConversations]
- .sort(
- (a, b) =>
- new Date(b.updatedAt).getTime() -
- new Date(a.updatedAt).getTime(),
- )
- .map((conversation) => (
- <ConversationListItem
- key={conversation.id}
- navigateToConversation={navigateToConversation}
- conversation={conversation}
- isActive={conversation.id === conversationId}
- />
- ))
- )}
+ </ScrollArea>
</div>
- </ScrollArea>
+ </div>
</div>
- </div>
- </div>
- {/* Conversation content */}
- <div className="flex h-full flex-1 flex-col">
- {isLoading ? (
- <div className="flex flex-1 items-center justify-center">
- <Loader2 className="h-8 w-8 animate-spin text-primary" />
- </div>
- ) : conversation ? (
- <>
- {/* Conversation header */}
- <div className="flex items-center justify-between border-b p-4">
- <div className="flex items-center gap-2">
- <Avatar className="h-8 w-8">
- <AvatarImage src="" />
- <AvatarFallback>
- {conversation.participants[0].email
- ? conversation.participants[0].email
- .charAt(0)
- .toUpperCase()
- : "?"}
- </AvatarFallback>
- </Avatar>
- <div className="flex-1">
- <h2 className="text-base font-semibold">
- {conversation.title || "Conversation"}
- </h2>
- <p className="text-sm text-muted-foreground">
- {conversation.participants[0].email ||
- "Anonymous Viewer"}
- </p>
- </div>
+ {/* Conversation content */}
+ <div className="flex h-full flex-1 flex-col">
+ {isLoading ? (
+ <div className="flex flex-1 items-center justify-center">
+ <Loader2 className="h-8 w-8 animate-spin text-primary" />
</div>
- <Button
- variant="ghost"
- size="icon"
- title="Delete conversation"
- onClick={() => setIsDeleteDialogOpen(true)}
- >
- <Trash2 className="h-4 w-4" />
- </Button>
- </div>
+ ) : conversation ? (
+ <>
+ {/* Conversation header */}
+ <div className="flex items-center justify-between border-b p-4">
+ <div className="flex items-center gap-2">
+ <Avatar className="h-8 w-8">
+ <AvatarImage src="" />
+ <AvatarFallback>
+ {conversation.participants[0].email
+ ? conversation.participants[0].email
+ .charAt(0)
+ .toUpperCase()
+ : "?"}
+ </AvatarFallback>
+ </Avatar>
+ <div className="flex-1">
+ <h2 className="text-base font-semibold">
+ {conversation.title || "Conversation"}
+ </h2>
+ <p className="text-sm text-muted-foreground">
+ {conversation.participants[0].email ||
+ "Anonymous Viewer"}
+ </p>
+ </div>
+ </div>
+ <div className="flex items-center gap-2">
+ {(selectedQuestionId || selectedAnswerId) && (
+ <Button
+ variant="ghost"
+ size="sm"
+ title="Clear message selections"
+ onClick={() => {
+ setSelectedQuestionId(null);
+ setSelectedAnswerId(null);
+ }}
+ >
+ <X className="mr-1 h-4 w-4" />
+ Clear
+ </Button>
+ )}
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger>
+ <Button
+ size="sm"
+ onClick={() => {
+ if (
+ selectedQuestionId &&
+ selectedAnswerId
+ ) {
+ setIsPublishFAQModalOpen(true);
+ } else {
+ autoSelectLatestQA();
+ }
+ }}
+ disabled={isPublishFAQDisabled}
+ >
+ <BookOpenCheckIcon className="mr-2 h-4 w-4" />
+ {selectedQuestionId && selectedAnswerId
+ ? "Publish FAQ"
+ : "Select messages to publish"}
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>
+ {isPublishFAQDisabled
+ ? "Need both visitor questions and admin answers to publish FAQ"
+ : selectedQuestionId && selectedAnswerId
+ ? "Publish selected question and answer as FAQ"
+ : "Select the latest question and answer for FAQ publishing"}
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ <Button
+ variant="ghost"
+ size="icon"
+ title="Delete conversation"
+ onClick={() => setIsDeleteDialogOpen(true)}
+ >
+ <Trash2 className="h-4 w-4" />
+ </Button>
+ </div>
+ </div>
+
+ {/* Messages */}
+ <ScrollArea className="flex-1">
+ <div className="flex flex-col gap-4 p-4">
+ {/* Document Context */}
+ <ConversationDocumentContext
+ dataroomDocument={conversation.dataroomDocument}
+ documentPageNumber={conversation.documentPageNumber}
+ documentVersionNumber={
+ conversation.documentVersionNumber
+ }
+ showVersionNumber={true} // Admin sees full context
+ className="mb-2"
+ />
+
+ {/* Selection Guidance */}
+ {/* {conversation.messages.length > 1 && (
+ <div className="mb-2 rounded-lg border border-blue-200 bg-blue-50 p-3 text-sm">
+ <div className="flex items-start gap-2">
+ <BookOpenCheck className="mt-0.5 h-4 w-4 flex-shrink-0 text-blue-600" />
+ <div className="text-blue-800">
+ {!selectedQuestionId && !selectedAnswerId ? (
+ <p>
+ <strong>💡 Step 1:</strong> Click "Select
+ messages to publish" to automatically choose
+ the latest question and answer, or manually
+ select different messages by clicking them
+ first.
+ </p>
+ ) : selectedQuestionId && !selectedAnswerId ? (
+ <p>
+ <strong>Question selected!</strong> Now select
+ an admin answer to complete your FAQ pair.
+ </p>
+ ) : !selectedQuestionId && selectedAnswerId ? (
+ <p>
+ <strong>Answer selected!</strong> Now select a
+ visitor question to complete your FAQ pair.
+ </p>
+ ) : (
+ <p>
+ <strong>Step 2:</strong> Perfect! Both
+ question and answer are selected. Click
+ "Publish FAQ" to review and publish.
+ </p>
+ )}
+ </div>
+ </div>
+ </div>
+ )} */}
+ {conversation.messages.map((message) => (
+ <ConversationMessage
+ key={message.id}
+ message={message}
+ isAuthor={
+ message.userId ===
+ (session?.user as CustomUser).id
+ }
+ senderEmail={
+ conversation.participants[0].email || "Viewer"
+ }
+ isSelectable={true}
+ isSelected={
+ message.id === selectedQuestionId ||
+ message.id === selectedAnswerId
+ }
+ onSelect={handleMessageSelect}
+ />
+ ))}
+ </div>
+ </ScrollArea>
- {/* Messages */}
- <ScrollArea className="flex-1">
- <div className="flex flex-col gap-4 p-4">
- {/* Document Context */}
- <ConversationDocumentContext
- dataroomDocument={conversation.dataroomDocument}
- documentPageNumber={conversation.documentPageNumber}
- documentVersionNumber={
- conversation.documentVersionNumber
- }
- showVersionNumber={true} // Admin sees full context
- className="mb-2"
+ <ConversationReplyForm
+ onSendMessage={handleSendMessage}
/>
- {conversation.messages.map((message) => (
- <ConversationMessage
- key={message.id}
- message={message}
- isAuthor={
- message.userId === (session?.user as CustomUser).id
- }
- senderEmail={
- conversation.participants[0].email || "Viewer"
- }
- />
- ))}
+ </>
+ ) : (
+ <div className="flex flex-1 items-center justify-center">
+ <p className="text-muted-foreground">
+ Conversation not found
+ </p>
</div>
- </ScrollArea>
-
- <ConversationReplyForm onSendMessage={handleSendMessage} />
- </>
- ) : (
- <div className="flex flex-1 items-center justify-center">
- <p className="text-muted-foreground">
- Conversation not found
- </p>
+ )}
</div>
- )}
+ </div>
</div>
- </div>
- </div>
+ </TabsContent>
+ </Tabs>
</div>
{/* Delete Confirmation Dialog */}
@@ -453,6 +666,28 @@ export default function ConversationDetailPage() {
</DialogFooter>
</DialogContent>
</Dialog>
+
+ {/* Publish FAQ Modal */}
+ {conversation && (
+ <PublishFAQModal
+ conversation={conversation}
+ dataroomId={dataroomId as string}
+ teamId={teamId as string}
+ isOpen={isPublishFAQModalOpen}
+ onClose={() => {
+ setIsPublishFAQModalOpen(false);
+ // Keep selections when modal closes so user can reselect
+ }}
+ onSuccess={() => {
+ // Reset selections after successful publish
+ setSelectedQuestionId(null);
+ setSelectedAnswerId(null);
+ toast.success("FAQ published successfully!");
+ }}
+ selectedQuestionMessage={getSelectedMessages()?.questionMessage}
+ selectedAnswerMessage={getSelectedMessages()?.answerMessage}
+ />
+ )}
</AppLayout>
);
}
diff --git a/ee/features/conversations/pages/conversation-overview.tsx b/ee/features/conversations/pages/conversation-overview.tsx
index 5233e85d..ba3d9169 100644
--- a/ee/features/conversations/pages/conversation-overview.tsx
+++ b/ee/features/conversations/pages/conversation-overview.tsx
@@ -1,10 +1,18 @@
+import Link from "next/link";
import { useRouter } from "next/router";
-import { useEffect, useState } from "react";
+import { useEffect, useMemo, useState } from "react";
+import { useTeam } from "@/context/team-context";
import { ConversationListItem } from "@/ee/features/conversations/components/dashboard/conversation-list-item";
import { ConversationsNotEnabledBanner } from "@/ee/features/conversations/components/dashboard/conversations-not-enabled-banner";
-import { Loader2, MessageSquare, Search } from "lucide-react";
+import { PublishedFAQ } from "@/ee/features/conversations/components/dashboard/published-faq-table";
+import {
+ BookOpenCheckIcon,
+ Loader2,
+ MessageSquare,
+ Search,
+} from "lucide-react";
import { toast } from "sonner";
import useSWR from "swr";
import z from "zod";
@@ -28,8 +36,9 @@ import {
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { ScrollArea } from "@/components/ui/scroll-area";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
-interface ConversationSummary {
+export interface ConversationSummary {
id: string;
title: string | null;
createdAt: string;
@@ -54,7 +63,7 @@ export default function DataroomConversationsPage() {
const router = useRouter();
const { limits } = useLimits();
const { dataroom } = useDataroom();
- const teamId = router.query.teamId || dataroom?.teamId;
+ const { currentTeamId: teamId } = useTeam();
const [searchQuery, setSearchQuery] = useState("");
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
@@ -64,19 +73,22 @@ export default function DataroomConversationsPage() {
const [localConversationsEnabled, setLocalConversationsEnabled] = useState<
boolean | undefined
>(undefined);
- const [isBannerDismissed, setIsBannerDismissed] = useState(false);
+ const [activeTab, setActiveTab] = useState("conversations");
- // Initialize local state from dataroom and check banner dismissed state
+ // Memoize banner dismissed state to avoid localStorage reads on every render
+ const isBannerDismissed = useMemo(() => {
+ if (!dataroom?.id) return false;
+ return (
+ localStorage.getItem(
+ `dataroom-${dataroom.id}-conversations-banner-dismissed`,
+ ) === "true"
+ );
+ }, [dataroom?.id]);
+
+ // Initialize local state from dataroom
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]);
@@ -98,6 +110,19 @@ export default function DataroomConversationsPage() {
},
);
+ // Fetch published FAQs
+ const { data: faqs = [] } = useSWR<PublishedFAQ[]>(
+ dataroom && teamId
+ ? `/api/teams/${teamId}/datarooms/${dataroom.id}/faq`
+ : null,
+ fetcher,
+ {
+ revalidateOnFocus: true,
+ dedupingInterval: 10000,
+ keepPreviousData: true,
+ },
+ );
+
// Filter conversations based on search query
const filteredConversations = conversations.filter((conversation) => {
if (!searchQuery) return true;
@@ -190,78 +215,108 @@ export default function DataroomConversationsPage() {
/>
)}
- <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 */}
- <div className="flex h-full w-full flex-col border-r md:w-96">
- <div className="flex items-center justify-between p-4">
- <h2 className="text-lg font-semibold">Conversations</h2>
- <Badge variant="secondary">{conversations.length}</Badge>
- </div>
+ <Tabs
+ value={activeTab}
+ onValueChange={setActiveTab}
+ className="space-y-6"
+ >
+ <TabsList>
+ <TabsTrigger
+ value="conversations"
+ className="flex items-center gap-2"
+ >
+ <MessageSquare className="h-4 w-4" />
+ Conversations
+ <Badge variant="notification">{conversations.length}</Badge>
+ </TabsTrigger>
+ <TabsTrigger value="faqs" asChild>
+ <Link
+ href={`/datarooms/${dataroom.id}/conversations/faqs`}
+ className="flex items-center gap-2"
+ >
+ <BookOpenCheckIcon className="h-4 w-4" />
+ Published FAQs
+ <Badge variant="notification">{faqs.length}</Badge>
+ </Link>
+ </TabsTrigger>
+ </TabsList>
- <div className="flex items-center px-4 pb-4">
- <div className="relative w-full">
- <Search className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
- <Input
- placeholder="Search conversations..."
- className="pl-8"
- value={searchQuery}
- onChange={(e) => setSearchQuery(e.target.value)}
- />
- </div>
- </div>
+ <TabsContent value="conversations" className="space-y-0">
+ <div className="h-[calc(100vh-20rem)] overflow-hidden rounded-md border">
+ <div className="flex h-full flex-col md:flex-row">
+ {/* Sidebar with conversations list */}
+ <div className="flex h-full w-full flex-col border-r md:w-96">
+ {/* <div className="flex items-center justify-between p-4">
+ <h2 className="text-lg font-semibold">Conversations</h2>
+ </div> */}
- <div className="flex h-[calc(100%-7.5rem)] flex-col">
- <div className="m-0 flex-1 overflow-hidden">
- <ScrollArea className="h-full">
- <div className="flex flex-col gap-2 p-4 pt-0">
- {isLoadingConversations ? (
- <div className="flex h-20 items-center justify-center">
- <Loader2 className="h-6 w-6 animate-spin text-primary" />
- </div>
- ) : filteredConversations.length === 0 ? (
- <div className="flex h-20 items-center justify-center">
- <p className="text-sm text-muted-foreground">
- No conversations found
- </p>
+ <div className="flex items-center p-4">
+ <div className="relative w-full">
+ <Search className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
+ <Input
+ placeholder="Search conversations..."
+ className="pl-8"
+ value={searchQuery}
+ onChange={(e) => setSearchQuery(e.target.value)}
+ />
+ </div>
+ </div>
+
+ <div className="flex h-[calc(100%-7.5rem)] flex-col">
+ <div className="m-0 flex-1 overflow-hidden">
+ <ScrollArea className="h-full">
+ <div className="flex flex-col gap-2 p-4 pt-0">
+ {isLoadingConversations ? (
+ <div className="flex h-20 items-center justify-center">
+ <Loader2 className="h-6 w-6 animate-spin text-primary" />
+ </div>
+ ) : filteredConversations.length === 0 ? (
+ <div className="flex h-20 items-center justify-center">
+ <p className="text-sm text-muted-foreground">
+ No conversations found
+ </p>
+ </div>
+ ) : (
+ // Sort by most recent first
+ [...filteredConversations]
+ .sort(
+ (a, b) =>
+ new Date(b.updatedAt).getTime() -
+ new Date(a.updatedAt).getTime(),
+ )
+ .map((conversation) => (
+ <ConversationListItem
+ key={conversation.id}
+ navigateToConversation={
+ navigateToConversation
+ }
+ conversation={conversation}
+ isActive={false}
+ />
+ ))
+ )}
</div>
- ) : (
- // Sort by most recent first
- [...filteredConversations]
- .sort(
- (a, b) =>
- new Date(b.updatedAt).getTime() -
- new Date(a.updatedAt).getTime(),
- )
- .map((conversation) => (
- <ConversationListItem
- key={conversation.id}
- navigateToConversation={navigateToConversation}
- conversation={conversation}
- isActive={false}
- />
- ))
- )}
+ </ScrollArea>
</div>
- </ScrollArea>
+ </div>
</div>
- </div>
- </div>
- {/* Empty state for the right panel */}
- <div className="hidden flex-1 items-center justify-center md:flex">
- <div className="text-center">
- <MessageSquare className="mx-auto h-10 w-10 text-muted-foreground" />
- <p className="mt-2 text-sm font-medium">
- Select a conversation
- </p>
- <p className="text-xs text-muted-foreground">
- Choose a conversation to view and reply
- </p>
+ {/* Empty state for the right panel */}
+ <div className="hidden flex-1 items-center justify-center md:flex">
+ <div className="text-center">
+ <MessageSquare className="mx-auto h-10 w-10 text-muted-foreground" />
+ <p className="mt-2 text-sm font-medium">
+ Select a conversation
+ </p>
+ <p className="text-xs text-muted-foreground">
+ Choose a conversation to view and reply
+ </p>
+ </div>
+ </div>
</div>
</div>
- </div>
- </div>
+ </TabsContent>
+ </Tabs>
</div>
{/* Delete Confirmation Dialog */}
diff --git a/ee/features/conversations/pages/faq-overview.tsx b/ee/features/conversations/pages/faq-overview.tsx
new file mode 100644
index 00000000..14a42426
--- /dev/null
+++ b/ee/features/conversations/pages/faq-overview.tsx
@@ -0,0 +1,511 @@
+import Link from "next/link";
+import { useRouter } from "next/router";
+
+import { useState } from "react";
+
+import { useTeam } from "@/context/team-context";
+import { EditFAQModal } from "@/ee/features/conversations/components/dashboard/edit-faq-modal";
+import {
+ BookOpenCheckIcon,
+ ClockIcon,
+ EditIcon,
+ EyeIcon,
+ FileTextIcon,
+ Link2Icon,
+ MessageSquare,
+ MoreVertical,
+ ServerIcon,
+ Trash2Icon,
+} from "lucide-react";
+import { toast } from "sonner";
+import useSWR, { mutate } from "swr";
+
+import { useDataroom } from "@/lib/swr/use-dataroom";
+import { fetcher, timeAgo } from "@/lib/utils";
+
+import { DataroomHeader } from "@/components/datarooms/dataroom-header";
+import { DataroomNavigation } from "@/components/datarooms/dataroom-navigation";
+import AppLayout from "@/components/layouts/app";
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { Switch } from "@/components/ui/switch";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/components/ui/table";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
+
+import { ConversationSummary } from "./conversation-overview";
+
+export interface PublishedFAQ {
+ id: string;
+ editedQuestion: string;
+ originalQuestion?: string;
+ answer: string;
+ visibilityMode: "PUBLIC_DATAROOM" | "PUBLIC_LINK" | "PUBLIC_DOCUMENT";
+ status: "DRAFT" | "PUBLISHED" | "ARCHIVED";
+ createdAt: string;
+ updatedAt: string;
+ dataroom: {
+ name: string;
+ };
+ link?: {
+ name: string;
+ };
+ dataroomDocument?: {
+ document: {
+ name: string;
+ };
+ };
+ publishedByUser: {
+ name: string;
+ email: string;
+ };
+ sourceConversation?: {
+ id: string;
+ };
+ questionMessage?: {
+ id: string;
+ content: string;
+ };
+ answerMessage?: {
+ id: string;
+ content: string;
+ };
+}
+
+const visibilityIcons = {
+ PUBLIC_DATAROOM: ServerIcon,
+ PUBLIC_LINK: Link2Icon,
+ PUBLIC_DOCUMENT: FileTextIcon,
+};
+
+const visibilityLabels = {
+ PUBLIC_DATAROOM: "Dataroom",
+ PUBLIC_LINK: "Link",
+ PUBLIC_DOCUMENT: "Document",
+};
+
+export default function FAQOverview() {
+ const router = useRouter();
+ const { dataroom } = useDataroom();
+ const { currentTeamId: teamId } = useTeam();
+
+ const [isEditModalOpen, setIsEditModalOpen] = useState(false);
+ const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
+ const [isDeleting, setIsDeleting] = useState(false);
+ const [faqToDelete, setFaqToDelete] = useState<string | null>(null);
+ const [faqToEdit, setFaqToEdit] = useState<PublishedFAQ | null>(null);
+
+ // Fetch published FAQs
+ const {
+ data: faqs = [],
+ isLoading,
+ error,
+ } = useSWR<PublishedFAQ[]>(
+ dataroom && teamId
+ ? `/api/teams/${teamId}/datarooms/${dataroom.id}/faq`
+ : null,
+ fetcher,
+ {
+ revalidateOnFocus: true,
+ dedupingInterval: 10000,
+ keepPreviousData: true,
+ },
+ );
+
+ // SWR hook for fetching conversation summaries
+ const { data: conversations = [], isLoading: isLoadingConversations } =
+ useSWR<ConversationSummary[]>(
+ dataroom && teamId
+ ? `/api/teams/${teamId}/datarooms/${dataroom.id}/conversations`
+ : null,
+ fetcher,
+ {
+ revalidateOnFocus: true,
+ dedupingInterval: 10000,
+ keepPreviousData: true,
+ onError: (err) => {
+ console.error("Error fetching conversations:", err);
+ toast.error("Failed to load conversations");
+ },
+ },
+ );
+
+ const handleEdit = (faq: PublishedFAQ) => {
+ setFaqToEdit(faq);
+ setIsEditModalOpen(true);
+ };
+
+ const handleStatusToggle = async (faq: PublishedFAQ) => {
+ const newStatus = faq.status === "PUBLISHED" ? "DRAFT" : "PUBLISHED";
+
+ try {
+ const response = await fetch(
+ `/api/teams/${teamId}/datarooms/${dataroom?.id}/faq/${faq.id}`,
+ {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ status: newStatus }),
+ },
+ );
+
+ if (!response.ok) {
+ throw new Error("Failed to update FAQ status");
+ }
+
+ toast.success(`FAQ ${newStatus.toLowerCase()} successfully`);
+ mutate(`/api/teams/${teamId}/datarooms/${dataroom?.id}/faq`);
+ } catch (error) {
+ console.error("Error updating FAQ status:", error);
+ toast.error("Failed to update FAQ status");
+ }
+ };
+
+ const handleDelete = async (faqId: string) => {
+ if (!dataroom || !teamId) {
+ toast.error("Failed to delete FAQ");
+ return;
+ }
+ setIsDeleting(true);
+ try {
+ const response = await fetch(
+ `/api/teams/${teamId}/datarooms/${dataroom.id}/faq/${faqId}`,
+ {
+ method: "DELETE",
+ },
+ );
+
+ if (!response.ok) {
+ throw new Error("Failed to delete FAQ");
+ }
+
+ toast.success("FAQ deleted successfully");
+ mutate(`/api/teams/${teamId}/datarooms/${dataroom.id}/faq`);
+ setIsDeleteModalOpen(false);
+ setFaqToDelete(null);
+ } catch (error) {
+ console.error("Error deleting FAQ:", error);
+ toast.error("Failed to delete FAQ");
+ } finally {
+ setIsDeleting(false);
+ }
+ };
+
+ const VisibilityIcon = ({
+ mode,
+ }: {
+ mode: PublishedFAQ["visibilityMode"];
+ }) => {
+ const Icon = visibilityIcons[mode];
+ return <Icon className="h-4 w-4" />;
+ };
+
+ if (isLoading) {
+ return (
+ <Card>
+ <CardContent className="flex h-48 items-center justify-center">
+ <p>Loading published FAQs...</p>
+ </CardContent>
+ </Card>
+ );
+ }
+
+ if (error) {
+ return (
+ <Card>
+ <CardContent className="flex h-48 items-center justify-center">
+ <p className="text-destructive">Failed to load FAQs</p>
+ </CardContent>
+ </Card>
+ );
+ }
+
+ if (!dataroom) {
+ return <div>Loading...</div>;
+ }
+
+ if (faqs.length === 0) {
+ return (
+ <AppLayout>
+ <div 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} />
+ <DataroomNavigation dataroomId={dataroom.id} />
+ </header>
+
+ <Tabs defaultValue="faqs" className="space-y-6">
+ <TabsList>
+ <TabsTrigger value="conversations" asChild>
+ <Link
+ href={`/datarooms/${dataroom.id}/conversations`}
+ className="flex items-center gap-2"
+ >
+ <MessageSquare className="h-4 w-4" />
+ Conversations
+ <Badge variant="secondary">{conversations.length}</Badge>
+ </Link>
+ </TabsTrigger>
+ <TabsTrigger value="faqs" className="flex items-center gap-2">
+ <BookOpenCheckIcon className="h-4 w-4" />
+ Published FAQs
+ <Badge variant="secondary" className="ml-1">
+ {faqs.length}
+ </Badge>
+ </TabsTrigger>
+ </TabsList>
+
+ <TabsContent value="faqs">
+ <Card>
+ <CardContent className="flex h-48 flex-col items-center justify-center text-center">
+ <BookOpenCheckIcon className="mb-4 h-12 w-12 text-muted-foreground" />
+ <h3 className="mb-2 text-lg font-semibold">
+ No Published FAQs
+ </h3>
+ <p className="text-muted-foreground">
+ Start by publishing FAQs from conversations to help visitors
+ find answers quickly.
+ </p>
+ </CardContent>
+ </Card>
+ </TabsContent>
+ </Tabs>
+ </div>
+ </AppLayout>
+ );
+ }
+
+ return (
+ <AppLayout>
+ <div 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} />
+ <DataroomNavigation dataroomId={dataroom.id} />
+ </header>
+
+ <Tabs defaultValue="faqs" className="space-y-6">
+ <TabsList>
+ <TabsTrigger value="conversations" asChild>
+ <Link
+ href={`/datarooms/${dataroom.id}/conversations`}
+ className="flex items-center gap-2"
+ >
+ <MessageSquare className="h-4 w-4" />
+ Conversations
+ <Badge variant="notification">{conversations.length}</Badge>
+ </Link>
+ </TabsTrigger>
+ <TabsTrigger value="faqs" className="flex items-center gap-2">
+ <BookOpenCheckIcon className="h-4 w-4" />
+ Published FAQs
+ <Badge variant="notification">{faqs.length}</Badge>
+ </TabsTrigger>
+ </TabsList>
+
+ <TabsContent value="faqs">
+ <Card>
+ <CardHeader>
+ <CardTitle>Published FAQs</CardTitle>
+ </CardHeader>
+ <CardContent>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>Question & Answer</TableHead>
+ <TableHead>Visibility</TableHead>
+ <TableHead>Published</TableHead>
+ <TableHead>Published Date</TableHead>
+ <TableHead className="w-12">Action</TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {faqs.map((faq) => (
+ <TableRow key={faq.id} className="group">
+ <TableCell className="max-w-md">
+ <div className="space-y-3">
+ {/* Question */}
+ <div>
+ <div className="flex items-start gap-2">
+ <span className="rounded bg-primary/80 px-1.5 py-0.5 text-sm font-medium text-primary-foreground">
+ Q
+ </span>
+ <div className="line-clamp-2 flex flex-col px-1 py-0.5 text-sm font-medium">
+ {faq.editedQuestion}
+ </div>
+ </div>
+ </div>
+
+ {/* Answer */}
+ <div className="flex items-start gap-2">
+ <span className="rounded bg-secondary px-1.5 py-0.5 text-sm font-medium text-foreground group-hover:bg-primary-foreground">
+ A
+ </span>
+ <div className="line-clamp-2 flex flex-col gap-1 rounded-sm bg-muted px-2 py-0.5 text-sm text-foreground group-hover:bg-primary-foreground">
+ {faq.answer}
+ </div>
+ </div>
+ </div>
+ </TableCell>
+ <TableCell>
+ <div className="flex items-center space-x-2">
+ <VisibilityIcon mode={faq.visibilityMode} />
+ <span className="text-sm">
+ {visibilityLabels[faq.visibilityMode]}
+ </span>
+ </div>
+ {faq.visibilityMode === "PUBLIC_LINK" && faq.link && (
+ <p className="mt-1 text-xs text-muted-foreground">
+ {faq.link.name}
+ </p>
+ )}
+ {faq.visibilityMode === "PUBLIC_DOCUMENT" &&
+ faq.dataroomDocument && (
+ <p className="mt-1 text-xs text-muted-foreground">
+ {faq.dataroomDocument.document.name}
+ </p>
+ )}
+ </TableCell>
+ <TableCell>
+ <div className="flex items-center space-x-2">
+ <Switch
+ checked={faq.status === "PUBLISHED"}
+ onCheckedChange={() => handleStatusToggle(faq)}
+ aria-label={`${faq.status === "PUBLISHED" ? "Unpublish" : "Publish"} FAQ`}
+ />
+ <span className="text-sm text-muted-foreground">
+ {faq.status === "PUBLISHED" ? "Yes" : "No"}
+ </span>
+ </div>
+ </TableCell>
+ <TableCell>
+ <div className="flex items-center space-x-1">
+ <ClockIcon className="h-4 w-4 text-muted-foreground" />
+ <span className="text-sm">
+ {timeAgo(new Date(faq.createdAt))}
+ </span>
+ </div>
+ </TableCell>
+
+ <TableCell>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="outline" size="icon">
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem onClick={() => handleEdit(faq)}>
+ <EditIcon className="mr-1 h-4 w-4" />
+ Edit FAQ
+ </DropdownMenuItem>
+ {faq.sourceConversation && (
+ <DropdownMenuItem
+ onClick={() =>
+ router.push(
+ `/datarooms/${dataroom?.id}/conversations/${faq.sourceConversation?.id}`,
+ )
+ }
+ >
+ <MessageSquare className="mr-1 h-4 w-4" />
+ View Conversation
+ </DropdownMenuItem>
+ )}
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ className="text-destructive"
+ onClick={() => {
+ setFaqToDelete(faq.id);
+ setIsDeleteModalOpen(true);
+ }}
+ >
+ <Trash2Icon className="mr-1 h-4 w-4" />
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </CardContent>
+ </Card>
+
+ {/* Delete Confirmation Modal */}
+ <Dialog
+ open={isDeleteModalOpen}
+ onOpenChange={setIsDeleteModalOpen}
+ >
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Delete FAQ</DialogTitle>
+ <DialogDescription>
+ Are you sure you want to delete this FAQ? This action cannot
+ be undone.
+ </DialogDescription>
+ </DialogHeader>
+ <DialogFooter>
+ <Button
+ variant="outline"
+ onClick={() => setIsDeleteModalOpen(false)}
+ disabled={isDeleting}
+ >
+ Cancel
+ </Button>
+ <Button
+ variant="destructive"
+ onClick={() => faqToDelete && handleDelete(faqToDelete)}
+ disabled={isDeleting}
+ >
+ {isDeleting ? "Deleting..." : "Delete"}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+
+ {/* Edit FAQ Modal */}
+ {faqToEdit && (
+ <EditFAQModal
+ faq={faqToEdit}
+ dataroomId={dataroom?.id!}
+ teamId={teamId!}
+ isOpen={isEditModalOpen}
+ onClose={() => {
+ setIsEditModalOpen(false);
+ setFaqToEdit(null);
+ }}
+ onSuccess={() => {
+ mutate(`/api/teams/${teamId}/datarooms/${dataroom?.id}/faq`);
+ setIsEditModalOpen(false);
+ setFaqToEdit(null);
+ }}
+ />
+ )}
+ </TabsContent>
+ </Tabs>
+ </div>
+ </AppLayout>
+ );
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/faq/[faqId].ts b/pages/api/teams/[teamId]/datarooms/[id]/faq/[faqId].ts
new file mode 100644
index 00000000..a9377d36
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/faq/[faqId].ts
@@ -0,0 +1,10 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import publishFAQRoute from "@/ee/features/conversations/api/team-faqs-route";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ return await publishFAQRoute(req, res);
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/faq/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/faq/index.ts
new file mode 100644
index 00000000..a9377d36
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/faq/index.ts
@@ -0,0 +1,10 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import publishFAQRoute from "@/ee/features/conversations/api/team-faqs-route";
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ return await publishFAQRoute(req, res);
+}
diff --git a/pages/datarooms/[id]/conversations/faqs/index.tsx b/pages/datarooms/[id]/conversations/faqs/index.tsx
new file mode 100644
index 00000000..8e6a4213
--- /dev/null
+++ b/pages/datarooms/[id]/conversations/faqs/index.tsx
@@ -0,0 +1 @@
+export { default } from "@/ee/features/conversations/pages/faq-overview";