Files
sign/apps/remix/app/components/tables/documents-table-title.tsx

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-01-02 15:33:37 +11:00
import type { Document, Recipient, Team, User } from '@prisma/client';
import { Link } from 'react-router';
2023-09-12 10:37:47 +10:00
import { match } from 'ts-pattern';
2025-01-02 15:33:37 +11:00
import { useSession } from '@documenso/lib/client-only/providers/session';
2024-02-12 19:00:47 +11:00
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
2023-09-12 10:37:47 +10:00
export type DataTableTitleProps = {
row: Document & {
2025-01-13 13:41:53 +11:00
user: Pick<User, 'id' | 'name' | 'email'>;
2024-02-12 19:00:47 +11:00
team: Pick<Team, 'url'> | null;
2025-01-13 13:41:53 +11:00
recipients: Recipient[];
2023-09-12 10:37:47 +10:00
};
2024-02-12 19:00:47 +11:00
teamUrl?: string;
2023-09-12 10:37:47 +10:00
};
2024-02-12 19:00:47 +11:00
export const DataTableTitle = ({ row, teamUrl }: DataTableTitleProps) => {
2025-01-02 15:33:37 +11:00
const { user } = useSession();
2023-09-12 10:37:47 +10:00
2025-01-02 15:33:37 +11:00
const recipient = row.recipients.find((recipient) => recipient.email === user.email);
2023-09-12 10:37:47 +10:00
2025-01-02 15:33:37 +11:00
const isOwner = row.user.id === user.id;
2023-09-12 10:37:47 +10:00
const isRecipient = !!recipient;
2024-02-12 19:00:47 +11:00
const isCurrentTeamDocument = teamUrl && row.team?.url === teamUrl;
const documentsPath = formatDocumentsPath(isCurrentTeamDocument ? teamUrl : undefined);
2023-09-12 10:37:47 +10:00
return match({
isOwner,
isRecipient,
2024-02-12 19:00:47 +11:00
isCurrentTeamDocument,
2023-09-12 10:37:47 +10:00
})
2024-02-12 19:00:47 +11:00
.with({ isOwner: true }, { isCurrentTeamDocument: true }, () => (
2023-09-12 10:37:47 +10:00
<Link
2025-01-02 15:33:37 +11:00
to={`${documentsPath}/${row.id}`}
2023-09-12 10:37:47 +10:00
title={row.title}
className="block max-w-[10rem] truncate font-medium hover:underline md:max-w-[20rem]"
>
{row.title}
</Link>
))
.with({ isRecipient: true }, () => (
<Link
2025-01-02 15:33:37 +11:00
to={`/sign/${recipient?.token}`}
2023-09-12 10:37:47 +10:00
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>
));
};