Skip to content

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

fix: add total dataroom count

Marc Seitzeb1dd0aef7b3
diff --git a/lib/swr/use-datarooms.ts b/lib/swr/use-datarooms.ts
index 1c1704e1..85e54770 100644
--- a/lib/swr/use-datarooms.ts
+++ b/lib/swr/use-datarooms.ts
@@ -30,6 +30,11 @@ export type DataroomWithCount = Dataroom & {
}[];
};
+export type DataroomsResponse = {
+ datarooms: DataroomWithCount[];
+ totalCount: number;
+};
+
export default function useDatarooms() {
const router = useRouter();
const teamInfo = useTeam();
@@ -45,7 +50,7 @@ export default function useDatarooms() {
if (tagsQuery) queryParts.push(`tags=${tagsQuery}`);
const queryString = queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
- const { data: datarooms, error, mutate } = useSWR<DataroomWithCount[]>(
+ const { data, error, mutate } = useSWR<DataroomsResponse>(
teamInfo?.currentTeam?.id &&
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms${queryString}`,
fetcher,
@@ -57,8 +62,9 @@ export default function useDatarooms() {
);
return {
- datarooms,
- loading: !datarooms && !error,
+ datarooms: data?.datarooms,
+ totalCount: data?.totalCount,
+ loading: !data && !error,
error,
mutate,
};
diff --git a/pages/api/teams/[teamId]/datarooms/index.ts b/pages/api/teams/[teamId]/datarooms/index.ts
index cfc06dd4..ba211571 100644
--- a/pages/api/teams/[teamId]/datarooms/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/index.ts
@@ -45,6 +45,13 @@ export default async function handle(
return res.status(401).end("Unauthorized");
}
+ // Get total unfiltered count first
+ const totalCount = await prisma.dataroom.count({
+ where: {
+ teamId: teamId,
+ },
+ });
+
// Build where clause based on filters
const whereClause: any = {
teamId: teamId,
@@ -144,7 +151,10 @@ export default async function handle(
});
}
- return res.status(200).json(filteredDatarooms);
+ return res.status(200).json({
+ datarooms: filteredDatarooms,
+ totalCount,
+ });
} catch (error) {
console.error("Request error", error);
return res.status(500).json({ error: "Error fetching datarooms" });
diff --git a/pages/datarooms/index.tsx b/pages/datarooms/index.tsx
index e513a6be..3efafba1 100644
--- a/pages/datarooms/index.tsx
+++ b/pages/datarooms/index.tsx
@@ -34,7 +34,7 @@ import { Separator } from "@/components/ui/separator";
export default function DataroomsPage() {
const teamInfo = useTeam();
- const { datarooms } = useDatarooms();
+ const { datarooms, totalCount } = useDatarooms();
const { isFree, isPro, isBusiness, isDatarooms, isDataroomsPlus, isTrial } =
usePlan();
const { limits } = useLimits();
@@ -53,13 +53,13 @@ export default function DataroomsPage() {
},
});
- const numDatarooms = datarooms?.length ?? 0;
+ const totalDatarooms = totalCount ?? 0;
const limitDatarooms = limits?.datarooms ?? 1;
const canCreateUnlimitedDatarooms =
isDatarooms ||
isDataroomsPlus ||
- (isBusiness && numDatarooms < limitDatarooms);
+ (isBusiness && totalDatarooms < limitDatarooms);
const searchQuery = router.query.search as string | undefined;
@@ -205,8 +205,9 @@ export default function DataroomsPage() {
{hasActiveFilters && (
<div className="mb-4 flex items-center gap-2 text-sm text-muted-foreground">
<span>
- Showing {sortedDatarooms?.length || 0} of {numDatarooms} dataroom
- {numDatarooms !== 1 ? "s" : ""}
+ Showing {sortedDatarooms?.length || 0} of {totalDatarooms}{" "}
+ dataroom
+ {totalDatarooms !== 1 ? "s" : ""}
</span>
<Button
variant="link"