Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat(group): add mutation to group link tables
Marc Seitz06d00a5a3a1b
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsxindex 9b3ae436..ff7cbe7b 100644--- a/components/links/link-sheet/index.tsx+++ b/components/links/link-sheet/index.tsx@@ -255,9 +255,64 @@ export default function LinkSheet({),false,);++ // Handle group changes+ if (!!groupId && returnedLink.audienceType === LinkAudienceType.GROUP) {+ // If we're viewing a group page+ if (currentLink.groupId !== returnedLink.groupId) {+ // If the link's group has changed+ if (currentLink.groupId === groupId) {+ // If the link was in the current group but is now in a different group+ // Remove it from the current group's view+ const groupLinks =+ existingLinks?.filter(+ (link) =>+ link.id !== currentLink.id && link.groupId === groupId,+ ) || [];++ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}/${encodeURIComponent(+ targetId,+ )}/groups/${groupId}/links`,+ groupLinks,+ false,+ );+ } else if (returnedLink.groupId === groupId) {+ // If the link was in a different group but is now in the current group+ // Add it to the current group's view+ const groupLinks =+ existingLinks?.filter((link) => link.groupId === groupId) || [];++ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}/${encodeURIComponent(+ targetId,+ )}/groups/${groupId}/links`,+ [returnedLink, ...groupLinks],+ false,+ );+ }+ } else if (returnedLink.groupId === groupId) {+ // If the link's group hasn't changed and it's in the current group+ // Update it in the current group's view+ const groupLinks =+ existingLinks?.filter((link) => link.groupId === groupId) || [];++ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}/${encodeURIComponent(+ targetId,+ )}/groups/${groupId}/links`,+ groupLinks.map((link) =>+ link.id === currentLink.id ? returnedLink : link,+ ),+ false,+ );+ }+ }+toast.success("Link updated successfully");} else {setIsOpen(false);+// Add the new link to the list of linksmutate(`/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}/${encodeURIComponent(@@ -267,6 +322,23 @@ export default function LinkSheet({false,);+ // Also update the group-specific links cache if this is a group link+ if (+ !!groupId &&+ returnedLink.audienceType === LinkAudienceType.GROUP &&+ returnedLink.groupId === groupId+ ) {+ const groupLinks =+ existingLinks?.filter((link) => link.groupId === groupId) || [];+ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}/${encodeURIComponent(+ targetId,+ )}/groups/${groupId}/links`,+ [returnedLink, ...groupLinks],+ false,+ );+ }+analytics.capture("Link Added", {linkId: returnedLink.id,targetId,diff --git a/components/links/links-table.tsx b/components/links/links-table.tsxindex 492b5195..60e3231f 100644--- a/components/links/links-table.tsx+++ b/components/links/links-table.tsx@@ -4,7 +4,7 @@ import { useMemo, useState } from "react";import { useTeam } from "@/context/team-context";import { PlanEnum } from "@/ee/stripe/constants";-import { DocumentVersion } from "@prisma/client";+import { DocumentVersion, LinkAudienceType } from "@prisma/client";import { isWithinInterval, subMinutes } from "date-fns";import {ArchiveIcon,@@ -230,6 +230,19 @@ export default function LinksTable({false,);+ // Update the group-specific links cache if this is a group link+ if (!!groupId) {+ const groupLinks =+ links?.filter((link) => link.groupId === groupId) || [];+ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}/${encodeURIComponent(+ duplicatedLink.documentId ?? duplicatedLink.dataroomId ?? "",+ )}/groups/${duplicatedLink.groupId}/links`,+ groupLinks.concat(duplicatedLink),+ false,+ );+ }+toast.success("Link duplicated successfully");setIsLoading(false);};@@ -282,13 +295,20 @@ export default function LinksTable({(links || []).map((link) => (link.id === linkId ? archivedLink : link)),false,);- mutate(- `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${encodeURIComponent(- targetId,- )}/groups/${groupId}/links`,- (links || []).map((link) => (link.id === linkId ? archivedLink : link)),- false,- );++ // Update the group-specific links cache if this is a group link+ if (!!groupId) {+ const groupLinks =+ links?.filter((link) => link.groupId === groupId) || [];+ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/${endpointTargetType}/${encodeURIComponent(+ archivedLink.documentId ?? archivedLink.dataroomId ?? "",+ )}/groups/${groupId}/links`,+ groupLinks.map((link) => (link.id === linkId ? archivedLink : link)),+ false,+ );+ }+toast.success(!isArchived? "Link successfully archived"@@ -306,7 +326,7 @@ export default function LinksTable({return (<><div className="w-full">- <div>+ <div className={cn(targetType === "DATAROOM" && "hidden")}><h2 className="mb-2 md:mb-4">All links</h2></div><div className="rounded-md border">