Skip to content

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

feat: add notion upload to welcome page

Marc Seitz5b6ce2ec0d18
diff --git a/components/shared/icons/notion.tsx b/components/shared/icons/notion.tsx
new file mode 100644
index 00000000..be17148f
--- /dev/null
+++ b/components/shared/icons/notion.tsx
@@ -0,0 +1,28 @@
+// Thanks to trigger.dev for the icon:
+// https://github.com/triggerdotdev/companyicons/blob/c6dcc5b389aa47fd6d8a0d346b48e7099f90703c/src/icons/companies/notion.tsx
+
+import React from "react";
+
+export default function NotionIcon(
+ props: React.JSX.IntrinsicAttributes & React.SVGProps<SVGSVGElement>,
+) {
+ return (
+ <svg
+ viewBox="0 0 100 100"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <path
+ d="M6.017 4.313l55.333 -4.087c6.797 -0.583 8.543 -0.19 12.817 2.917l17.663 12.443c2.913 2.14 3.883 2.723 3.883 5.053v68.243c0 4.277 -1.553 6.807 -6.99 7.193L24.467 99.967c-4.08 0.193 -6.023 -0.39 -8.16 -3.113L3.3 79.94c-2.333 -3.113 -3.3 -5.443 -3.3 -8.167V11.113c0 -3.497 1.553 -6.413 6.017 -6.8z"
+ fill="#fff"
+ />
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M61.35 0.227l-55.333 4.087C1.553 4.7 0 7.617 0 11.113v60.66c0 2.723 0.967 5.053 3.3 8.167l13.007 16.913c2.137 2.723 4.08 3.307 8.16 3.113l64.257 -3.89c5.433 -0.387 6.99 -2.917 6.99 -7.193V20.64c0 -2.21 -0.873 -2.847 -3.443 -4.733L74.167 3.143c-4.273 -3.107 -6.02 -3.5 -12.817 -2.917zM25.92 19.523c-5.247 0.353 -6.437 0.433 -9.417 -1.99L8.927 11.507c-0.77 -0.78 -0.383 -1.753 1.557 -1.947l53.193 -3.887c4.467 -0.39 6.793 1.167 8.54 2.527l9.123 6.61c0.39 0.197 1.36 1.36 0.193 1.36l-54.933 3.307 -0.68 0.047zM19.803 88.3V30.367c0 -2.53 0.777 -3.697 3.103 -3.893L86 22.78c2.14 -0.193 3.107 1.167 3.107 3.693v57.547c0 2.53 -0.39 4.67 -3.883 4.863l-60.377 3.5c-3.493 0.193 -5.043 -0.97 -5.043 -4.083zm59.6 -54.827c0.387 1.75 0 3.5 -1.75 3.7l-2.91 0.577v42.773c-2.527 1.36 -4.853 2.137 -6.797 2.137 -3.107 0 -3.883 -0.973 -6.21 -3.887l-19.03 -29.94v28.967l6.02 1.363s0 3.5 -4.857 3.5l-13.39 0.777c-0.39 -0.78 0 -2.723 1.357 -3.11l3.497 -0.97v-38.3L30.48 40.667c-0.39 -1.75 0.58 -4.277 3.3 -4.473l14.367 -0.967 19.8 30.327v-26.83l-5.047 -0.58c-0.39 -2.143 1.163 -3.7 3.103 -3.89l13.4 -0.78z"
+ fill="#000"
+ />
+ </svg>
+ );
+}
diff --git a/components/welcome/next.tsx b/components/welcome/next.tsx
index 47818ec3..f42ad36f 100644
--- a/components/welcome/next.tsx
+++ b/components/welcome/next.tsx
@@ -1,7 +1,11 @@
import { useRouter } from "next/router";
import { motion } from "framer-motion";
-import { DocumentIcon, PresentationChartBarIcon } from "@heroicons/react/24/outline";
+import {
+ DocumentIcon,
+ PresentationChartBarIcon,
+} from "@heroicons/react/24/outline";
import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
+import NotionIcon from "@/components/shared/icons/notion";
export default function Next() {
const router = useRouter();
@@ -36,7 +40,7 @@ export default function Next() {
</motion.div>
<motion.div
variants={STAGGER_CHILD_VARIANTS}
- className="grid w-full grid-cols-1 divide-y divide-border text-foreground rounded-md border border-border md:grid-cols-2 md:divide-x"
+ className="grid w-full grid-cols-1 divide-y divide-border text-foreground rounded-md border border-border md:grid-cols-3 md:divide-x"
>
<button
onClick={() =>
@@ -49,7 +53,7 @@ export default function Next() {
}
className="flex flex-col items-center justify-center overflow-hidden p-5 space-y-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10 min-h-[200px]"
>
- <PresentationChartBarIcon className="h-auto pointer-events-none w-12 sm:w-12" />
+ <PresentationChartBarIcon className="h-auto pointer-events-none w-12 sm:w-12" />
<p>Pitchdeck</p>
</button>
<button
@@ -63,9 +67,23 @@ export default function Next() {
}
className="flex flex-col items-center justify-center overflow-hidden p-5 space-y-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10 min-h-[200px]"
>
- <DocumentIcon className="h-auto pointer-events-none w-12 sm:w-12" />
+ <DocumentIcon className="h-auto pointer-events-none w-12 sm:w-12" />
<p>Another document</p>
</button>
+ <button
+ onClick={() =>
+ router.push({
+ pathname: "/welcome",
+ query: {
+ type: "notion",
+ },
+ })
+ }
+ className="flex flex-col items-center justify-center overflow-hidden p-5 space-y-5 transition-colors hover:bg-gray-200 hover:dark:bg-gray-800 md:p-10 min-h-[200px]"
+ >
+ <NotionIcon className="h-auto pointer-events-none w-12 sm:w-12" />
+ <p>Notion Page</p>
+ </button>
</motion.div>
</motion.div>
);
diff --git a/components/welcome/notion-form.tsx b/components/welcome/notion-form.tsx
new file mode 100644
index 00000000..b593c381
--- /dev/null
+++ b/components/welcome/notion-form.tsx
@@ -0,0 +1,221 @@
+import { useRouter } from "next/router";
+import { motion } from "framer-motion";
+import { useState, type FormEvent } from "react";
+import { toast } from "sonner";
+import Skeleton from "../Skeleton";
+import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
+import { copyToClipboard } from "@/lib/utils";
+import { Button } from "../ui/button";
+import { usePlausible } from "next-plausible";
+import { useTeam } from "@/context/team-context";
+import { Label } from "../ui/label";
+
+export default function NotionForm() {
+ const router = useRouter();
+ const plausible = usePlausible();
+ const [uploading, setUploading] = useState<boolean>(false);
+ const [currentLinkId, setCurrentLinkId] = useState<string | null>(null);
+ const [currentDocId, setCurrentDocId] = useState<string | null>(null);
+ const [notionLink, setNotionLink] = useState<string | null>(null);
+ const teamInfo = useTeam();
+
+ const handleNotionUpload = async (
+ event: FormEvent<HTMLFormElement>,
+ ): Promise<void> => {
+ event.preventDefault();
+
+ // Check if the file is chosen
+ if (!notionLink) {
+ toast.error("Please enter a Notion link to proceed.");
+ return; // prevent form from submitting
+ }
+
+ try {
+ setUploading(true);
+
+ const response = await fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/documents`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ name: "Notion Link", // TODO: get the title of the notion page
+ url: notionLink,
+ numPages: 1,
+ type: "notion",
+ }),
+ },
+ );
+
+ if (response) {
+ const document = await response.json();
+ const linkId = document.links[0].id;
+
+ // track the event
+ plausible("documentUploaded");
+ plausible("notionDocumentUploaded");
+
+ // redirect to the document page
+ setTimeout(() => {
+ setCurrentDocId(document.id);
+ setCurrentLinkId(linkId);
+ setUploading(false);
+ }, 2000);
+ }
+ } catch (error) {
+ console.error(
+ "An error occurred while processing the Notion link: ",
+ error,
+ );
+ setNotionLink(null);
+ setUploading(false);
+ }
+ };
+
+ const handleContinue = (id: string) => {
+ copyToClipboard(
+ `${process.env.NEXT_PUBLIC_BASE_URL}/view/${id}`,
+ "Link copied to clipboard. Redirecting to document page...",
+ );
+ setTimeout(() => {
+ router.push(`/documents/${currentDocId}`);
+ setUploading(false);
+ }, 2000);
+ };
+
+ return (
+ <>
+ {!currentDocId && (
+ <motion.div
+ className="z-10 flex flex-col space-y-10 -mt-10"
+ variants={{
+ hidden: { opacity: 0, scale: 0.95 },
+ show: {
+ opacity: 1,
+ scale: 1,
+ transition: {
+ staggerChildren: 0.2,
+ },
+ },
+ }}
+ initial="hidden"
+ animate="show"
+ exit="hidden"
+ transition={{ duration: 0.3, type: "spring" }}
+ >
+ <motion.div
+ variants={STAGGER_CHILD_VARIANTS}
+ className="flex flex-col items-center space-y-10 text-center"
+ >
+ <h1 className="font-display text-3xl font-semibold text-foreground transition-colors sm:text-4xl">
+ Share a Notion Page
+ </h1>
+ </motion.div>
+ <motion.div variants={STAGGER_CHILD_VARIANTS}>
+ <form
+ encType="multipart/form-data"
+ onSubmit={handleNotionUpload}
+ className="flex flex-col"
+ >
+ <div className="space-y-1 pb-8">
+ <Label htmlFor="notion-link">Add Notion Page Link</Label>
+ <div className="mt-2">
+ <input
+ type="text"
+ name="notion-link"
+ id="notion-link"
+ placeholder="notion.site/..."
+ 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"
+ value={notionLink || ""}
+ onChange={(e) => setNotionLink(e.target.value)}
+ />
+ </div>
+ <small className="text-xs text-muted-foreground">
+ Your Notion page needs to be shared publicly. Learn more.
+ </small>
+ </div>
+ <div className="flex justify-center">
+ <Button
+ type="submit"
+ className="w-full lg:w-1/2"
+ disabled={uploading || !notionLink}
+ loading={uploading}
+ >
+ {uploading ? "Saving..." : "Save Notion Link"}
+ </Button>
+ </div>
+ </form>
+ </motion.div>
+ </motion.div>
+ )}
+
+ {currentDocId && (
+ <motion.div
+ className="z-10 flex flex-col space-y-10 text-center"
+ variants={{
+ hidden: { opacity: 0, scale: 0.95 },
+ show: {
+ opacity: 1,
+ scale: 1,
+ transition: {
+ staggerChildren: 0.2,
+ },
+ },
+ }}
+ initial="hidden"
+ animate="show"
+ exit="hidden"
+ transition={{ duration: 0.3, type: "spring" }}
+ >
+ <motion.div
+ variants={STAGGER_CHILD_VARIANTS}
+ className="flex flex-col items-center space-y-10 text-center"
+ >
+ <h1 className="font-display text-3xl font-semibold text-foreground transition-colors sm:text-4xl">
+ Share your unique link
+ </h1>
+ </motion.div>
+
+ <motion.div variants={STAGGER_CHILD_VARIANTS}>
+ {!currentLinkId && (
+ <main className="min-h-[300px]">
+ <div className="flex flex-col justify-center">
+ <div className="flex py-8">
+ <div className="flex w-full focus-within:z-10">
+ <Skeleton className="h-6 w-full" />
+ </div>
+ </div>
+ </div>
+ </main>
+ )}
+ {currentLinkId && currentDocId && (
+ <main className="min-h-[300px]">
+ <div className="flex flex-col justify-center">
+ <div className="relative">
+ <div className="flex py-8">
+ <div className="flex w-full max-w-xs sm:max-w-lg focus-within:z-10">
+ <p className="block w-full md:min-w-[500px] rounded-md px-4 text-left border-0 py-1.5 text-secondary-foreground bg-secondary leading-6 overflow-y-scroll">
+ {`${process.env.NEXT_PUBLIC_BASE_URL}/view/${currentLinkId}`}
+ </p>
+ </div>
+ </div>
+ </div>
+ <div className="flex items-center justify-center mb-4">
+ <Button
+ onClick={() => handleContinue(currentLinkId)}
+ type="submit"
+ >
+ {"Share Document"}
+ </Button>
+ </div>
+ </div>
+ </main>
+ )}
+ </motion.div>
+ </motion.div>
+ )}
+ </>
+ );
+}
diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.ts
index e3ba1c93..5cc4b146 100644
--- a/pages/api/teams/[teamId]/documents/index.ts
+++ b/pages/api/teams/[teamId]/documents/index.ts
@@ -11,7 +11,7 @@ import { client } from "@/trigger";
export default async function handle(
req: NextApiRequest,
- res: NextApiResponse
+ res: NextApiResponse,
) {
if (req.method === "GET") {
// GET /api/teams/:teamId/documents
@@ -63,7 +63,17 @@ export default async function handle(
const userId = (session.user as CustomUser).id;
// Assuming data is an object with `name` and `description` properties
- const { name, url: fileUrl, numPages } = req.body as { name: string; url: string; numPages: number }
+ const {
+ name,
+ url: fileUrl,
+ numPages,
+ type: fileType,
+ } = req.body as {
+ name: string;
+ url: string;
+ numPages: number;
+ type?: string;
+ };
try {
await getTeamWithUsersAndDocument({
@@ -71,8 +81,8 @@ export default async function handle(
userId,
});
- // Get the file extension and save it as the type
- const type = getExtension(name);
+ // Get passed type property or alternatively, the file extension and save it as the type
+ const type = fileType || getExtension(name);
// You could perform some validation here
@@ -127,16 +137,19 @@ export default async function handle(
customDomain: null,
});
- // trigger document uploaded event to trigger convert-pdf-to-image job
- await client.sendEvent({
- name: "document.uploaded",
- payload: { documentVersionId: document.versions[0].id },
- });
+ // skip triggering convert-pdf-to-image job for "notion" documents
+ if (type !== "notion") {
+ // trigger document uploaded event to trigger convert-pdf-to-image job
+ await client.sendEvent({
+ name: "document.uploaded",
+ payload: { documentVersionId: document.versions[0].id },
+ });
+ }
return res.status(201).json(document);
} catch (error) {
log(
- `Failed to create document. \n\n teamId: ${teamId}, file: ${fileUrl} \n\n ${error}`
+ `Failed to create document. \n\n teamId: ${teamId}, file: ${fileUrl} \n\n ${error}`,
);
errorhandler(error, res);
}
diff --git a/pages/welcome.tsx b/pages/welcome.tsx
index aceb3784..803255fe 100644
--- a/pages/welcome.tsx
+++ b/pages/welcome.tsx
@@ -4,11 +4,11 @@ import Next from "@/components/welcome/next";
import Upload from "@/components/welcome/upload";
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
import { AnimatePresence } from "framer-motion";
+import NotionForm from "@/components/welcome/notion-form";
export default function Welcome() {
const router = useRouter();
-
return (
<div className="flex h-screen flex-col items-center justify-center max-w-3xl mx-auto overflow-x-hidden">
<div
@@ -37,6 +37,7 @@ export default function Welcome() {
{router.query.type === "next" && <Next key="next" />}
{router.query.type === "pitchdeck" && <Upload key="pitchdeck" />}
{router.query.type === "document" && <Upload key="document" />}
+ {router.query.type === "notion" && <NotionForm key="notion" />}
</AnimatePresence>
</div>
);