Skip to content

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

fix: document link shit

Marc Seitzc7bd7071ed28
diff --git a/components/datarooms/dataroom-card.tsx b/components/datarooms/dataroom-card.tsx
deleted file mode 100644
index a39d62c5..00000000
--- a/components/datarooms/dataroom-card.tsx
+++ /dev/null
@@ -1,107 +0,0 @@
-import { timeAgo } from "@/lib/utils";
-import Link from "next/link";
-import { TeamContextType } from "@/context/team-context";
-import { Button } from "@/components/ui/button";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuLabel,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
-} from "@/components/ui/dropdown-menu";
-import { MoreVertical, FolderIcon } from "lucide-react";
-import { useRef } from "react";
-import { FolderWithCount } from "@/lib/swr/use-documents";
-import { Dataroom } from "@prisma/client";
-
-export default function DataroomCard({
- dataroom,
-}: {
- dataroom: Dataroom & { _count: { documents: number } };
-}) {
- const dropdownRef = useRef<HTMLDivElement | null>(null);
-
- return (
- <li className="group/row relative rounded-lg p-3 border-0 dark:bg-secondary ring-1 ring-gray-400 dark:ring-gray-500 transition-all hover:ring-gray-500 hover:dark:ring-gray-400 hover:bg-secondary sm:p-4 flex justify-between items-center">
- <div className="min-w-0 flex shrink items-center space-x-2 sm:space-x-4">
- <div className="w-8 mx-0.5 sm:mx-1 text-center flex justify-center items-center">
- <FolderIcon className="w-8 h-8 " strokeWidth={1} />
- </div>
-
- <div className="flex-col">
- <div className="flex items-center">
- <h2 className="min-w-0 text-sm font-semibold leading-6 text-foreground truncate max-w-[150px] sm:max-w-md">
- <Link
- href={`/datarooms/${dataroom.id}`}
- className="truncate w-full"
- >
- <span>{dataroom.name}</span>
- <span className="absolute inset-0" />
- </Link>
- </h2>
- </div>
- <div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-muted-foreground">
- <p className="truncate">{timeAgo(dataroom.createdAt)}</p>
- <p>•</p>
- <p className="truncate">
- {dataroom._count.documents}{" "}
- {folder._count.documents === 1 ? "Document" : "Documents"}
- </p>
- <p>•</p>
- <p className="truncate">
- {folder._count.childFolders}{" "}
- {folder._count.childFolders === 1 ? "Folder" : "Folders"}
- </p>
- </div>
- </div>
- </div>
-
- <div className="flex flex-row space-x-2">
- {/* <Link
- onClick={(e) => {
- e.stopPropagation();
- }}
- href={`/documents/${prismaDocument.id}`}
- className="flex items-center z-10 space-x-1 rounded-md bg-gray-200 dark:bg-gray-700 px-1.5 sm:px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
- >
- <BarChart className="h-3 sm:h-4 w-3 sm:w-4 text-muted-foreground" />
- <p className="whitespace-nowrap text-xs sm:text-sm text-muted-foreground">
- {nFormatter(prismaDocument._count.views)}
- <span className="ml-1 hidden sm:inline-block">views</span>
- </p>
- </Link> */}
-
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- // size="icon"
- variant="outline"
- className="h-8 lg:h-9 w-8 lg:w-9 p-0 z-10 bg-transparent border-gray-200 dark:border-gray-700 hover:bg-gray-200 hover:dark:bg-gray-700"
- >
- <span className="sr-only">Open menu</span>
- <MoreVertical className="w-4 h-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" ref={dropdownRef}>
- <DropdownMenuLabel>Actions</DropdownMenuLabel>
- <DropdownMenuSeparator />
-
- {/* <DropdownMenuItem
- onClick={(event) => handleButtonClick(event, prismaDocument.id)}
- className="text-destructive focus:bg-destructive focus:text-destructive-foreground duration-200"
- >
- {isFirstClick ? (
- "Really delete?"
- ) : (
- <>
- <TrashIcon className="w-4 h-4 mr-2" /> Delete document
- </>
- )}
- </DropdownMenuItem> */}
- </DropdownMenuContent>
- </DropdownMenu>
- </div>
- </li>
- );
-}
diff --git a/components/visitors/visitors-table.tsx b/components/visitors/visitors-table.tsx
index 3d3e1828..3f34f4b5 100644
--- a/components/visitors/visitors-table.tsx
+++ b/components/visitors/visitors-table.tsx
@@ -139,7 +139,7 @@ export default function VisitorsTable({ numPages }: { numPages: number }) {
<TableRow className="hover:bg-transparent">
<TableCell colSpan={5}>
<VisitorChart
- documentId={view.documentId}
+ documentId={view.documentId!}
viewId={view.id}
totalPages={numPages}
/>
diff --git a/lib/types.ts b/lib/types.ts
index ace21eee..00494a8d 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -39,8 +39,8 @@ export interface LinkWithViews extends Link {
views: View[];
}
-export interface LinkWithDocumentOrDataroom extends Link {
- document?: Document & {
+export interface LinkWithDocument extends Link {
+ document: Document & {
versions: {
id: string;
versionNumber: number;
@@ -53,13 +53,6 @@ export interface LinkWithDocumentOrDataroom extends Link {
};
};
};
- dataroom?: Dataroom & {
- documents: DataroomDocument[];
- folders: DataroomFolder[];
- team?: {
- plan: string;
- };
- };
}
export interface Geo {
diff --git a/pages/api/jobs/send-notification.ts b/pages/api/jobs/send-notification.ts
index c2c04ae0..7d7db97d 100644
--- a/pages/api/jobs/send-notification.ts
+++ b/pages/api/jobs/send-notification.ts
@@ -41,7 +41,7 @@ export default async function handle(
id: string;
email: string | null;
};
- };
+ } | null;
} | null;
try {
@@ -86,9 +86,9 @@ export default async function handle(
try {
// send email to document owner that document
await sendViewedDocumentEmail({
- ownerEmail: view.document.owner.email,
- documentId: view.document.id,
- documentName: view.document.name,
+ ownerEmail: view.document!.owner.email,
+ documentId: view.document!.id,
+ documentName: view.document!.name,
viewerEmail: view.viewerEmail,
});
@@ -96,7 +96,7 @@ export default async function handle(
return;
} catch (error) {
log({
- message: `Failed to send email in _/api/views_ route for linkId: ${view.linkId}. \n\n Error: ${error} \n\n*Metadata*: \`{ownerId: ${view.document.owner.id}, viewId: ${viewId}}\``,
+ message: `Failed to send email in _/api/views_ route for linkId: ${view.linkId}. \n\n Error: ${error} \n\n*Metadata*: \`{ownerId: ${view.document!.owner.id}, viewId: ${viewId}}\``,
type: "error",
mention: true,
});
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index e6c4d615..3517a4ed 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -67,7 +67,7 @@ export default async function handle(
let brand = await prisma.brand.findFirst({
where: {
- teamId: link.document.teamId!,
+ teamId: link.document!.teamId!,
},
select: {
logo: true,
@@ -226,7 +226,7 @@ export default async function handle(
}
if (
- linkToBeDeleted.document.ownerId !== (session.user as CustomUser).id
+ linkToBeDeleted.document!.ownerId !== (session.user as CustomUser).id
) {
return res.status(401).end("Unauthorized to access the link");
}
diff --git a/pages/api/links/[id]/visits.ts b/pages/api/links/[id]/visits.ts
index 430487f9..99861c0b 100644
--- a/pages/api/links/[id]/visits.ts
+++ b/pages/api/links/[id]/visits.ts
@@ -46,8 +46,8 @@ export default async function handle(
},
});
- const docId = result?.document.id!;
-
+ const docId = result?.document!.id!;
+
// check if the the team that own the document has the current user
await getDocumentWithTeamAndUser({
docId,
@@ -81,7 +81,7 @@ export default async function handle(
const durationsPromises = views.map((view) => {
return getViewPageDuration({
- documentId: view.documentId,
+ documentId: view.documentId!,
viewId: view.id,
since: 0,
});
@@ -116,7 +116,10 @@ export default async function handle(
return res.status(200).json(viewsWithDuration);
} catch (error) {
- log({message: `Failed to get views for link: _${id}_. \n\n ${error} \n\n*Metadata*: \`{userId: ${userId}}\``, type: "error"});
+ log({
+ message: `Failed to get views for link: _${id}_. \n\n ${error} \n\n*Metadata*: \`{userId: ${userId}}\``,
+ type: "error",
+ });
errorhandler(error, res);
}
} else {
diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].ts
index 7936bcc4..3f67dfdd 100644
--- a/pages/api/links/domains/[...domainSlug].ts
+++ b/pages/api/links/domains/[...domainSlug].ts
@@ -66,7 +66,7 @@ export default async function handle(
});
// if link not found, return 404
- if (!link || !link.document.team) {
+ if (!link || !link.document!.team) {
log({
message: `Link not found for custom domain _${domain}/${slug}_`,
type: "error",
@@ -74,20 +74,20 @@ export default async function handle(
});
return res.status(404).json({
error: "Link not found",
- message: `no link found, team ${link?.document.team}`,
+ message: `no link found, team ${link?.document!.team}`,
});
}
// if owner of document is on free plan, return 404
- if (link.document.team.plan === "free") {
+ if (link.document!.team.plan === "free") {
log({
- message: `Link is from a free team _${link.document.team.id}_ for custom domain _${domain}/${slug}_`,
+ message: `Link is from a free team _${link.document!.team.id}_ for custom domain _${domain}/${slug}_`,
type: "info",
mention: true,
});
return res.status(404).json({
error: "Link not found",
- message: `link found, team ${link.document.team.plan}`,
+ message: `link found, team ${link.document!.team.plan}`,
});
}
@@ -100,7 +100,7 @@ export default async function handle(
let brand = await prisma.brand.findFirst({
where: {
- teamId: link.document.team.id,
+ teamId: link.document!.team.id,
},
select: {
logo: true,
diff --git a/pages/api/links/download.ts b/pages/api/links/download.ts
index 6653ada6..380e6c35 100644
--- a/pages/api/links/download.ts
+++ b/pages/api/links/download.ts
@@ -63,7 +63,7 @@ export default async function handle(
}
// if document is a Notion document, we should not allow the download
- if (view.document.versions[0].type === "notion") {
+ if (view.document!.versions[0].type === "notion") {
return res.status(403).json({ error: "Error downloading" });
}
@@ -82,8 +82,8 @@ export default async function handle(
});
const downloadUrl = await getFile({
- type: view.document.versions[0].storageType,
- data: view.document.versions[0].file,
+ type: view.document!.versions[0].storageType,
+ data: view.document!.versions[0].file,
isDownload: true,
});
diff --git a/pages/view/[linkId]/chat.tsx b/pages/view/[linkId]/chat.tsx
index e49b379d..692079a6 100644
--- a/pages/view/[linkId]/chat.tsx
+++ b/pages/view/[linkId]/chat.tsx
@@ -55,7 +55,7 @@ export const getServerSideProps = async (context: any) => {
};
}
- if (!link.document.assistantEnabled) {
+ if (!link.document!.assistantEnabled) {
return {
notFound: true,
};
@@ -72,7 +72,7 @@ export const getServerSideProps = async (context: any) => {
"Content-Type": "application/json",
},
body: JSON.stringify({
- documentId: link!.document.id,
+ documentId: link!.document!.id,
userId: userId,
}),
},
@@ -86,10 +86,10 @@ export const getServerSideProps = async (context: any) => {
const { threadId, messages } = await res.json();
- const firstPage = link.document.versions[0].pages[0]
+ const firstPage = link.document!.versions[0].pages[0]
? await getFile({
- type: link.document.versions[0].pages[0].storageType,
- data: link.document.versions[0].pages[0].file,
+ type: link.document!.versions[0].pages[0].storageType,
+ data: link.document!.versions[0].pages[0].file,
})
: "";