Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add question to links table
Marc Seitz128166756e9b
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsxindex 77c35718..d5e0e796 100644--- a/components/links/link-sheet/index.tsx+++ b/components/links/link-sheet/index.tsx@@ -41,6 +41,9 @@ export const DEFAULT_LINK_PROPS = {metaTitle: null,metaDescription: null,metaImage: null,+ enabledQuestion: false,+ questionText: null,+ questionType: null,};export type DEFAULT_LINK_TYPE = {@@ -61,6 +64,9 @@ export type DEFAULT_LINK_TYPE = {metaTitle: string | null; // metatagsmetaDescription: string | null; // metatagsmetaImage: string | null; // metatags+ enableQuestion?: boolean; // feedback question+ questionText: string | null;+ questionType: string | null;};export default function LinkSheet({diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsxindex d6ddcffa..59de10bb 100644--- a/components/links/link-sheet/link-options.tsx+++ b/components/links/link-sheet/link-options.tsx@@ -19,6 +19,7 @@ import OGSection from "@/components/links/link-sheet/og-section";import FeedbackSection from "@/components/links/link-sheet/feedback-section";import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";import { usePlan } from "@/lib/swr/use-billing";+import QuestionSection from "./question-section";export const LinkOptions = ({data,@@ -29,6 +30,7 @@ export const LinkOptions = ({}) => {const { plan } = usePlan();const hasFreePlan = plan?.plan === "free";+ const isNotBusiness = plan?.plan !== "business";const [openUpgradeModal, setOpenUpgradeModal] = useState<boolean>(false);const [trigger, setTrigger] = useState<string>("");@@ -75,6 +77,11 @@ export const LinkOptions = ({/><PasswordSection {...{ data, setData }} /><FeedbackSection {...{ data, setData }} />+ <QuestionSection+ {...{ data, setData }}+ hasFreePlan={isNotBusiness}+ handleUpgradeStateChange={handleUpgradeStateChange}+ /></AccordionContent></AccordionItem></Accordion>diff --git a/components/links/link-sheet/question-section.tsx b/components/links/link-sheet/question-section.tsxnew file mode 100644index 00000000..5682f6a7--- /dev/null+++ b/components/links/link-sheet/question-section.tsx@@ -0,0 +1,140 @@+import {+ Dispatch,+ SetStateAction,+ useState,+ useEffect,+ useCallback,+} from "react";+import { Switch } from "@/components/ui/switch";+import { cn } from "@/lib/utils";+import { DEFAULT_LINK_TYPE } from ".";+import { motion } from "framer-motion";+import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";+import LoadingSpinner from "@/components/ui/loading-spinner";+import {+ Upload as ArrowUpTrayIcon,+ BadgeInfoIcon,+ HelpCircleIcon,+} from "lucide-react";+import { Input } from "@/components/ui/input";+import { Textarea } from "@/components/ui/textarea";+import { Label } from "@/components/ui/label";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@/components/ui/select";++export default function QuestionSection({+ data,+ setData,+ hasFreePlan,+ handleUpgradeStateChange,+}: {+ data: DEFAULT_LINK_TYPE;+ setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;+ hasFreePlan: boolean;+ handleUpgradeStateChange: (state: boolean, trigger: string) => void;+}) {+ const { enableQuestion, questionText, questionType } = data;+ const [enabled, setEnabled] = useState<boolean>(false);++ useEffect(() => {+ setEnabled(enableQuestion!);+ }, [enableQuestion]);++ const handleQuestion = async () => {+ const updatedQuestion = !enabled;++ setData({ ...data, enableQuestion: updatedQuestion });+ setEnabled(updatedQuestion);+ };++ return (+ <div className="pb-5">+ <div className="flex items-center justify-between">+ <div className="flex items-center justify-between space-x-2">+ <h2+ className={cn(+ "flex items-center gap-x-2 text-sm font-medium leading-6",+ enabled ? "text-foreground" : "text-muted-foreground",+ hasFreePlan ? "cursor-pointer" : undefined,+ )}+ onClick={+ hasFreePlan+ ? () =>+ handleUpgradeStateChange(+ true,+ "link_sheet_question_section",+ )+ : undefined+ }+ >+ Feedback Question+ <span>+ <HelpCircleIcon className="text-muted-foreground h-4 w-4" />+ </span>+ {hasFreePlan && (+ <span className="bg-background text-foreground ring-1 ring-gray-800 dark:ring-gray-500 rounded-full px-2 py-0.5 text-xs ml-2">+ Business+ </span>+ )}+ </h2>+ </div>+ <Switch+ checked={enabled}+ onClick={+ hasFreePlan+ ? () =>+ handleUpgradeStateChange(true, "link_sheet_question_section")+ : undefined+ }+ className={hasFreePlan ? "opacity-50" : undefined}+ onCheckedChange={hasFreePlan ? undefined : handleQuestion}+ />+ </div>++ {enabled && (+ <motion.div+ className="relative mt-4 space-y-3"+ {...FADE_IN_ANIMATION_SETTINGS}+ >+ <div className="flex flex-col w-full items-start gap-6 overflow-x-visible pb-4 pt-0">+ <div className="w-full space-y-2">+ <Label>Question Type</Label>+ <Select defaultValue="yes-no">+ <SelectTrigger className="flex w-full rounded-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-offset-3 focus:ring-gray-400 sm:text-sm sm:leading-6">+ <SelectValue placeholder="Select a question type" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="yes-no">Yes / No</SelectItem>+ </SelectContent>+ </Select>+ </div>+ <div className="w-full space-y-2">+ <Label htmlFor="question">Question</Label>+ <Input+ className="flex w-full rounded-md border-0 py-1.5 text-foreground bg-background shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"+ id="question"+ type="text"+ name="question"+ required+ placeholder="Are you interested?"+ value={questionText || ""}+ onChange={(e) =>+ setData({+ ...data,+ questionText: e.target.value,+ questionType: "YES_NO",+ })+ }+ />+ </div>+ </div>+ </motion.div>+ )}+ </div>+ );+}diff --git a/prisma/migrations/20240415000000_add_feedback/migration.sql b/prisma/migrations/20240415000000_add_feedback/migration.sqlindex 1e2a8388..7ba0ecca 100644--- a/prisma/migrations/20240415000000_add_feedback/migration.sql+++ b/prisma/migrations/20240415000000_add_feedback/migration.sql@@ -1,8 +1,10 @@+-- AlterTable+ALTER TABLE "Link" ADD COLUMN "enableQuestion" BOOLEAN DEFAULT false;+-- CreateTableCREATE TABLE "Feedback" ("id" TEXT NOT NULL,- "documentId" TEXT NOT NULL,- "enabled" BOOLEAN NOT NULL DEFAULT false,+ "linkId" TEXT NOT NULL,"data" JSONB NOT NULL,"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,"updatedAt" TIMESTAMP(3) NOT NULL,@@ -23,10 +25,10 @@ CREATE TABLE "FeedbackResponse" ();-- CreateIndex-CREATE UNIQUE INDEX "Feedback_documentId_key" ON "Feedback"("documentId");+CREATE UNIQUE INDEX "Feedback_linkId_key" ON "Feedback"("linkId");-- CreateIndex-CREATE INDEX "Feedback_documentId_idx" ON "Feedback"("documentId");+CREATE INDEX "Feedback_linkId_idx" ON "Feedback"("linkId");-- CreateIndexCREATE UNIQUE INDEX "FeedbackResponse_viewId_key" ON "FeedbackResponse"("viewId");@@ -38,7 +40,7 @@ CREATE INDEX "FeedbackResponse_feedbackId_idx" ON "FeedbackResponse"("feedbackIdCREATE INDEX "FeedbackResponse_viewId_idx" ON "FeedbackResponse"("viewId");-- AddForeignKey-ALTER TABLE "Feedback" ADD CONSTRAINT "Feedback_documentId_fkey" FOREIGN KEY ("documentId") REFERENCES "Document"("id") ON DELETE CASCADE ON UPDATE CASCADE;+ALTER TABLE "Feedback" ADD CONSTRAINT "Feedback_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "Link"("id") ON DELETE CASCADE ON UPDATE CASCADE;-- AddForeignKeyALTER TABLE "FeedbackResponse" ADD CONSTRAINT "FeedbackResponse_feedbackId_fkey" FOREIGN KEY ("feedbackId") REFERENCES "Feedback"("id") ON DELETE CASCADE ON UPDATE CASCADE;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 2cce872f..372a9df6 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -135,7 +135,6 @@ model Document {views View[]versions DocumentVersion[]conversations Conversation[]- feedback Feedback?folderId String? // Optional Folder ID for documents in foldersfolder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)@@ -217,7 +216,9 @@ model Link {createdAt DateTime @default(now())updatedAt DateTime @updatedAtenableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications- enableFeedback Boolean? @default(true) // Optional give user a option to enable the feedback toolbar+ enableFeedback Boolean? @default(true) // Optional give user a option to enable the reactions toolbar+ enableQuestion Boolean? @default(false) // Optional give user a option to enable the question feedback+ feedback Feedback?// custom metatagsmetaTitle String? // This will be the meta title of the link@@ -436,18 +437,17 @@ model DataroomBrand {}model Feedback {- id String @id @default(cuid())- documentId String @unique- document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)- enabled Boolean @default(false) // This indicates if feedback is enabled for this document- data Json // This will store the feedback question data: {question: "What is the purpose of this document?", type: "yes/no", options: ["Yes", "No"]}+ id String @id @default(cuid())+ linkId String @unique+ link Link @relation(fields: [linkId], references: [id], onDelete: Cascade)+ data Json // This will store the feedback question data: {question: "What is the purpose of this document?", type: "yes/no", options: ["Yes", "No"]}responses FeedbackResponse[]createdAt DateTime @default(now())updatedAt DateTime @updatedAt- @@index([documentId])+ @@index([linkId])}model FeedbackResponse {