Skip to content

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

feat: add notion indicator

Marc Seitz66bee4f63cf3
diff --git a/components/documents/document-header.tsx b/components/documents/document-header.tsx
index 5dcee722..d4cc7f4b 100644
--- a/components/documents/document-header.tsx
+++ b/components/documents/document-header.tsx
@@ -608,7 +608,7 @@ export default function DocumentHeader({
{actionRows.map((row, i) => (
<ul
key={i.toString()}
- className="flex flex-wrap items-center justify-end gap-x-4 md:flex-nowrap md:gap-x-2"
+ className="flex flex-wrap items-center justify-end gap-x-2 md:flex-nowrap md:gap-x-1"
>
{row.map((action, i) => (
<li key={i}>{action}</li>
diff --git a/components/documents/notion-accessibility-indicator.tsx b/components/documents/notion-accessibility-indicator.tsx
index 1958bc93..dccddc9c 100644
--- a/components/documents/notion-accessibility-indicator.tsx
+++ b/components/documents/notion-accessibility-indicator.tsx
@@ -1,11 +1,19 @@
import { useEffect, useState } from "react";
+import { useTeam } from "@/context/team-context";
import { DocumentVersion } from "@prisma/client";
-import { AlertCircle, CheckCircle, Edit, ExternalLink, RefreshCw } from "lucide-react";
+import {
+ AlertCircle,
+ CheckCircle,
+ CheckCircleIcon,
+ CircleCheckIcon,
+ CircleXIcon,
+ Edit,
+ ExternalLink,
+ RefreshCw,
+} from "lucide-react";
import { toast } from "sonner";
-import { useTeam } from "@/context/team-context";
-
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -19,6 +27,7 @@ import {
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import LoadingSpinner from "@/components/ui/loading-spinner";
+import { ButtonTooltip } from "@/components/ui/tooltip";
interface NotionAccessibilityIndicatorProps {
documentId: string;
@@ -42,7 +51,8 @@ export default function NotionAccessibilityIndicator({
const teamInfo = useTeam();
const [status, setStatus] = useState<AccessibilityStatus | null>(null);
const [isLoading, setIsLoading] = useState(false);
- const [isDialogOpen, setIsDialogOpen] = useState(false);
+ const [isMainDialogOpen, setIsMainDialogOpen] = useState(false);
+ const [isUrlDialogOpen, setIsUrlDialogOpen] = useState(false);
const [newUrl, setNewUrl] = useState("");
const [isUpdating, setIsUpdating] = useState(false);
@@ -60,7 +70,7 @@ export default function NotionAccessibilityIndicator({
`/api/teams/${teamInfo.currentTeam.id}/documents/${documentId}/check-notion-accessibility`,
);
const data = await response.json();
-
+
if (response.ok) {
setStatus(data);
} else {
@@ -94,7 +104,7 @@ export default function NotionAccessibilityIndicator({
if (response.ok) {
toast.success("Notion URL updated successfully");
- setIsDialogOpen(false);
+ setIsUrlDialogOpen(false);
setNewUrl("");
// Refresh accessibility status
await checkAccessibility();
@@ -128,132 +138,169 @@ export default function NotionAccessibilityIndicator({
if (isLoading) {
return <LoadingSpinner className="h-4 w-4" />;
}
-
+
if (status?.isAccessible) {
- return <CheckCircle className="h-4 w-4 text-green-500" />;
+ return (
+ <CircleCheckIcon className="h-4 w-4 rounded-full bg-green-500 text-white" />
+ );
} else {
- return <AlertCircle className="h-4 w-4 text-red-500" />;
+ return (
+ <CircleXIcon className="h-4 w-4 rounded-full bg-red-500 text-white" />
+ );
}
};
- const getStatusText = () => {
+ const getTooltipText = () => {
if (isLoading) {
return "Checking accessibility...";
}
-
- if (status?.isAccessible) {
- return "Publicly accessible";
- } else if (status?.error) {
- return "Unable to check";
- } else {
- return "Not publicly accessible";
- }
- };
- const getStatusColor = () => {
- if (isLoading) {
- return "text-gray-500";
- }
-
if (status?.isAccessible) {
- return "text-green-600";
+ return "Notion page is publicly accessible";
+ } else if (status?.error) {
+ return "Unable to check accessibility";
} else {
- return "text-red-600";
+ return "Notion page is not publicly accessible";
}
};
return (
- <div className="flex items-center gap-2 rounded-lg border bg-white p-3 shadow-sm">
- <div className="flex items-center gap-2">
- {getStatusIcon()}
- <span className={`text-sm font-medium ${getStatusColor()}`}>
- {getStatusText()}
- </span>
- </div>
-
- <div className="flex items-center gap-1 ml-auto">
- <Button
- variant="ghost"
- size="sm"
- onClick={checkAccessibility}
- disabled={isLoading}
- className="h-7 px-2"
- >
- <RefreshCw className={`h-3 w-3 ${isLoading ? "animate-spin" : ""}`} />
- </Button>
-
- {status?.url && (
- <Button
- variant="ghost"
- size="sm"
- onClick={openNotionPage}
- className="h-7 px-2"
- >
- <ExternalLink className="h-3 w-3" />
- </Button>
- )}
-
- <Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
+ <>
+ {/* Compact Icon Trigger */}
+ <Dialog open={isMainDialogOpen} onOpenChange={setIsMainDialogOpen}>
+ <ButtonTooltip content={getTooltipText()}>
<DialogTrigger asChild>
<Button
- variant="ghost"
- size="sm"
- className="h-7 px-2"
- onClick={() => setNewUrl(status?.url || "")}
+ variant="outline"
+ size="default"
+ className="h-8 w-8 p-0 lg:h-9 lg:w-9"
>
- <Edit className="h-3 w-3" />
+ {getStatusIcon()}
</Button>
</DialogTrigger>
- <DialogContent className="sm:max-w-md">
- <DialogHeader>
- <DialogTitle>Update Notion URL</DialogTitle>
- <DialogDescription>
- Change the URL of the Notion page for this document.
- </DialogDescription>
- </DialogHeader>
- <div className="grid gap-4 py-4">
- <div className="grid gap-2">
- <Label htmlFor="notion-url">Notion URL</Label>
- <Input
- id="notion-url"
- value={newUrl}
- onChange={(e) => setNewUrl(e.target.value)}
- placeholder="https://www.notion.so/your-page-url"
- className="w-full"
- />
+ </ButtonTooltip>
+
+ {/* Main Status Dialog */}
+ <DialogContent className="sm:max-w-lg">
+ <DialogHeader>
+ <DialogTitle>Notion Page Status</DialogTitle>
+ <DialogDescription>
+ Check and manage your Notion page accessibility.
+ </DialogDescription>
+ </DialogHeader>
+
+ <div className="space-y-4 py-4">
+ {/* Status Display */}
+ <div className="flex items-center gap-3 rounded-lg border p-3">
+ {getStatusIcon()}
+ <div className="flex-1">
+ <div className="font-medium">
+ {isLoading
+ ? "Checking..."
+ : status?.isAccessible
+ ? "Publicly accessible"
+ : status?.error
+ ? "Unable to check"
+ : "Not publicly accessible"}
+ </div>
+ {status?.lastChecked && (
+ <div className="text-sm text-gray-500">
+ Last checked:{" "}
+ {new Date(status.lastChecked).toLocaleTimeString()}
+ </div>
+ )}
</div>
</div>
- <DialogFooter>
+
+ {/* Action Buttons */}
+ <div className="flex gap-2">
<Button
variant="outline"
- onClick={() => setIsDialogOpen(false)}
- disabled={isUpdating}
+ size="sm"
+ onClick={checkAccessibility}
+ disabled={isLoading}
+ className="flex-1"
>
- Cancel
+ <RefreshCw
+ className={`mr-2 h-4 w-4 ${isLoading ? "animate-spin" : ""}`}
+ />
+ Refresh
</Button>
+
+ {status?.url && (
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={openNotionPage}
+ className="flex-1"
+ >
+ <ExternalLink className="mr-2 h-4 w-4" />
+ Open Page
+ </Button>
+ )}
+
<Button
- onClick={updateNotionUrl}
- disabled={isUpdating || !newUrl.trim()}
+ variant="outline"
+ size="sm"
+ onClick={() => {
+ setNewUrl(status?.url || "");
+ setIsUrlDialogOpen(true);
+ }}
+ className="flex-1"
>
- {isUpdating ? (
- <>
- <LoadingSpinner className="mr-2 h-4 w-4" />
- Updating...
- </>
- ) : (
- "Update URL"
- )}
+ <Edit className="mr-2 h-4 w-4" />
+ Edit URL
</Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- </div>
+ </div>
+ </div>
+ </DialogContent>
+ </Dialog>
- {status?.lastChecked && (
- <div className="text-xs text-gray-400 mt-1">
- Last checked: {new Date(status.lastChecked).toLocaleTimeString()}
- </div>
- )}
- </div>
+ {/* URL Edit Dialog */}
+ <Dialog open={isUrlDialogOpen} onOpenChange={setIsUrlDialogOpen}>
+ <DialogContent className="sm:max-w-md">
+ <DialogHeader>
+ <DialogTitle>Update Notion URL</DialogTitle>
+ <DialogDescription>
+ Change the URL of the Notion page for this document.
+ </DialogDescription>
+ </DialogHeader>
+ <div className="grid gap-4 py-4">
+ <div className="grid gap-2">
+ <Label htmlFor="notion-url">Notion URL</Label>
+ <Input
+ id="notion-url"
+ value={newUrl}
+ onChange={(e) => setNewUrl(e.target.value)}
+ placeholder="https://www.notion.so/your-page-url"
+ className="w-full"
+ />
+ </div>
+ </div>
+ <DialogFooter>
+ <Button
+ variant="outline"
+ onClick={() => setIsUrlDialogOpen(false)}
+ disabled={isUpdating}
+ >
+ Cancel
+ </Button>
+ <Button
+ onClick={updateNotionUrl}
+ disabled={isUpdating || !newUrl.trim()}
+ >
+ {isUpdating ? (
+ <>
+ <LoadingSpinner className="mr-2 h-4 w-4" />
+ Updating...
+ </>
+ ) : (
+ "Update URL"
+ )}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </>
);
-}
\ No newline at end of file
+}
diff --git a/pages/api/teams/[teamId]/documents/[id]/check-notion-accessibility.ts b/pages/api/teams/[teamId]/documents/[id]/check-notion-accessibility.ts
index 942e147f..50734c36 100644
--- a/pages/api/teams/[teamId]/documents/[id]/check-notion-accessibility.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/check-notion-accessibility.ts
@@ -2,7 +2,9 @@ import { NextApiRequest, NextApiResponse } from "next";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { getServerSession } from "next-auth/next";
+import { parsePageId } from "notion-utils";
+import notion from "@/lib/notion";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
@@ -66,19 +68,29 @@ export default async function handle(
// Check if the Notion page is publicly accessible
try {
const notionUrl = documentVersion.file;
- const response = await fetch(notionUrl, {
- method: "HEAD",
- headers: {
- "User-Agent": "Papermark/1.0 (accessibility-check)",
- },
- });
-
- const isAccessible = response.ok && response.status === 200;
-
+ const pageId = parsePageId(notionUrl, { uuid: false });
+ if (!pageId) {
+ return res.status(200).json({
+ isAccessible: false,
+ url: notionUrl,
+ error: "Notion page URL is not valid",
+ lastChecked: new Date().toISOString(),
+ });
+ }
+ try {
+ await notion.getPage(pageId);
+ } catch (error) {
+ console.error("Error checking Notion accessibility:", error);
+ return res.status(200).json({
+ isAccessible: false,
+ url: documentVersion.file,
+ lastChecked: new Date().toISOString(),
+ });
+ }
return res.status(200).json({
- isAccessible,
+ isAccessible: true,
url: notionUrl,
- statusCode: response.status,
+ statusCode: 200,
lastChecked: new Date().toISOString(),
});
} catch (error) {
@@ -94,4 +106,4 @@ export default async function handle(
console.error("Error:", error);
return res.status(500).json({ message: "Internal server error" });
}
-}
\ No newline at end of file
+}
diff --git a/pages/documents/[id]/index.tsx b/pages/documents/[id]/index.tsx
index 35e2dfb0..1d66eb48 100644
--- a/pages/documents/[id]/index.tsx
+++ b/pages/documents/[id]/index.tsx
@@ -76,6 +76,12 @@ export default function DocumentPage() {
prismaDocument={prismaDocument}
teamId={teamInfo?.currentTeam?.id!}
actions={[
+ <NotionAccessibilityIndicator
+ key={"notion-status"}
+ documentId={prismaDocument.id}
+ primaryVersion={primaryVersion}
+ onUrlUpdate={mutateDocument}
+ />,
<DocumentPreviewButton
key={"preview"}
documentId={prismaDocument.id}
@@ -89,15 +95,6 @@ export default function DocumentPage() {
]}
/>
- {/* Notion Accessibility Indicator */}
- {primaryVersion.type === "notion" && (
- <NotionAccessibilityIndicator
- documentId={prismaDocument.id}
- primaryVersion={primaryVersion}
- onUrlUpdate={mutateDocument}
- />
- )}
-
{/* Document Analytics */}
{primaryVersion.type !== "video" && (
<StatsComponent