Skip to content

The Open Source DocuSign Alternative.

fix: data table links for recipients

Mythiea849c6431f6b
diff --git a/apps/web/src/app/(dashboard)/documents/data-table-title.tsx b/apps/web/src/app/(dashboard)/documents/data-table-title.tsx
new file mode 100644
index 000000000..c04f9f13d
--- /dev/null
+++ b/apps/web/src/app/(dashboard)/documents/data-table-title.tsx
@@ -0,0 +1,56 @@
+'use client';
+
+import Link from 'next/link';
+
+import { useSession } from 'next-auth/react';
+import { match } from 'ts-pattern';
+
+import { Document, Recipient, User } from '@documenso/prisma/client';
+
+export type DataTableTitleProps = {
+ row: Document & {
+ User: Pick<User, 'id' | 'name' | 'email'>;
+ Recipient: Recipient[];
+ };
+};
+
+export const DataTableTitle = ({ row }: DataTableTitleProps) => {
+ const { data: session } = useSession();
+
+ if (!session) {
+ return null;
+ }
+
+ const recipient = row.Recipient.find((recipient) => recipient.email === session.user.email);
+
+ const isOwner = row.User.id === session.user.id;
+ const isRecipient = !!recipient;
+
+ return match({
+ isOwner,
+ isRecipient,
+ })
+ .with({ isOwner: true }, () => (
+ <Link
+ href={`/documents/${row.id}`}
+ title={row.title}
+ className="block max-w-[10rem] truncate font-medium hover:underline md:max-w-[20rem]"
+ >
+ {row.title}
+ </Link>
+ ))
+ .with({ isRecipient: true }, () => (
+ <Link
+ href={`/sign/${recipient?.token}`}
+ title={row.title}
+ className="block max-w-[10rem] truncate font-medium hover:underline md:max-w-[20rem]"
+ >
+ {row.title}
+ </Link>
+ ))
+ .otherwise(() => (
+ <span className="block max-w-[10rem] truncate font-medium hover:underline md:max-w-[20rem]">
+ {row.title}
+ </span>
+ ));
+};
diff --git a/apps/web/src/app/(dashboard)/documents/data-table.tsx b/apps/web/src/app/(dashboard)/documents/data-table.tsx
index 1d6c08e73..245734a8e 100644
--- a/apps/web/src/app/(dashboard)/documents/data-table.tsx
+++ b/apps/web/src/app/(dashboard)/documents/data-table.tsx
@@ -2,9 +2,8 @@
import { useTransition } from 'react';
-import Link from 'next/link';
-
import { Loader } from 'lucide-react';
+import { useSession } from 'next-auth/react';
import { useUpdateSearchParams } from '@documenso/lib/client-only/hooks/use-update-search-params';
import { FindResultSet } from '@documenso/lib/types/find-result-set';
@@ -18,6 +17,7 @@ import { LocaleDate } from '~/components/formatter/locale-date';
import { DataTableActionButton } from './data-table-action-button';
import { DataTableActionDropdown } from './data-table-action-dropdown';
+import { DataTableTitle } from './data-table-title';
export type DocumentsDataTableProps = {
results: FindResultSet<
@@ -29,6 +29,7 @@ export type DocumentsDataTableProps = {
};
export const DocumentsDataTable = ({ results }: DocumentsDataTableProps) => {
+ const { data: session } = useSession();
const [isPending, startTransition] = useTransition();
const updateSearchParams = useUpdateSearchParams();
@@ -42,6 +43,10 @@ export const DocumentsDataTable = ({ results }: DocumentsDataTableProps) => {
});
};
+ if (!session) {
+ return null;
+ }
+
return (
<div className="relative">
<DataTable
@@ -52,15 +57,7 @@ export const DocumentsDataTable = ({ results }: DocumentsDataTableProps) => {
},
{
header: 'Title',
- cell: ({ row }) => (
- <Link
- href={`/documents/${row.original.id}`}
- title={row.original.title}
- className="block max-w-[10rem] truncate font-medium hover:underline md:max-w-[20rem]"
- >
- {row.original.title}
- </Link>
- ),
+ cell: ({ row }) => <DataTableTitle row={row.original} />,
},
{
header: 'Recipient',