Skip to content

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

fix: visitorgroup on the team

Marc Seitz44ebb5500b63
diff --git a/components/visitors/visitor-group-modal.tsx b/components/visitors/visitor-group-modal.tsx
index 01954769..0766fcec 100644
--- a/components/visitors/visitor-group-modal.tsx
+++ b/components/visitors/visitor-group-modal.tsx
@@ -106,7 +106,6 @@ export function VisitorGroupModal({
if (!response.ok) {
const data = await response.json();
toast.error(data.error || "Failed to save visitor group.");
- setLoading(false);
return;
}
@@ -122,11 +121,11 @@ export function VisitorGroupModal({
if (existingGroup) {
mutate(`/api/teams/${teamId}/visitor-groups/${existingGroup.id}`);
}
+ setOpen(false);
} catch (error) {
toast.error("Error saving visitor group. Please try again.");
} finally {
setLoading(false);
- setOpen(false);
}
};
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index 7cd7b0ca..c59d0a5f 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -322,6 +322,23 @@ export default async function handle(
}
}
+ // Validate visitor group IDs belong to this team
+ if (linkData.visitorGroupIds?.length > 0) {
+ const validGroups = await prisma.visitorGroup.findMany({
+ where: {
+ id: { in: linkData.visitorGroupIds },
+ teamId: teamId,
+ },
+ select: { id: true },
+ });
+
+ if (validGroups.length !== linkData.visitorGroupIds.length) {
+ return res.status(400).json({
+ error: "One or more visitor group IDs do not belong to this team.",
+ });
+ }
+ }
+
const updatedLink = await prisma.$transaction(async (tx) => {
const link = await tx.link.update({
where: { id, teamId },
@@ -487,7 +504,13 @@ export default async function handle(
},
});
- return { ...link, tags };
+ // Re-fetch visitor groups to get post-update associations
+ const freshVisitorGroups = await tx.linkVisitorGroup.findMany({
+ where: { linkId: id },
+ select: { visitorGroupId: true },
+ });
+
+ return { ...link, visitorGroups: freshVisitorGroups, tags };
});
if (!updatedLink) {
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index 1a80ba9e..7302e08a 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -156,6 +156,24 @@ export default async function handler(
}
}
+ // Validate visitor group IDs belong to this team
+ if (linkData.visitorGroupIds?.length > 0) {
+ const validGroups = await prisma.visitorGroup.findMany({
+ where: {
+ id: { in: linkData.visitorGroupIds },
+ teamId: teamId,
+ },
+ select: { id: true },
+ });
+
+ if (validGroups.length !== linkData.visitorGroupIds.length) {
+ return res.status(400).json({
+ error:
+ "One or more visitor group IDs do not belong to this team.",
+ });
+ }
+ }
+
// Fetch the link and its related document from the database
const updatedLink = await prisma.$transaction(async (tx) => {
const link = await tx.link.create({