Skip to content

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

fix: people are loading now

Marc Seitz9fefaa12e676
diff --git a/lib/types.ts b/lib/types.ts
index 9778ae7c..f485744b 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -314,14 +314,17 @@ export interface TeamDetail {
role: "ADMIN" | "MANAGER" | "MEMBER";
status: "ACTIVE" | "BLOCKED_TRIAL_EXPIRED";
teamId: string;
+ userId: string;
user: {
email: string;
name: string;
- _count: {
- documents: number;
- };
};
- userId: string;
+ }[];
+ documents: {
+ owner: {
+ name: string;
+ id: string;
+ };
}[];
}
diff --git a/pages/api/teams/[teamId]/index.ts b/pages/api/teams/[teamId]/index.ts
index 33e89266..bd179ef6 100644
--- a/pages/api/teams/[teamId]/index.ts
+++ b/pages/api/teams/[teamId]/index.ts
@@ -46,13 +46,16 @@ export default async function handle(
select: {
email: true,
name: true,
- _count: {
- select: {
- documents: {
- where: { teamId: teamId },
- },
- },
- },
+ },
+ },
+ },
+ },
+ documents: {
+ select: {
+ owner: {
+ select: {
+ name: true,
+ id: true,
},
},
},
diff --git a/pages/settings/people.tsx b/pages/settings/people.tsx
index 69bc9520..55fcd880 100644
--- a/pages/settings/people.tsx
+++ b/pages/settings/people.tsx
@@ -1,7 +1,6 @@
-import Link from "next/link";
import { useRouter } from "next/router";
-import { useState } from "react";
+import { useMemo, useState } from "react";
import { useTeam } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
@@ -10,7 +9,6 @@ import { toast } from "sonner";
import { mutate } from "swr";
import { useAnalytics } from "@/lib/analytics";
-import { usePlan } from "@/lib/swr/use-billing";
import { useInvitations } from "@/lib/swr/use-invitations";
import useLimits from "@/lib/swr/use-limits";
import { useGetTeam } from "@/lib/swr/use-team";
@@ -51,9 +49,21 @@ export default function Billing() {
const router = useRouter();
+ const documentCountsByUser = useMemo(() => {
+ if (!team?.documents) return {};
+
+ const counts: Record<string, number> = {};
+ team.documents.forEach((document) => {
+ const ownerId = document.owner?.id;
+ if (ownerId) {
+ counts[ownerId] = (counts[ownerId] || 0) + 1;
+ }
+ });
+ return counts;
+ }, [team]);
+
const getUserDocumentCount = (userId: string) => {
- return team?.users.find((user) => user.userId === userId)?.user._count
- .documents;
+ return documentCountsByUser[userId] || 0;
};
const isCurrentUser = (userId: string) => {