Skip to content

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

feat: add teamId on duplicate link

Marc Seitzb3f1bf01a9d8
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 3f4131a5..91af9519 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -7,7 +7,7 @@ import { DocumentVersion } from "@prisma/client";
import { BoxesIcon, EyeIcon, LinkIcon, Settings2Icon } from "lucide-react";
import { toast } from "sonner";
import { mutate } from "swr";
-import useLimits from "@/lib/swr/use-limits";
+
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import { Button } from "@/components/ui/button";
import {
@@ -34,6 +34,7 @@ import {
} from "@/components/ui/table";
import { usePlan } from "@/lib/swr/use-billing";
+import useLimits from "@/lib/swr/use-limits";
import { LinkWithViews, WatermarkConfig } from "@/lib/types";
import { cn, copyToClipboard, nFormatter, timeAgo } from "@/lib/utils";
@@ -144,15 +145,15 @@ export default function LinksTable({
const handleDuplicateLink = async (link: LinkWithViews) => {
setIsLoading(true);
- const response = await fetch(
- `/api/links/${link.id}/duplicate?teamId=${teamInfo?.currentTeam?.id}`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
+ const response = await fetch(`/api/links/${link.id}/duplicate`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
},
- );
+ body: JSON.stringify({
+ teamId: teamInfo?.currentTeam?.id,
+ }),
+ });
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
@@ -178,9 +179,7 @@ export default function LinksTable({
if (!canAddLinks) {
return (
<UpgradePlanModal clickedPlan="Pro" trigger={"limit_add_link"}>
- <Button>
- Upgrade to Create Link
- </Button>
+ <Button>Upgrade to Create Link</Button>
</UpgradePlanModal>
);
} else {
@@ -456,7 +455,7 @@ export default function LinksTable({
</div>
</div>
<p>No links found for this {targetType.toLowerCase()}</p>
- <AddLinkButton/>
+ <AddLinkButton />
</div>
</TableCell>
</TableRow>
diff --git a/pages/api/links/[id]/duplicate.ts b/pages/api/links/[id]/duplicate.ts
index f536e9b3..9cea0ebc 100644
--- a/pages/api/links/[id]/duplicate.ts
+++ b/pages/api/links/[id]/duplicate.ts
@@ -20,7 +20,8 @@ export default async function handle(
return res.status(401).end("Unauthorized");
}
- const { id, teamId } = req.query as { id: string; teamId: string };
+ const { id } = req.query as { id: string };
+ const { teamId } = req.body as { teamId: string };
try {
const team = await prisma.team.findUnique({
@@ -40,35 +41,23 @@ export default async function handle(
}
const link = await prisma.link.findUnique({
- where: { id },
- include: {
- dataroom: {
- select: {
- teamId: true,
- },
- },
- document: {
- select: { teamId: true },
- },
- },
+ where: { id, teamId },
});
if (!link) {
return res.status(404).json({ error: "Link not found" });
}
- const { dataroom, document, ...linkData } = link;
-
- const newLinkName = linkData.name
- ? linkData.name + " (Copy)"
- : `Link #${linkData.id.slice(-5)} (Copy)`;
+ const newLinkName = link.name
+ ? link.name + " (Copy)"
+ : `Link #${link.id.slice(-5)} (Copy)`;
const newLink = await prisma.link.create({
data: {
- ...linkData,
+ ...link,
id: undefined,
- slug: linkData.slug ? linkData.slug + "-copy" : null,
+ slug: link.slug ? link.slug + "-copy" : null,
name: newLinkName,
- watermarkConfig: linkData.watermarkConfig || Prisma.JsonNull,
+ watermarkConfig: link.watermarkConfig || Prisma.JsonNull,
createdAt: undefined,
updatedAt: undefined,
},
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/users/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/users/index.ts
index b17ad365..b9513038 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/users/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/users/index.ts
@@ -19,107 +19,111 @@ export default async function handle(
return res.status(401).end("Unauhorized");
}
- const { teamId, id: dataroomId } = req.query as {
- teamId: string;
- id: string;
- };
-
- const { emails } = req.body as { emails: string[] };
-
- if (!emails) {
- return res.status(400).json("Email is missing in request body");
- }
-
- if (emails.length > 5) {
- return res
- .status(400)
- .json("You can only send invitations to 5 emails at a time.");
- }
-
- try {
- const team = await prisma.team.findUnique({
- where: {
- id: teamId,
- plan: {
- notIn: ["free", "free+drtrial"],
- },
- users: {
- some: {
- userId: (session.user as CustomUser).id,
- },
- },
- },
- select: {
- id: true,
- },
- });
-
- if (!team) {
- return res.status(403).end("Unauthorized to access this team");
- }
-
- const dataroom = await prisma.dataroom.findUnique({
- where: {
- id: dataroomId,
- teamId: teamId,
- },
- include: {
- viewers: true,
- },
- });
-
- if (!dataroom) {
- return res.status(404).end("Dataroom not found");
- }
-
- await prisma.viewer.createMany({
- data: emails.map((email) => ({
- email,
- dataroomId,
- teamId,
- invitedAt: new Date(),
- })),
- skipDuplicates: true,
- });
-
- const viewers = await prisma.viewer.findMany({
- where: {
- dataroomId,
- email: {
- in: emails,
- },
- },
- select: {
- id: true,
- email: true,
- },
- });
-
- // create a new link for the invited group
- const link = await prisma.link.create({
- data: {
- dataroomId,
- linkType: "DATAROOM_LINK",
- name: `Invited ${new Date().toLocaleString()}`,
- enableFeedback: false,
- },
- select: {
- id: true,
- },
- });
-
- console.time("sendemail");
- await sendViewerInvitation({
- dataroomId,
- linkId: link.id,
- viewerIds: viewers.map((v) => v.id),
- senderUserId: (session.user as CustomUser).id,
- });
- console.timeEnd("sendemail");
-
- return res.status(200).json("Invitation sent!");
- } catch (error) {
- errorhandler(error, res);
- }
+ // INFO: This endpoint is not available anymore
+ return res.status(404).json("Not available");
+
+ // const { teamId, id: dataroomId } = req.query as {
+ // teamId: string;
+ // id: string;
+ // };
+
+ // const { emails } = req.body as { emails: string[] };
+
+ // if (!emails) {
+ // return res.status(400).json("Email is missing in request body");
+ // }
+
+ // if (emails.length > 5) {
+ // return res
+ // .status(400)
+ // .json("You can only send invitations to 5 emails at a time.");
+ // }
+
+ // try {
+ // const team = await prisma.team.findUnique({
+ // where: {
+ // id: teamId,
+ // plan: {
+ // notIn: ["free", "free+drtrial"],
+ // },
+ // users: {
+ // some: {
+ // userId: (session.user as CustomUser).id,
+ // },
+ // },
+ // },
+ // select: {
+ // id: true,
+ // },
+ // });
+
+ // if (!team) {
+ // return res.status(403).end("Unauthorized to access this team");
+ // }
+
+ // const dataroom = await prisma.dataroom.findUnique({
+ // where: {
+ // id: dataroomId,
+ // teamId: teamId,
+ // },
+ // include: {
+ // viewers: true,
+ // },
+ // });
+
+ // if (!dataroom) {
+ // return res.status(404).end("Dataroom not found");
+ // }
+
+ // await prisma.viewer.createMany({
+ // data: emails.map((email) => ({
+ // email,
+ // dataroomId,
+ // teamId,
+ // invitedAt: new Date(),
+ // })),
+ // skipDuplicates: true,
+ // });
+
+ // const viewers = await prisma.viewer.findMany({
+ // where: {
+ // dataroomId,
+ // email: {
+ // in: emails,
+ // },
+ // },
+ // select: {
+ // id: true,
+ // email: true,
+ // },
+ // });
+
+ // // create a new link for the invited group
+ // const link = await prisma.link.create({
+ // data: {
+ // dataroomId,
+ // linkType: "DATAROOM_LINK",
+ // name: `Invited ${new Date().toLocaleString()}`,
+ // enableFeedback: false,
+ // teamId,
+ // },
+ // select: {
+ // id: true,
+ // },
+ // });
+
+ // console.time("sendemail");
+ // await sendViewerInvitation({
+ // dataroomId,
+ // linkId: link.id,
+ // viewerIds: viewers.map((v) => v.id),
+ // senderUserId: (session.user as CustomUser).id,
+ // });
+ // console.timeEnd("sendemail");
+
+ // return res.status(200).json("Invitation sent!");
+ // } catch (error) {
+ // errorhandler(error, res);
+ // }
}
}
diff --git a/pages/api/teams/[teamId]/viewers/[id]/index.ts b/pages/api/teams/[teamId]/viewers/[id]/index.ts
index 89f6d7f0..bf0b601b 100644
--- a/pages/api/teams/[teamId]/viewers/[id]/index.ts
+++ b/pages/api/teams/[teamId]/viewers/[id]/index.ts
@@ -152,8 +152,6 @@ export default async function handle(
views: groupedViews,
};
- console.log("newViewer", newViewer);
-
return res.status(200).json(newViewer);
} catch (error) {
errorhandler(error, res);