Skip to content

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

feat: add simple datarooms endpoint

Marc Seitz4d09d2cab680
diff --git a/lib/swr/use-datarooms-simple.ts b/lib/swr/use-datarooms-simple.ts
new file mode 100644
index 00000000..0da824d1
--- /dev/null
+++ b/lib/swr/use-datarooms-simple.ts
@@ -0,0 +1,39 @@
+import { useTeam } from "@/context/team-context";
+import { Dataroom } from "@prisma/client";
+import useSWR from "swr";
+
+import { fetcher } from "@/lib/utils";
+
+export type DataroomSimple = Pick<Dataroom, "id" | "name" | "createdAt">;
+
+type DataroomsSimpleResponse = {
+ datarooms: DataroomSimple[];
+};
+
+/**
+ * A lightweight hook for fetching datarooms without filtering or extended data.
+ * Use this for simple use cases like dropdowns, sidebars, or modals that only need
+ * basic dataroom info (id, name, createdAt).
+ *
+ * For full features (search, tags, counts), use `useDatarooms` instead.
+ */
+export default function useDataroomsSimple() {
+ const teamInfo = useTeam();
+
+ const { data, error, mutate } = useSWR<DataroomsSimpleResponse>(
+ teamInfo?.currentTeam?.id &&
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms?simple=true`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ dedupingInterval: 30000,
+ },
+ );
+
+ return {
+ datarooms: data?.datarooms,
+ loading: !data && !error,
+ error,
+ mutate,
+ };
+}
diff --git a/pages/api/teams/[teamId]/datarooms/index.ts b/pages/api/teams/[teamId]/datarooms/index.ts
index 2a9e010b..3e127698 100644
--- a/pages/api/teams/[teamId]/datarooms/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/index.ts
@@ -4,7 +4,6 @@ import { isTeamPausedById } from "@/ee/features/billing/cancellation/lib/is-team
import { getLimits } from "@/ee/limits/server";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { Prisma } from "@prisma/client";
-import slugify from "@sindresorhus/slugify";
import { getServerSession } from "next-auth/next";
import { newId } from "@/lib/id-helper";
@@ -27,13 +26,17 @@ export default async function handle(
}
const userId = (session.user as CustomUser).id;
- const { teamId, search, status, tags } = req.query as {
+ const { teamId, search, status, tags, simple } = req.query as {
teamId: string;
search?: string;
status?: string;
tags?: string;
+ simple?: string;
};
+ // Simple mode: return minimal data without filters, tags, or aggregations
+ const isSimpleMode = simple === "true";
+
try {
const teamAccess = await prisma.userTeam.findUnique({
where: {
@@ -51,6 +54,25 @@ export default async function handle(
return res.status(401).end("Unauthorized");
}
+ // Simple mode: return minimal data without filters, tags, or aggregations
+ if (isSimpleMode) {
+ const datarooms = await prisma.dataroom.findMany({
+ where: {
+ teamId: teamId,
+ },
+ select: {
+ id: true,
+ name: true,
+ createdAt: true,
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ });
+
+ return res.status(200).json({ datarooms });
+ }
+
const now = new Date();
const activeLinkFilter: Prisma.LinkWhereInput = {
linkType: "DATAROOM_LINK",
@@ -88,11 +110,11 @@ export default async function handle(
}
}
- if (status === "active") {
- whereClause.links = { some: activeLinkFilter };
- } else if (status === "inactive") {
- whereClause.links = { none: activeLinkFilter };
- }
+ // if (status === "active") {
+ // whereClause.links = { some: activeLinkFilter };
+ // } else if (status === "inactive") {
+ // whereClause.links = { none: activeLinkFilter };
+ // }
const [totalCount, datarooms] = await Promise.all([
prisma.dataroom.count({