Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add two sruvey questions
Iuliia Shnai3de50aff94fc
diff --git a/components/settings/survey-settings.tsx b/components/settings/survey-settings.tsxnew file mode 100644index 00000000..7a8d9700--- /dev/null+++ b/components/settings/survey-settings.tsx@@ -0,0 +1,431 @@+"use client";++import { useEffect, useState } from "react";++import { useTeam } from "@/context/team-context";+import { ArrowLeftIcon, CheckCircle2Icon, PencilIcon } from "lucide-react";+import { toast } from "sonner";++import { Button } from "@/components/ui/button";+import {+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+} from "@/components/ui/card";+import {+ Dialog,+ DialogContent,+ DialogHeader,+ DialogTitle,+} from "@/components/ui/dialog";++const DEAL_TYPE_OPTIONS = [+ { value: "startup-fundraising", label: "Startup Fundraising" },+ { value: "fund-management", label: "Fund Management" },+ { value: "mergers-acquisitions", label: "Mergers & Acquisitions" },+ { value: "financial-operations", label: "Financial Operations" },+ { value: "real-estate", label: "Real Estate" },+ { value: "project-management", label: "Project Management" },+];++const DEAL_SIZE_OPTIONS = [+ { value: "0-500k", label: "$0 - $500K" },+ { value: "500k-5m", label: "$500K - $5M" },+ { value: "5m-10m", label: "$5M - $10M" },+ { value: "10m-100m", label: "$10M - $100M" },+ { value: "100m+", label: "$100M+" },+];++export function SurveySettings() {+ const teamInfo = useTeam();+ const teamId = teamInfo?.currentTeam?.id;++ const [dealType, setDealType] = useState<string | null>(null);+ const [dealTypeOther, setDealTypeOther] = useState<string | null>(null);+ const [dealSize, setDealSize] = useState<string | null>(null);+ const [isLoading, setIsLoading] = useState(true);+ const [isEditing, setIsEditing] = useState(false);+ const [editStep, setEditStep] = useState(1);+ const [editDealType, setEditDealType] = useState<string | null>(null);+ const [editDealTypeOther, setEditDealTypeOther] = useState<string>("");+ const [showOtherInput, setShowOtherInput] = useState(false);+ const [editDealSize, setEditDealSize] = useState<string | null>(null);+ const [isSaving, setIsSaving] = useState(false);++ useEffect(() => {+ const fetchSurvey = async () => {+ if (!teamId) return;++ try {+ const response = await fetch(`/api/teams/${teamId}/survey`);+ if (response.ok) {+ const data = await response.json();+ setDealType(data.dealType);+ setDealTypeOther(data.dealTypeOther);+ setDealSize(data.dealSize);+ }+ } catch (error) {+ console.error("Failed to fetch survey data:", error);+ } finally {+ setIsLoading(false);+ }+ };++ fetchSurvey();+ }, [teamId]);++ const getDealTypeLabel = (value: string | null, otherText?: string | null) => {+ if (!value) return null;+ if (value === "other" && otherText) {+ return `Other: ${otherText}`;+ }+ return DEAL_TYPE_OPTIONS.find((opt) => opt.value === value)?.label || value;+ };++ const getDealSizeLabel = (value: string | null) => {+ if (!value) return null;+ return DEAL_SIZE_OPTIONS.find((opt) => opt.value === value)?.label || value;+ };++ const handleEdit = () => {+ setEditDealType(dealType);+ setEditDealTypeOther(dealTypeOther || "");+ setEditDealSize(dealSize);+ setEditStep(1);+ setShowOtherInput(false);+ setIsEditing(true);+ };++ const handleDealTypeSelect = (value: string) => {+ setEditDealType(value);+ setShowOtherInput(false);+ if (value === "project-management") {+ setEditDealSize(null);+ handleSave(value, null, null);+ } else {+ setEditStep(2);+ }+ };++ const handleOtherSubmit = () => {+ if (!editDealTypeOther.trim()) return;+ setEditDealType("other");+ setShowOtherInput(false);+ setEditStep(2);+ };++ const handleSave = async (+ type?: string,+ size?: string | null,+ otherText?: string | null,+ ) => {+ const finalDealType = type || editDealType;+ if (!finalDealType || !teamId) return;++ setIsSaving(true);+ try {+ const response = await fetch(`/api/teams/${teamId}/survey`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ dealType: finalDealType,+ dealTypeOther:+ otherText !== undefined ? otherText : editDealTypeOther || null,+ dealSize: size !== undefined ? size : editDealSize,+ }),+ });++ if (!response.ok) {+ throw new Error("Failed to save");+ }++ setDealType(finalDealType);+ setDealTypeOther(+ otherText !== undefined ? otherText : editDealTypeOther || null,+ );+ setDealSize(size !== undefined ? size : editDealSize);+ setIsEditing(false);+ toast.success("Survey answers updated!");+ } catch (error) {+ console.error("Failed to save survey:", error);+ toast.error("Failed to save changes");+ } finally {+ setIsSaving(false);+ }+ };++ const hasAnswered = !!dealType;++ return (+ <>+ <Card>+ <CardHeader>+ <div className="flex items-center justify-between">+ <div>+ <CardTitle>Team Survey</CardTitle>+ <CardDescription>+ Information about your deal flow to help us improve Papermark+ </CardDescription>+ </div>+ {hasAnswered && (+ <Button variant="outline" size="sm" onClick={handleEdit}>+ <PencilIcon className="mr-2 h-4 w-4" />+ Edit+ </Button>+ )}+ </div>+ </CardHeader>+ <CardContent>+ {isLoading ? (+ <p className="text-sm text-muted-foreground">Loading...</p>+ ) : hasAnswered ? (+ <div className="space-y-4">+ <div className="flex items-start gap-3">+ <CheckCircle2Icon className="mt-0.5 h-5 w-5 text-green-500" />+ <div>+ <p className="text-sm font-medium">Deal Type</p>+ <p className="text-sm text-muted-foreground">+ {getDealTypeLabel(dealType, dealTypeOther)}+ </p>+ </div>+ </div>+ {dealSize && (+ <div className="flex items-start gap-3">+ <CheckCircle2Icon className="mt-0.5 h-5 w-5 text-green-500" />+ <div>+ <p className="text-sm font-medium">Deal Size</p>+ <p className="text-sm text-muted-foreground">+ {getDealSizeLabel(dealSize)}+ </p>+ </div>+ </div>+ )}+ </div>+ ) : editStep === 1 ? (+ <div className="space-y-4">+ <p className="text-sm font-medium">+ What do you use Papermark for?+ </p>+ <div className="grid gap-2">+ {DEAL_TYPE_OPTIONS.map((option) => (+ <button+ key={option.value}+ onClick={() => handleDealTypeSelect(option.value)}+ disabled={isSaving}+ className="flex items-center justify-between rounded-lg border border-border px-4 py-3 text-left transition-all hover:border-primary/50 hover:bg-muted/50"+ >+ <span className="font-medium">{option.label}</span>+ </button>+ ))}+ {/* Other - inline input */}+ {showOtherInput ? (+ <div className="flex gap-2">+ <input+ type="text"+ value={editDealTypeOther}+ onChange={(e) => setEditDealTypeOther(e.target.value)}+ placeholder="Please specify..."+ className="flex-1 rounded-lg border border-border bg-background px-4 py-3 text-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary"+ autoFocus+ onKeyDown={(e) => {+ if (e.key === "Enter" && editDealTypeOther.trim()) {+ handleOtherSubmit();+ }+ }}+ />+ <Button+ onClick={handleOtherSubmit}+ disabled={!editDealTypeOther.trim() || isSaving}+ >+ →+ </Button>+ </div>+ ) : (+ <button+ onClick={() => setShowOtherInput(true)}+ disabled={isSaving}+ className="flex items-center justify-between rounded-lg border border-border px-4 py-3 text-left transition-all hover:border-primary/50 hover:bg-muted/50"+ >+ <span className="font-medium">Other</span>+ </button>+ )}+ </div>+ </div>+ ) : (+ <div className="space-y-4">+ <div className="flex items-center gap-2">+ <button+ onClick={() => setEditStep(1)}+ className="rounded-full p-1 hover:bg-muted"+ disabled={isSaving}+ >+ <ArrowLeftIcon className="h-4 w-4" />+ </button>+ <p className="text-sm font-medium">+ {editDealType === "mergers-acquisitions" ||+ editDealType === "real-estate" ||+ editDealType === "financial-operations" ||+ editDealType === "other"+ ? "What's the deal size?"+ : "How much are you raising?"}+ </p>+ </div>+ <div className="grid gap-2">+ {DEAL_SIZE_OPTIONS.map((option) => (+ <button+ key={option.value}+ onClick={() => setEditDealSize(option.value)}+ className={`flex items-center justify-between rounded-lg border px-4 py-3 text-left transition-all ${+ editDealSize === option.value+ ? "border-primary bg-primary/5 ring-1 ring-primary"+ : "border-border hover:border-primary/50 hover:bg-muted/50"+ }`}+ >+ <span className="font-medium">{option.label}</span>+ <div+ className={`h-4 w-4 rounded-full border-2 transition-colors ${+ editDealSize === option.value+ ? "border-primary bg-primary"+ : "border-muted-foreground/30"+ }`}+ />+ </button>+ ))}+ </div>+ <div className="flex justify-end">+ <Button+ onClick={() => handleSave()}+ disabled={!editDealSize || isSaving}+ >+ {isSaving ? "Saving..." : "Save"}+ </Button>+ </div>+ </div>+ )}+ </CardContent>+ </Card>++ {/* Edit Dialog */}+ <Dialog open={isEditing} onOpenChange={setIsEditing}>+ <DialogContent className="sm:max-w-md">+ {editStep === 1 ? (+ <>+ <DialogHeader>+ <DialogTitle>What do you use Papermark for?</DialogTitle>+ </DialogHeader>++ <div className="grid gap-2 py-4">+ {DEAL_TYPE_OPTIONS.map((option) => (+ <button+ key={option.value}+ onClick={() => handleDealTypeSelect(option.value)}+ disabled={isSaving}+ className={`flex items-center justify-between rounded-lg border px-4 py-3 text-left transition-all ${+ editDealType === option.value+ ? "border-primary bg-primary/5 ring-1 ring-primary"+ : "border-border hover:border-primary/50 hover:bg-muted/50"+ }`}+ >+ <span className="font-medium">{option.label}</span>+ </button>+ ))}+ {/* Other - inline input */}+ {showOtherInput ? (+ <div className="flex gap-2">+ <input+ type="text"+ value={editDealTypeOther}+ onChange={(e) => setEditDealTypeOther(e.target.value)}+ placeholder="Please specify..."+ className="flex-1 rounded-lg border border-border bg-background px-4 py-3 text-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary"+ autoFocus+ onKeyDown={(e) => {+ if (e.key === "Enter" && editDealTypeOther.trim()) {+ handleOtherSubmit();+ }+ }}+ />+ <Button+ onClick={handleOtherSubmit}+ disabled={!editDealTypeOther.trim() || isSaving}+ >+ →+ </Button>+ </div>+ ) : (+ <button+ onClick={() => setShowOtherInput(true)}+ disabled={isSaving}+ className={`flex items-center justify-between rounded-lg border px-4 py-3 text-left transition-all ${+ editDealType === "other"+ ? "border-primary bg-primary/5 ring-1 ring-primary"+ : "border-border hover:border-primary/50 hover:bg-muted/50"+ }`}+ >+ <span className="font-medium">Other</span>+ </button>+ )}+ </div>+ </>+ ) : (+ <>+ <DialogHeader>+ <DialogTitle>+ {editDealType === "mergers-acquisitions" ||+ editDealType === "real-estate" ||+ editDealType === "financial-operations" ||+ editDealType === "other"+ ? "What's the deal size?"+ : "How much are you raising?"}+ </DialogTitle>+ </DialogHeader>++ <div className="grid gap-2 py-4">+ {DEAL_SIZE_OPTIONS.map((option) => (+ <button+ key={option.value}+ onClick={() => setEditDealSize(option.value)}+ className={`flex items-center justify-between rounded-lg border px-4 py-3 text-left transition-all ${+ editDealSize === option.value+ ? "border-primary bg-primary/5 ring-1 ring-primary"+ : "border-border hover:border-primary/50 hover:bg-muted/50"+ }`}+ >+ <span className="font-medium">{option.label}</span>+ <div+ className={`h-4 w-4 rounded-full border-2 transition-colors ${+ editDealSize === option.value+ ? "border-primary bg-primary"+ : "border-muted-foreground/30"+ }`}+ />+ </button>+ ))}+ </div>++ <div className="flex items-center justify-between">+ <Button+ variant="outline"+ onClick={() => setEditStep(1)}+ disabled={isSaving}+ >+ Back+ </Button>+ <Button+ onClick={() => handleSave()}+ disabled={!editDealSize || isSaving}+ >+ {isSaving ? "Saving..." : "Save"}+ </Button>+ </div>+ </>+ )}+ </DialogContent>+ </Dialog>+ </>+ );+}diff --git a/components/shared/dealflow-popup.tsx b/components/shared/dealflow-popup.tsxnew file mode 100644index 00000000..fac27f56--- /dev/null+++ b/components/shared/dealflow-popup.tsx@@ -0,0 +1,315 @@+"use client";++import { useRouter } from "next/router";++import { useEffect, useState } from "react";++import { useTeam } from "@/context/team-context";+import { ArrowLeftIcon, CheckCircleIcon, XIcon } from "lucide-react";+import { toast } from "sonner";++import Link from "next/link";++const DEAL_TYPE_OPTIONS = [+ { value: "startup-fundraising", label: "Startup Fundraising" },+ { value: "fund-management", label: "Fund Management" },+ { value: "mergers-acquisitions", label: "Mergers & Acquisitions" },+ { value: "financial-operations", label: "Financial Operations" },+ { value: "real-estate", label: "Real Estate" },+ { value: "project-management", label: "Project Management" },+];++const DEAL_SIZE_OPTIONS = [+ { value: "0-500k", label: "$0 - $500K" },+ { value: "500k-5m", label: "$500K - $5M" },+ { value: "5m-10m", label: "$5M - $10M" },+ { value: "10m-100m", label: "$10M - $100M" },+ { value: "100m+", label: "$100M+" },+];++export function DealflowPopup() {+ const router = useRouter();+ const teamInfo = useTeam();+ const [isOpen, setIsOpen] = useState(false);+ const [step, setStep] = useState(1);+ const [dealType, setDealType] = useState<string | null>(null);+ const [dealTypeOther, setDealTypeOther] = useState<string>("");+ const [showOtherInput, setShowOtherInput] = useState(false);+ const [dealSize, setDealSize] = useState<string | null>(null);+ const [isSubmitting, setIsSubmitting] = useState(false);++ const teamId = teamInfo?.currentTeam?.id;+ const storageKey = `dealflow-survey-dismissed-${teamId}`;++ // Check if we're on onboarding/welcome pages+ const isOnboarding = router.pathname.startsWith("/welcome");++ useEffect(() => {+ // Don't show on onboarding pages+ if (isOnboarding) return;++ // Don't show if no team context+ if (!teamId) return;++ // Check if already dismissed in localStorage for this team+ const dismissed = localStorage.getItem(storageKey);+ if (dismissed) return;++ // Check if team already has survey data+ const checkSurvey = async () => {+ try {+ const response = await fetch(`/api/teams/${teamId}/survey`);+ if (response.ok) {+ const data = await response.json();++ // If dealType is missing → show popup from question 1+ if (!data.dealType) {+ setTimeout(() => {+ setStep(1);+ setIsOpen(true);+ }, 2000);+ }+ // If dealType exists but dealSize is missing (and not project-management) → show popup from question 2+ else if (!data.dealSize && data.dealType !== "project-management") {+ setTimeout(() => {+ setDealType(data.dealType);+ setDealTypeOther(data.dealTypeOther || "");+ setStep(2);+ setIsOpen(true);+ }, 2000);+ }+ // If both are filled → don't show popup+ }+ } catch (error) {+ console.error("Failed to check survey status:", error);+ }+ };++ checkSurvey();+ }, [teamId, storageKey, isOnboarding]);++ const handleDealTypeSelect = (value: string) => {+ setDealType(value);+ setShowOtherInput(false);+ if (value === "project-management") {+ // Project management doesn't need a second step - go straight to thank you+ handleSubmit(value, null, null);+ } else {+ setStep(2);+ }+ };++ const handleOtherSubmit = () => {+ if (!dealTypeOther.trim()) return;+ setDealType("other");+ setShowOtherInput(false);+ // After entering "Other" text, go to deal size question+ setStep(2);+ };++ const handleDealSizeSelect = async (value: string) => {+ setDealSize(value);+ await handleSubmit(dealType, value, dealTypeOther || null);+ };++ const handleSubmit = async (+ type?: string | null,+ size?: string | null,+ otherText?: string | null,+ ) => {+ const finalDealType = type || dealType;+ if (!finalDealType) return;++ setIsSubmitting(true);+ try {+ const response = await fetch(+ `/api/teams/${teamInfo?.currentTeam?.id}/survey`,+ {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ dealType: finalDealType,+ dealTypeOther:+ otherText !== undefined+ ? otherText+ : dealTypeOther || null,+ dealSize: size !== undefined ? size : dealSize,+ }),+ },+ );++ if (!response.ok) {+ throw new Error("Failed to save response");+ }++ localStorage.setItem(storageKey, "true");+ setStep(3); // Go to thank you screen+ } catch (error) {+ console.error("Failed to save survey response:", error);+ toast.error("Failed to save your response");+ } finally {+ setIsSubmitting(false);+ }+ };++ const handleClose = () => {+ setIsOpen(false);+ };++ const handleDismiss = () => {+ localStorage.setItem(storageKey, "true");+ setIsOpen(false);+ };++ const handleBack = () => {+ setStep(1);+ setDealType(null);+ setDealSize(null);+ setShowOtherInput(false);+ };++ const getDealSizeQuestion = () => {+ switch (dealType) {+ case "startup-fundraising":+ case "fund-management":+ return "How much are you raising?";+ case "mergers-acquisitions":+ case "real-estate":+ case "financial-operations":+ return "What's the deal size?";+ default:+ return "What's the typical deal size?";+ }+ };++ if (!isOpen) return null;++ return (+ <div className="fixed bottom-4 right-4 z-50 w-full max-w-sm animate-in fade-in slide-in-from-bottom-4 duration-300">+ <div className="rounded-lg border bg-background p-4 shadow-lg">+ {step === 1 ? (+ <>+ <div className="mb-4 flex items-start justify-between">+ <div>+ <h3 className="text-lg font-semibold">What do you use Papermark for?</h3>++ </div>+ <button+ onClick={handleDismiss}+ className="rounded-full p-1 hover:bg-muted"+ >+ <XIcon className="h-4 w-4 text-muted-foreground" />+ </button>+ </div>++ <div className="grid gap-2">+ {DEAL_TYPE_OPTIONS.map((option) => (+ <button+ key={option.value}+ onClick={() => handleDealTypeSelect(option.value)}+ disabled={isSubmitting}+ className="flex items-center justify-between rounded-lg border border-border px-3 py-2 text-left text-sm transition-all hover:border-primary/50 hover:bg-muted/50"+ >+ <span className="font-medium">{option.label}</span>+ </button>+ ))}+ {/* Other - inline input */}+ {showOtherInput ? (+ <div className="flex gap-2">+ <input+ type="text"+ value={dealTypeOther}+ onChange={(e) => setDealTypeOther(e.target.value)}+ placeholder="Please specify..."+ className="flex-1 rounded-lg border border-border bg-background px-3 py-2 text-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary"+ autoFocus+ onKeyDown={(e) => {+ if (e.key === "Enter" && dealTypeOther.trim()) {+ handleOtherSubmit();+ }+ }}+ />+ <button+ onClick={handleOtherSubmit}+ disabled={!dealTypeOther.trim() || isSubmitting}+ className="rounded-lg bg-primary px-3 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50"+ >+ →+ </button>+ </div>+ ) : (+ <button+ onClick={() => setShowOtherInput(true)}+ disabled={isSubmitting}+ className="flex items-center justify-between rounded-lg border border-border px-3 py-2 text-left text-sm transition-all hover:border-primary/50 hover:bg-muted/50"+ >+ <span className="font-medium">Other</span>+ </button>+ )}+ </div>++ <p className="mt-3 text-xs text-muted-foreground">+ By answering each question, you receive $10 credit+ </p>+ </>+ ) : step === 2 ? (+ <>+ <div className="mb-4 flex items-start justify-between">+ <div>+ <h3 className="text-lg font-semibold">+ {getDealSizeQuestion()}+ </h3>+ </div>+ <button+ onClick={handleDismiss}+ className="rounded-full p-1 hover:bg-muted"+ >+ <XIcon className="h-4 w-4 text-muted-foreground" />+ </button>+ </div>++ <div className="grid gap-2">+ {DEAL_SIZE_OPTIONS.map((option) => (+ <button+ key={option.value}+ onClick={() => handleDealSizeSelect(option.value)}+ disabled={isSubmitting}+ className="flex items-center justify-between rounded-lg border border-border px-3 py-2 text-left text-sm transition-all hover:border-primary/50 hover:bg-muted/50"+ >+ <span className="font-medium">{option.label}</span>+ </button>+ ))}+ </div>++ <p className="mt-3 text-xs text-muted-foreground">+ By answering each question, you receive $10 credit+ </p>+ </>+ ) : (+ <>+ <div className="mb-4 flex items-start justify-between">+ <div className="flex items-center gap-3">+ <CheckCircleIcon className="h-6 w-6 text-green-500" />+ <h3 className="text-lg font-semibold">Thanks for sharing!</h3>+ </div>+ <button+ onClick={handleClose}+ className="rounded-full p-1 hover:bg-muted"+ >+ <XIcon className="h-4 w-4 text-muted-foreground" />+ </button>+ </div>++ <p className="mb-4 text-sm text-muted-foreground">+ Your next payment will be minus $20.+ </p>+++ </>+ )}+ </div>+ </div>+ );+}diff --git a/components/welcome/dataroom-trial.tsx b/components/welcome/dataroom-trial.tsxindex 0747cefb..460386be 100644--- a/components/welcome/dataroom-trial.tsx+++ b/components/welcome/dataroom-trial.tsx@@ -33,6 +33,7 @@ export default function DataroomTrial() {const [useCase, setUseCase] = useState<string>("");const [customUseCase, setCustomUseCase] = useState<string>("");+ const [dealSize, setDealSize] = useState<string>("");const [companySize, setCompanySize] = useState<string>("");const [name, setName] = useState<string>("");const [companyName, setCompanyName] = useState<string>("");@@ -40,6 +41,22 @@ export default function DataroomTrial() {const [loading, setLoading] = useState<boolean>(false);+ // Map use case to deal type for survey+ const useCaseToDealType: Record<string, string> = {+ "mergers-and-acquisitions": "mergers-acquisitions",+ "startup-fundraising": "startup-fundraising",+ "fund-management": "fund-management",+ sales: "sales",+ "project-management": "project-management",+ operations: "financial-operations",+ "real-estate": "real-estate",+ };++ // Check if use case needs deal size question+ const needsDealSize =+ useCase &&+ useCase !== "project-management";+// Helper function to convert use case to proper dataroom nameconst getDataroomName = (useCaseValue: string, customValue: string = "") => {if (useCaseValue === "other" && customValue) {@@ -47,12 +64,13 @@ export default function DataroomTrial() {}const useCaseNames: Record<string, string> = {- "mergers-and-acquisitions": "Mergers and Acquisitions Data Room",+ "mergers-and-acquisitions": "Mergers & Acquisitions Data Room","startup-fundraising": "Startup Fundraising Data Room",- "fund-management": "Fund Management & Fundraising Data Room",+ "fund-management": "Fund Management Data Room",sales: "Sales Data Room","project-management": "Project Management Data Room",- operations: "Operations Data Room",+ operations: "Financial Operations Data Room",+ "real-estate": "Real Estate Data Room",};return useCaseNames[useCaseValue] || "Data Room";@@ -67,11 +85,31 @@ export default function DataroomTrial() {return;}+ // Check if deal size is required but not filled+ if (needsDealSize && !dealSize) {+ toast.error("Please select a deal size.");+ return;+ }+setLoading(true);const dataroomName = getDataroomName(useCase, customUseCase.trim());try {+ // Save survey data to team+ const dealType = useCase === "other" ? "other" : useCaseToDealType[useCase];+ if (dealType) {+ await fetch(`/api/teams/${teamInfo?.currentTeam?.id}/survey`, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ dealType,+ dealTypeOther: useCase === "other" ? customUseCase.trim() : null,+ dealSize: dealSize || null,+ }),+ });+ }+const response = await fetch(`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/trial`,{@@ -107,6 +145,7 @@ export default function DataroomTrial() {dataroomName: dataroomName,useCase: useCase === "other" ? customUseCase.trim() : useCase,companySize,+ dealSize,dataroomId,});toast.success("Dataroom successfully created! 🎉");@@ -250,6 +289,8 @@ export default function DataroomTrial() {if (value !== "other") {setCustomUseCase("");}+ // Reset deal size when use case changes+ setDealSize("");}}><SelectTrigger>@@ -257,19 +298,20 @@ export default function DataroomTrial() {</SelectTrigger><SelectContent><SelectItem value="mergers-and-acquisitions">- Mergers and Acquisitions+ Mergers & Acquisitions</SelectItem><SelectItem value="startup-fundraising">Startup Fundraising</SelectItem><SelectItem value="fund-management">- Fund management & Fundraising+ Fund Management</SelectItem><SelectItem value="sales">Sales</SelectItem><SelectItem value="project-management">- Project management+ Project Management</SelectItem>- <SelectItem value="operations">Operations</SelectItem>+ <SelectItem value="operations">Financial Operations</SelectItem>+ <SelectItem value="real-estate">Real Estate</SelectItem><SelectItem value="other">Other</SelectItem></SelectContent>@@ -285,6 +327,29 @@ export default function DataroomTrial() {)}</div>+ {/* Deal Size - shown after use case is selected (except project-management and operations) */}+ {needsDealSize && (+ <div className="space-y-1">+ <Label className="opacity-80">+ {useCase === "startup-fundraising" || useCase === "fund-management"+ ? "How much are you raising?*"+ : "What's the deal size?*"}+ </Label>+ <Select onValueChange={(value) => setDealSize(value)}>+ <SelectTrigger>+ <SelectValue placeholder="Select deal size" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value="0-500k">$0 - $500K</SelectItem>+ <SelectItem value="500k-5m">$500K - $5M</SelectItem>+ <SelectItem value="5m-10m">$5M - $10M</SelectItem>+ <SelectItem value="10m-100m">$10M - $100M</SelectItem>+ <SelectItem value="100m+">$100M+</SelectItem>+ </SelectContent>+ </Select>+ </div>+ )}+<div className="space-y-1"><Label htmlFor="tools" className="opacity-80">Tools*@@ -318,7 +383,8 @@ export default function DataroomTrial() {!useCase ||!name ||!companyName ||- (useCase === "other" && !customUseCase.trim())+ (useCase === "other" && !customUseCase.trim()) ||+ (needsDealSize && !dealSize)}loading={loading}>diff --git a/components/welcome/select.tsx b/components/welcome/select.tsxindex 110f16e8..1e8087d7 100644--- a/components/welcome/select.tsx+++ b/components/welcome/select.tsx@@ -1,5 +1,8 @@import { useRouter } from "next/router";+import { useState } from "react";++import { useTeam } from "@/context/team-context";import { FileChartPieIcon, FileIcon, PresentationIcon } from "lucide-react";import { motion } from "motion/react";@@ -7,8 +10,133 @@ import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";import NotionIcon from "@/components/shared/icons/files/notion";-export default function Next() {+const DEAL_TYPE_OPTIONS = [+ { value: "startup-fundraising", label: "Startup Fundraising" },+ { value: "fund-management", label: "Fund Management" },+ { value: "mergers-acquisitions", label: "Mergers & Acquisitions" },+ { value: "financial-operations", label: "Financial Operations" },+ { value: "real-estate", label: "Real Estate" },+ { value: "project-management", label: "Project Management" },+];++const DEAL_SIZE_OPTIONS = [+ { value: "0-500k", label: "$0-500K" },+ { value: "500k-5m", label: "$500K-5M" },+ { value: "5m-10m", label: "$5M-10M" },+ { value: "10m-100m", label: "$10-100M" },+ { value: "100m+", label: "$100M+" },+];++export default function Select() {const router = useRouter();+ const teamInfo = useTeam();+ const [selectedDoc, setSelectedDoc] = useState<string | null>(null);+ const [dealType, setDealType] = useState<string | null>(null);+ const [dealTypeOther, setDealTypeOther] = useState<string>("");+ const [showOtherInput, setShowOtherInput] = useState(false);+ const [dealSize, setDealSize] = useState<string | null>(null);+ const [isSubmitting, setIsSubmitting] = useState(false);++ // Determine which survey step to show based on document type+ const needsDealTypeQuestion =+ selectedDoc === "notion" || selectedDoc === "document";+ const needsDealSizeQuestion =+ selectedDoc === "pitchdeck" ||+ selectedDoc === "sales-document" ||+ (needsDealTypeQuestion && dealType && dealType !== "project-management");++ const showDealTypeOptions = needsDealTypeQuestion && !dealType && !showOtherInput;+ const showDealSizeOptions =+ needsDealSizeQuestion &&+ (dealType || !needsDealTypeQuestion) &&+ !showOtherInput;++ const handleDocSelect = (docType: string) => {+ setSelectedDoc(docType);+ setDealType(null);+ setDealTypeOther("");+ setShowOtherInput(false);+ setDealSize(null);++ // Auto-set deal type for specific document types+ if (docType === "pitchdeck") {+ setDealType("startup-fundraising");+ } else if (docType === "sales-document") {+ setDealType("sales");+ }+ };++ const handleDealTypeSelect = (value: string) => {+ setDealType(value);+ setShowOtherInput(false);+ if (value === "project-management") {+ // If project management, proceed immediately (no deal size needed)+ saveSurveyAndProceed(value, null, null);+ }+ };++ const handleOtherConfirm = () => {+ if (!dealTypeOther.trim()) return;+ setDealType("other");+ setShowOtherInput(false);+ // Show deal size question after confirming "Other"+ };++ const handleDealSizeSelect = (value: string) => {+ setDealSize(value);+ saveSurveyAndProceed(dealType, value, dealTypeOther || null);+ };++ const saveSurveyAndProceed = async (+ type: string | null,+ size: string | null,+ otherText: string | null,+ ) => {+ setIsSubmitting(true);++ // Save survey data if team exists+ if (teamInfo?.currentTeam?.id && type) {+ try {+ await fetch(`/api/teams/${teamInfo.currentTeam.id}/survey`, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ dealType: type,+ dealTypeOther: otherText,+ dealSize: size,+ }),+ });+ } catch (error) {+ console.error("Failed to save survey:", error);+ }+ }++ // Navigate to the appropriate upload page+ router.push({+ pathname: "/welcome",+ query: { type: selectedDoc },+ });+ };++ const getDealSizeQuestion = () => {+ if (+ selectedDoc === "pitchdeck" ||+ dealType === "startup-fundraising" ||+ dealType === "fund-management"+ ) {+ return "How much are you raising?";+ }+ if (+ dealType === "mergers-acquisitions" ||+ dealType === "real-estate" ||+ dealType === "financial-operations" ||+ dealType === "other"+ ) {+ return "What's the deal size?";+ }+ return "What's the typical deal size?";+ };+return (<motion.divclassName="z-10 mx-5 flex flex-col items-center space-y-10 text-center sm:mx-auto"@@ -38,88 +166,156 @@ export default function Next() {Which document do you want to share today?</h1></motion.div>+<motion.divvariants={STAGGER_CHILD_VARIANTS}className="grid w-full grid-cols-1 divide-y divide-border rounded-md border border-border text-foreground md:grid-cols-4 md:divide-x"><button- onClick={() =>- router.push({- pathname: "/welcome",- query: {- type: "pitchdeck",- },- })- }- className="flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10"+ onClick={() => handleDocSelect("pitchdeck")}+ className={`flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors md:p-10 ${+ selectedDoc === "pitchdeck"+ ? "bg-primary/5 ring-2 ring-inset ring-primary"+ : "hover:bg-gray-200 hover:dark:bg-gray-800"+ }`}><PresentationIcon className="pointer-events-none h-auto w-12 sm:w-12" /><p>Pitchdeck</p></button><button- onClick={() =>- router.push({- pathname: "/welcome",- query: {- type: "sales-document",- },- })- }- className="flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10"+ onClick={() => handleDocSelect("sales-document")}+ className={`flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors md:p-10 ${+ selectedDoc === "sales-document"+ ? "bg-primary/5 ring-2 ring-inset ring-primary"+ : "hover:bg-gray-200 hover:dark:bg-gray-800"+ }`}><FileChartPieIcon className="pointer-events-none h-auto w-12 sm:w-12" /><p>Sales document</p></button><button- onClick={() =>- router.push({- pathname: "/welcome",- query: {- type: "notion",- },- })- }- className="flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10"+ onClick={() => handleDocSelect("notion")}+ className={`flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors md:p-10 ${+ selectedDoc === "notion"+ ? "bg-primary/5 ring-2 ring-inset ring-primary"+ : "hover:bg-gray-200 hover:dark:bg-gray-800"+ }`}><NotionIcon className="pointer-events-none h-auto w-12 sm:w-12" /><p>Notion Page</p></button>+<button- onClick={() =>- router.push({- pathname: "/welcome",- query: {- type: "document",- },- })- }- className="flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10"+ onClick={() => handleDocSelect("document")}+ className={`flex min-h-[200px] flex-col items-center justify-center space-y-5 overflow-hidden p-5 transition-colors md:p-10 ${+ selectedDoc === "document"+ ? "bg-primary/5 ring-2 ring-inset ring-primary"+ : "hover:bg-gray-200 hover:dark:bg-gray-800"+ }`}><FileIcon className="pointer-events-none h-auto w-12 sm:w-12" /><p>Another document</p></button></motion.div>- <motion.div- variants={STAGGER_CHILD_VARIANTS}- className="text-center text-sm text-muted-foreground"- >- {/* <button- className="text-center text-sm text-muted-foreground underline-offset-4 transition-all hover:text-gray-800 hover:underline hover:dark:text-muted-foreground/80"- onClick={() =>- router.push({- pathname: "/welcome",- query: {- type: "dataroom",- },- })- }- > */}- {/* You can start by sharing documents and create a data room later. */}- {/* </button> */}- </motion.div>+ {/* Inline Survey Questions */}+ {selectedDoc && (+ <motion.div+ initial={{ opacity: 0, y: 10 }}+ animate={{ opacity: 1, y: 0 }}+ className="w-full max-w-xl space-y-4"+ >+ {/* Deal Type Question (for notion/document) */}+ {showDealTypeOptions && (+ <div className="space-y-3">+ <p className="text-sm font-medium text-muted-foreground">+ What do you use Papermark for?+ </p>+ <div className="flex flex-wrap justify-center gap-2">+ {DEAL_TYPE_OPTIONS.map((option) => (+ <button+ key={option.value}+ onClick={() => handleDealTypeSelect(option.value)}+ disabled={isSubmitting}+ className="rounded-full border border-border px-4 py-2 text-sm transition-all hover:border-primary hover:bg-primary/5"+ >+ {option.label}+ </button>+ ))}+ <button+ onClick={() => setShowOtherInput(true)}+ disabled={isSubmitting}+ className="rounded-full border border-border px-4 py-2 text-sm transition-all hover:border-primary hover:bg-primary/5"+ >+ Other+ </button>+ </div>+ </div>+ )}++ {/* Other Input Field - inline */}+ {showOtherInput && !dealType && (+ <div className="space-y-3">+ <p className="text-sm font-medium text-muted-foreground">+ What do you use Papermark for?+ </p>+ <div className="flex items-center justify-center gap-2">+ <input+ type="text"+ value={dealTypeOther}+ onChange={(e) => setDealTypeOther(e.target.value)}+ placeholder="Please specify..."+ className="max-w-xs rounded-full border border-border bg-background px-4 py-2 text-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary"+ autoFocus+ onKeyDown={(e) => {+ if (e.key === "Enter" && dealTypeOther.trim()) {+ handleOtherConfirm();+ }+ }}+ />+ <button+ onClick={handleOtherConfirm}+ disabled={!dealTypeOther.trim() || isSubmitting}+ className="rounded-full border border-primary bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-all hover:bg-primary/90 disabled:opacity-50"+ >+ →+ </button>+ </div>+ </div>+ )}++ {/* Deal Size Question */}+ {showDealSizeOptions && !showDealTypeOptions && (+ <div className="space-y-3">+ <p className="text-sm font-medium text-muted-foreground">+ {getDealSizeQuestion()}+ </p>+ <div className="flex flex-wrap justify-center gap-2">+ {DEAL_SIZE_OPTIONS.map((option) => (+ <button+ key={option.value}+ onClick={() => handleDealSizeSelect(option.value)}+ disabled={isSubmitting}+ className="rounded-full border border-border px-4 py-2 text-sm transition-all hover:border-primary hover:bg-primary/5"+ >+ {option.label}+ </button>+ ))}+ </div>+ </div>+ )}++ {/* Skip option */}+ <button+ onClick={() => saveSurveyAndProceed(dealType, null, dealTypeOther || null)}+ className="text-xs text-muted-foreground underline-offset-4 hover:underline"+ >+ Skip+ </button>+ </motion.div>+ )}</motion.div>);}diff --git a/pages/_app.tsx b/pages/_app.tsxindex 0256090b..3a71e952 100644--- a/pages/_app.tsx+++ b/pages/_app.tsx@@ -10,6 +10,7 @@ import { NuqsAdapter } from "nuqs/adapters/next/pages";import { EXCLUDED_PATHS } from "@/lib/constants";import { PostHogCustomProvider } from "@/components/providers/posthog-provider";+import { DealflowPopup } from "@/components/shared/dealflow-popup";import { ThemeProvider } from "@/components/theme-provider";import { Toaster } from "@/components/ui/sonner";import { TooltipProvider } from "@/components/ui/tooltip";@@ -82,6 +83,7 @@ export default function App({) : (<TeamProvider><Component {...pageProps} />+ <DealflowPopup /></TeamProvider>)}</TooltipProvider>diff --git a/pages/api/teams/[teamId]/survey.ts b/pages/api/teams/[teamId]/survey.tsnew file mode 100644index 00000000..329c347c--- /dev/null+++ b/pages/api/teams/[teamId]/survey.ts@@ -0,0 +1,127 @@+import { NextApiRequest, NextApiResponse } from "next";++import { authOptions } from "@/pages/api/auth/[...nextauth]";+import { getServerSession } from "next-auth/next";+import { z } from "zod";++import { errorhandler } from "@/lib/errorHandler";+import prisma from "@/lib/prisma";+import { getTeamWithUsersAndDocument } from "@/lib/team/helper";+import { CustomUser } from "@/lib/types";++// Zod schema for survey data - flexible for future options+const surveyDataSchema = z.object({+ dealType: z+ .enum([+ "startup-fundraising",+ "fund-management",+ "mergers-acquisitions",+ "project-management",+ "sales",+ "financial-operations",+ "real-estate",+ "other",+ ])+ .optional()+ .nullable(),+ dealTypeOther: z.string().max(200).optional().nullable(), // Custom text when "other" is selected+ dealSize: z+ .enum(["0-500k", "500k-5m", "5m-10m", "10m-100m", "100m+"])+ .optional()+ .nullable(),+});++export type SurveyData = z.infer<typeof surveyDataSchema>;++export default async function handler(+ req: NextApiRequest,+ res: NextApiResponse,+) {+ const session = await getServerSession(req, res, authOptions);++ if (!session) {+ return res.status(401).json({ error: "Unauthorized" });+ }++ const { teamId } = req.query as { teamId: string };+ const userId = (session.user as CustomUser).id;++ try {+ await getTeamWithUsersAndDocument({+ teamId,+ visitorId: undefined,+ userId,+ options: {},+ });+ } catch (error) {+ return res.status(403).json({ error: "Forbidden" });+ }++ if (req.method === "GET") {+ try {+ const team = await prisma.team.findUnique({+ where: { id: teamId },+ select: { surveyData: true },+ });++ const surveyData = (team?.surveyData as SurveyData) || {};++ return res.status(200).json({+ dealType: surveyData.dealType || null,+ dealTypeOther: surveyData.dealTypeOther || null,+ dealSize: surveyData.dealSize || null,+ });+ } catch (error) {+ errorhandler(error, res);+ }+ }++ if (req.method === "POST") {+ try {+ const { dealType, dealTypeOther, dealSize } = req.body;++ // Validate with Zod+ const validationResult = surveyDataSchema.safeParse({+ dealType,+ dealTypeOther,+ dealSize,+ });++ if (!validationResult.success) {+ return res.status(400).json({+ error: "Invalid survey data",+ details: validationResult.error.errors,+ });+ }++ // Get current survey data to merge with new data+ const team = await prisma.team.findUnique({+ where: { id: teamId },+ select: { surveyData: true },+ });++ const currentSurveyData = (team?.surveyData as SurveyData) || {};++ // Merge new data with existing data+ const updatedSurveyData: SurveyData = {+ ...currentSurveyData,+ ...(dealType !== undefined && { dealType }),+ ...(dealTypeOther !== undefined && { dealTypeOther }),+ ...(dealSize !== undefined && { dealSize }),+ };++ await prisma.team.update({+ where: { id: teamId },+ data: {+ surveyData: updatedSurveyData,+ },+ });++ return res.status(200).json({ success: true });+ } catch (error) {+ errorhandler(error, res);+ }+ }++ return res.status(405).json({ error: "Method not allowed" });+}diff --git a/pages/settings/general.tsx b/pages/settings/general.tsxindex a1f729f2..10641ff8 100644--- a/pages/settings/general.tsx+++ b/pages/settings/general.tsx@@ -16,6 +16,7 @@ import DeleteTeam from "@/components/settings/delete-team";import GlobalBlockListForm from "@/components/settings/global-block-list-form";import IgnoredDomainsForm from "@/components/settings/ignored-domains-form";import { SettingsHeader } from "@/components/settings/settings-header";+import { SurveySettings } from "@/components/settings/survey-settings";import { TimezoneSelector } from "@/components/settings/timezone-selector";import { Form } from "@/components/ui/form";@@ -225,6 +226,7 @@ export default function General() {<TimezoneSelector /><IgnoredDomainsForm /><GlobalBlockListForm />+ <SurveySettings /><DeleteTeam /></div>diff --git a/prisma/schema/team.prisma b/prisma/schema/team.prismaindex 1f59f670..3790cc9e 100644--- a/prisma/schema/team.prisma+++ b/prisma/schema/team.prisma@@ -47,6 +47,9 @@ model Team {replicateDataroomFolders Boolean @default(true) // Replicate dataroom folder structure in "All Documents"timezone String @default("Etc/UTC") // Team-wide timezone for analytics display (IANA timezone identifier)+ // Survey data (stored as JSON for flexibility)+ surveyData Json? // { dealType?: string, dealSize?: string, ... }+// AI agentsagentsEnabled Boolean @default(false) // Enable AI agents for the teamvectorStoreId String? // OpenAI vector store ID for team-level document search