Skip to content

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

feat: add in-document link explainer on free accounts

Marc Seitz0e82b373fba9
diff --git a/components/documents/document-header.tsx b/components/documents/document-header.tsx
index 93f848fd..06a026cd 100644
--- a/components/documents/document-header.tsx
+++ b/components/documents/document-header.tsx
@@ -5,6 +5,7 @@ import { useEffect, useRef, useState } from "react";
import { useTeam } from "@/context/team-context";
import { Document, DocumentVersion } from "@prisma/client";
import {
+ AlertCircleIcon,
BetweenHorizontalStartIcon,
FileDownIcon,
SheetIcon,
@@ -40,6 +41,7 @@ import PlanBadge from "../billing/plan-badge";
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
import AdvancedSheet from "../shared/icons/advanced-sheet";
import PortraitLandscape from "../shared/icons/portrait-landscape";
+import { Alert, AlertClose, AlertDescription, AlertTitle } from "../ui/alert";
import LoadingSpinner from "../ui/loading-spinner";
import { ButtonTooltip } from "../ui/tooltip";
import { AddDocumentModal } from "./add-document-modal";
@@ -51,7 +53,7 @@ export default function DocumentHeader({
teamId,
actions,
}: {
- prismaDocument: Document;
+ prismaDocument: Document & { hasPageLinks: boolean };
primaryVersion: DocumentVersion;
teamId: string;
actions?: React.ReactNode[];
@@ -71,6 +73,7 @@ export default function DocumentHeader({
const [addDocumentVersion, setAddDocumentVersion] = useState<boolean>(false);
const [openAddDocModal, setOpenAddDocModal] = useState<boolean>(false);
const [planModalOpen, setPlanModalOpen] = useState<boolean>(false);
+ const [planModalTrigger, setPlanModalTrigger] = useState<string>("");
const nameRef = useRef<HTMLHeadingElement>(null);
const enterPressedRef = useRef<boolean>(false);
const dropdownRef = useRef<HTMLDivElement | null>(null);
@@ -417,239 +420,273 @@ export default function DocumentHeader({
};
return (
- <header className="flex items-center justify-between gap-x-8">
- <div className="flex items-center space-x-2">
- {fileIcon({
- fileType: prismaDocument.type ?? "",
- className: "size-7 sm:size-8",
- isLight,
- })}
-
- <div className="mt-1 flex flex-col lg:mt-0">
- <h2
- className="rounded-md border border-transparent px-1 py-0.5 text-lg font-semibold tracking-tight text-foreground duration-200 hover:cursor-text hover:border hover:border-border focus-visible:text-lg lg:px-3 lg:py-1 lg:text-xl lg:focus-visible:text-xl xl:text-2xl"
- ref={nameRef}
- contentEditable={true}
- onFocus={() => setIsEditingName(true)}
- onBlur={handleNameSubmit}
- onKeyDown={preventEnterAndSubmit}
- title="Click to edit"
- dangerouslySetInnerHTML={{ __html: prismaDocument.name }}
- />
- {isEditingName && (
- <span className="mt-1 text-xs text-muted-foreground">
- {`Press <Enter> to save the name.`}
- </span>
- )}
+ <header className="flex flex-col gap-y-4">
+ <div className="flex items-center justify-between gap-x-8">
+ <div className="flex items-center space-x-2">
+ {fileIcon({
+ fileType: prismaDocument.type ?? "",
+ className: "size-7 sm:size-8",
+ isLight,
+ })}
+
+ <div className="mt-1 flex flex-col lg:mt-0">
+ <h2
+ className="rounded-md border border-transparent px-1 py-0.5 text-lg font-semibold tracking-tight text-foreground duration-200 hover:cursor-text hover:border hover:border-border focus-visible:text-lg lg:px-3 lg:py-1 lg:text-xl lg:focus-visible:text-xl xl:text-2xl"
+ ref={nameRef}
+ contentEditable={true}
+ onFocus={() => setIsEditingName(true)}
+ onBlur={handleNameSubmit}
+ onKeyDown={preventEnterAndSubmit}
+ title="Click to edit"
+ dangerouslySetInnerHTML={{ __html: prismaDocument.name }}
+ />
+ {isEditingName && (
+ <span className="mt-1 text-xs text-muted-foreground">
+ {`Press <Enter> to save the name.`}
+ </span>
+ )}
+ </div>
+
+ {prismaDocument.type === "sheet" &&
+ prismaDocument.advancedExcelEnabled && (
+ <ButtonTooltip content="Advanced Excel mode">
+ <span className="mt-1 text-xs">
+ <AdvancedSheet className="h-6 w-6" />
+ </span>
+ </ButtonTooltip>
+ )}
</div>
- {prismaDocument.type === "sheet" &&
- prismaDocument.advancedExcelEnabled && (
- <ButtonTooltip content="Advanced Excel mode">
- <span className="mt-1 text-xs">
- <AdvancedSheet className="h-6 w-6" />
- </span>
+ <div className="flex items-center gap-x-4 md:gap-x-2">
+ {!orientationLoading ? (
+ <ButtonTooltip content="Change orientation">
+ <Button
+ variant="ghost"
+ size="icon"
+ className="hidden md:flex"
+ onClick={changeDocumentOrientation}
+ title={`Change document orientation to ${primaryVersion.isVertical ? "landscape" : "portrait"}`}
+ >
+ <PortraitLandscape
+ className={cn(
+ "h-6 w-6",
+ !primaryVersion.isVertical && "-rotate-90 transform",
+ )}
+ />
+ </Button>
</ButtonTooltip>
+ ) : (
+ <div className="hidden md:flex">
+ <LoadingSpinner className="h-6 w-6" />
+ </div>
)}
- </div>
- <div className="flex items-center gap-x-4 md:gap-x-2">
- {!orientationLoading ? (
- <ButtonTooltip content="Change orientation">
- <Button
- variant="ghost"
- size="icon"
- className="hidden md:flex"
- onClick={changeDocumentOrientation}
- title={`Change document orientation to ${primaryVersion.isVertical ? "landscape" : "portrait"}`}
+ {primaryVersion.type !== "notion" && (
+ <AddDocumentModal
+ newVersion
+ openModal={openAddDocModal}
+ setAddDocumentModalOpen={setOpenAddDocModal}
>
- <PortraitLandscape
- className={cn(
- "h-6 w-6",
- !primaryVersion.isVertical && "-rotate-90 transform",
- )}
- />
- </Button>
- </ButtonTooltip>
- ) : (
- <div className="hidden md:flex">
- <LoadingSpinner className="h-6 w-6" />
- </div>
- )}
-
- {primaryVersion.type !== "notion" && (
- <AddDocumentModal
- newVersion
- openModal={openAddDocModal}
- setAddDocumentModalOpen={setOpenAddDocModal}
- >
- {/* <ButtonTooltip
+ {/* <ButtonTooltip
content="Upload a new version"
link="https://www.papermark.io/help/article/document-versions"
> */}
- <Button
- variant="ghost"
- size="icon"
- onClick={(e) => {
- e.stopPropagation();
- setOpenAddDocModal(true);
- }}
- className="hidden md:flex"
- >
- <FileUp className="h-6 w-6" />
- </Button>
- {/* </ButtonTooltip> */}
- </AddDocumentModal>
- )}
-
- {prismaDocument.type !== "notion" &&
- prismaDocument.type !== "sheet" &&
- prismaDocument.assistantEnabled && (
- <Button
- className="group hidden h-8 space-x-1 whitespace-nowrap bg-gradient-to-r from-[#16222A] via-emerald-500 to-[#16222A] text-xs duration-200 ease-linear hover:bg-right md:flex lg:h-9 lg:text-sm"
- variant={"special"}
- size={"icon"}
- style={{ backgroundSize: "200% auto" }}
- onClick={() => activateOrRedirectAssistant(prismaDocument)}
- title="Open AI Assistant"
- >
- <PapermarkSparkle className="h-5 w-5" />
- </Button>
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={(e) => {
+ e.stopPropagation();
+ setOpenAddDocModal(true);
+ }}
+ className="hidden md:flex"
+ >
+ <FileUp className="h-6 w-6" />
+ </Button>
+ {/* </ButtonTooltip> */}
+ </AddDocumentModal>
)}
- <div className="flex items-center gap-x-1">
- {actionRows.map((row, i) => (
- <ul
- key={i.toString()}
- className="flex flex-wrap items-center justify-end gap-2 md:flex-nowrap md:gap-4"
- >
- {row.map((action, i) => (
- <li key={i}>{action}</li>
- ))}
- </ul>
- ))}
- </div>
+ {prismaDocument.type !== "notion" &&
+ prismaDocument.type !== "sheet" &&
+ prismaDocument.assistantEnabled && (
+ <Button
+ className="group hidden h-8 space-x-1 whitespace-nowrap bg-gradient-to-r from-[#16222A] via-emerald-500 to-[#16222A] text-xs duration-200 ease-linear hover:bg-right md:flex lg:h-9 lg:text-sm"
+ variant={"special"}
+ size={"icon"}
+ style={{ backgroundSize: "200% auto" }}
+ onClick={() => activateOrRedirectAssistant(prismaDocument)}
+ title="Open AI Assistant"
+ >
+ <PapermarkSparkle className="h-5 w-5" />
+ </Button>
+ )}
- <DropdownMenu open={menuOpen} onOpenChange={handleMenuStateChange}>
- <DropdownMenuTrigger asChild>
- <Button
- variant="outline"
- className="h-8 w-8 bg-transparent p-0 lg:h-9 lg:w-9"
+ <div className="flex items-center gap-x-1">
+ {actionRows.map((row, i) => (
+ <ul
+ key={i.toString()}
+ className="flex flex-wrap items-center justify-end gap-2 md:flex-nowrap md:gap-4"
+ >
+ {row.map((action, i) => (
+ <li key={i}>{action}</li>
+ ))}
+ </ul>
+ ))}
+ </div>
+
+ <DropdownMenu open={menuOpen} onOpenChange={handleMenuStateChange}>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="outline"
+ className="h-8 w-8 bg-transparent p-0 lg:h-9 lg:w-9"
+ >
+ <span className="sr-only">Open menu</span>
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent
+ align="end"
+ className="w-[240px]"
+ ref={dropdownRef}
>
- <span className="sr-only">Open menu</span>
- <MoreVertical className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent
- align="end"
- className="w-[240px]"
- ref={dropdownRef}
- >
- <DropdownMenuLabel>Actions</DropdownMenuLabel>
- <DropdownMenuGroup className="block md:hidden">
- <DropdownMenuItem>
- <AddDocumentModal
- newVersion
- setAddDocumentModalOpen={setAddDocumentVersion}
- >
- <button
- title="Add a new version"
- className="flex items-center"
- onClick={(e) => {
- e.stopPropagation();
- setAddDocumentVersion(true);
- }}
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ <DropdownMenuGroup className="block md:hidden">
+ <DropdownMenuItem>
+ <AddDocumentModal
+ newVersion
+ setAddDocumentModalOpen={setAddDocumentVersion}
>
- <FileUp className="mr-2 h-4 w-4" /> Add new version
- </button>
- </AddDocumentModal>
- </DropdownMenuItem>
+ <button
+ title="Add a new version"
+ className="flex items-center"
+ onClick={(e) => {
+ e.stopPropagation();
+ setAddDocumentVersion(true);
+ }}
+ >
+ <FileUp className="mr-2 h-4 w-4" /> Add new version
+ </button>
+ </AddDocumentModal>
+ </DropdownMenuItem>
- <DropdownMenuItem onClick={() => changeDocumentOrientation()}>
- <PortraitLandscape
- className={cn(
- "mr-2 h-4 w-4",
- !primaryVersion.isVertical && "-rotate-90 transform",
+ <DropdownMenuItem onClick={() => changeDocumentOrientation()}>
+ <PortraitLandscape
+ className={cn(
+ "mr-2 h-4 w-4",
+ !primaryVersion.isVertical && "-rotate-90 transform",
+ )}
+ />
+ {" Change orientation"}
+ </DropdownMenuItem>
+
+ {prismaDocument.type !== "notion" &&
+ prismaDocument.type !== "sheet" && (
+ <DropdownMenuItem
+ onClick={() =>
+ activateOrRedirectAssistant(prismaDocument)
+ }
+ >
+ <PapermarkSparkle className="mr-2 h-4 w-4" />
+ Open AI Assistant
+ </DropdownMenuItem>
)}
- />
- {" Change orientation"}
- </DropdownMenuItem>
- {prismaDocument.type !== "notion" &&
- prismaDocument.type !== "sheet" && (
+ <DropdownMenuSeparator />
+ </DropdownMenuGroup>
+ {primaryVersion.type !== "notion" &&
+ primaryVersion.type !== "sheet" &&
+ (!prismaDocument.assistantEnabled ? (
<DropdownMenuItem
- onClick={() => activateOrRedirectAssistant(prismaDocument)}
+ onClick={() =>
+ activateOrDeactivateAssistant(true, prismaDocument.id)
+ }
>
- <PapermarkSparkle className="mr-2 h-4 w-4" />
- Open AI Assistant
+ <Sparkles className="mr-2 h-4 w-4" /> Activate Assistant
+ </DropdownMenuItem>
+ ) : (
+ <DropdownMenuItem
+ onClick={() =>
+ activateOrDeactivateAssistant(false, prismaDocument.id)
+ }
+ >
+ <Sparkles className="mr-2 h-4 w-4" /> Disable Assistant
+ </DropdownMenuItem>
+ ))}
+ {prismaDocument.type === "sheet" &&
+ !prismaDocument.advancedExcelEnabled &&
+ (plan === "business" || plan === "datarooms" || isTrial) && (
+ <DropdownMenuItem
+ onClick={() => enableAdvancedExcel(prismaDocument)}
+ >
+ <SheetIcon className="mr-2 h-4 w-4" />
+ Enable Advanced Mode
</DropdownMenuItem>
)}
-
- <DropdownMenuSeparator />
- </DropdownMenuGroup>
- {primaryVersion.type !== "notion" &&
- primaryVersion.type !== "sheet" &&
- (!prismaDocument.assistantEnabled ? (
- <DropdownMenuItem
- onClick={() =>
- activateOrDeactivateAssistant(true, prismaDocument.id)
- }
- >
- <Sparkles className="mr-2 h-4 w-4" /> Activate Assistant
- </DropdownMenuItem>
- ) : (
- <DropdownMenuItem
- onClick={() =>
- activateOrDeactivateAssistant(false, prismaDocument.id)
- }
- >
- <Sparkles className="mr-2 h-4 w-4" /> Disable Assistant
- </DropdownMenuItem>
- ))}
- {prismaDocument.type === "sheet" &&
- !prismaDocument.advancedExcelEnabled &&
- (plan === "business" || plan === "datarooms" || isTrial) && (
- <DropdownMenuItem
- onClick={() => enableAdvancedExcel(prismaDocument)}
- >
- <SheetIcon className="mr-2 h-4 w-4" />
- Enable Advanced Mode
+ {datarooms && datarooms.length !== 0 && (
+ <DropdownMenuItem onClick={() => setAddDataRoomOpen(true)}>
+ <BetweenHorizontalStartIcon className="mr-2 h-4 w-4" />
+ Add to dataroom
</DropdownMenuItem>
)}
- {datarooms && datarooms.length !== 0 && (
- <DropdownMenuItem onClick={() => setAddDataRoomOpen(true)}>
- <BetweenHorizontalStartIcon className="mr-2 h-4 w-4" />
- Add to dataroom
+ <DropdownMenuSeparator />
+
+ {/* Export views in CSV */}
+ <DropdownMenuItem
+ onClick={() =>
+ isFree
+ ? (setPlanModalTrigger("export-document-visits"),
+ setPlanModalOpen(true))
+ : exportVisitCounts(prismaDocument)
+ }
+ >
+ <FileDownIcon className="mr-2 h-4 w-4" />
+ Export visits{" "}
+ {isFree && <PlanBadge className="ml-2" plan="pro" />}
</DropdownMenuItem>
- )}
- <DropdownMenuSeparator />
-
- {/* Export views in CSV */}
- <DropdownMenuItem
- onClick={() =>
- isFree
- ? setPlanModalOpen(true)
- : exportVisitCounts(prismaDocument)
- }
- >
- <FileDownIcon className="mr-2 h-4 w-4" />
- Export visits{" "}
- {isFree && <PlanBadge className="ml-2" plan="pro" />}
- </DropdownMenuItem>
- <DropdownMenuSeparator />
+ <DropdownMenuSeparator />
- <DropdownMenuItem
- className="text-destructive focus:bg-destructive focus:text-destructive-foreground"
- onClick={(event) => handleButtonClick(event, prismaDocument.id)}
- >
- <TrashIcon className="mr-2 h-4 w-4" />
- {isFirstClick ? "Really delete?" : "Delete document"}
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ <DropdownMenuItem
+ className="text-destructive focus:bg-destructive focus:text-destructive-foreground"
+ onClick={(event) => handleButtonClick(event, prismaDocument.id)}
+ >
+ <TrashIcon className="mr-2 h-4 w-4" />
+ {isFirstClick ? "Really delete?" : "Delete document"}
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
</div>
+ {isFree && prismaDocument.hasPageLinks ? (
+ <Alert id="in-document-links-alert" variant="destructive">
+ <AlertCircleIcon className="h-4 w-4" />
+ <AlertTitle>In-document links detected</AlertTitle>
+ <AlertDescription>
+ External in-document links are not available on the free plan.
+ Upgrade to a{" "}
+ <span
+ className="cursor-pointer underline underline-offset-4 hover:text-destructive/80"
+ onClick={() => {
+ setPlanModalTrigger("in-document-links");
+ setPlanModalOpen(true);
+ }}
+ >
+ higher plan
+ </span>{" "}
+ to use this feature.
+ </AlertDescription>
+ <AlertClose
+ onClick={() => {
+ const alert = document.getElementById("in-document-links-alert");
+ if (alert) {
+ alert.style.display = "none";
+ }
+ }}
+ />
+ </Alert>
+ ) : null}
+
{addDataRoomOpen ? (
<AddToDataroomModal
open={addDataRoomOpen}
@@ -662,7 +699,7 @@ export default function DocumentHeader({
{planModalOpen ? (
<UpgradePlanModal
clickedPlan="Pro"
- trigger="export-document-visits"
+ trigger={planModalTrigger}
open={planModalOpen}
setOpen={setPlanModalOpen}
/>
diff --git a/components/ui/alert.tsx b/components/ui/alert.tsx
new file mode 100644
index 00000000..8f471e7d
--- /dev/null
+++ b/components/ui/alert.tsx
@@ -0,0 +1,81 @@
+import * as React from "react";
+
+import { type VariantProps, cva } from "class-variance-authority";
+import { X } from "lucide-react";
+
+import { cn } from "@/lib/utils";
+
+import { Button } from "./button";
+
+const alertVariants = cva(
+ "relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",
+ {
+ variants: {
+ variant: {
+ default: "bg-background text-foreground",
+ destructive:
+ "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ },
+ },
+);
+
+const Alert = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
+>(({ className, variant, ...props }, ref) => (
+ <div
+ ref={ref}
+ role="alert"
+ className={cn(alertVariants({ variant }), className)}
+ {...props}
+ />
+));
+Alert.displayName = "Alert";
+
+const AlertTitle = React.forwardRef<
+ HTMLParagraphElement,
+ React.HTMLAttributes<HTMLHeadingElement>
+>(({ className, ...props }, ref) => (
+ <h5
+ ref={ref}
+ className={cn("mb-1 font-medium leading-none tracking-tight", className)}
+ {...props}
+ />
+));
+AlertTitle.displayName = "AlertTitle";
+
+const AlertDescription = React.forwardRef<
+ HTMLParagraphElement,
+ React.HTMLAttributes<HTMLParagraphElement>
+>(({ className, ...props }, ref) => (
+ <div
+ ref={ref}
+ className={cn("text-sm [&_p]:leading-relaxed", className)}
+ {...props}
+ />
+));
+AlertDescription.displayName = "AlertDescription";
+
+const AlertClose = React.forwardRef<
+ HTMLButtonElement,
+ React.ButtonHTMLAttributes<HTMLButtonElement>
+>(({ className, ...props }, ref) => (
+ <button
+ ref={ref}
+ className={cn(
+ "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",
+ className,
+ )}
+ {...props}
+ >
+ <X className="h-4 w-4" />
+ <span className="sr-only">Close</span>
+ </button>
+));
+AlertClose.displayName = "AlertClose";
+
+export { Alert, AlertTitle, AlertDescription, AlertClose };
diff --git a/pages/api/teams/[teamId]/documents/[id]/index.ts b/pages/api/teams/[teamId]/documents/[id]/index.ts
index 63c543a1..566f3fe6 100644
--- a/pages/api/teams/[teamId]/documents/[id]/index.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/index.ts
@@ -42,12 +42,32 @@ export default async function handle(
},
});
+ if (!document || !document.versions || document.versions.length === 0) {
+ return res.status(404).end("Document not found");
+ }
+
+ const pages = await prisma.documentPage.findMany({
+ where: {
+ versionId: document.versions[0].id,
+ },
+ select: {
+ pageLinks: true,
+ },
+ });
+
+ const hasPageLinks = pages.some(
+ (page) =>
+ page.pageLinks &&
+ Array.isArray(page.pageLinks) &&
+ (page.pageLinks as any[]).length > 0,
+ );
+
// Check that the user is owner of the document, otherwise return 401
// if (document.ownerId !== (session.user as CustomUser).id) {
// return res.status(401).end("Unauthorized to access this document");
// }
- return res.status(200).json(document);
+ return res.status(200).json({ ...document, hasPageLinks });
} catch (error) {
errorhandler(error, res);
}