mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +10:00
chore: self-review
This commit is contained in:
@ -5,14 +5,11 @@ import Link from 'next/link';
|
|||||||
import { Edit } from 'lucide-react';
|
import { Edit } from 'lucide-react';
|
||||||
import { useSession } from 'next-auth/react';
|
import { useSession } from 'next-auth/react';
|
||||||
|
|
||||||
import { Document, Recipient, User } from '@documenso/prisma/client';
|
import { Document } from '@documenso/prisma/client';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
|
||||||
export type DataTableActionButtonProps = {
|
export type DataTableActionButtonProps = {
|
||||||
row: Document & {
|
row: Pick<Document, 'id'>;
|
||||||
User: Pick<User, 'id' | 'name' | 'email'>;
|
|
||||||
Recipient: Recipient[];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DataTableActionButton = ({ row }: DataTableActionButtonProps) => {
|
export const DataTableActionButton = ({ row }: DataTableActionButtonProps) => {
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import {
|
|||||||
export type DataTableActionDropdownProps = {
|
export type DataTableActionDropdownProps = {
|
||||||
row: Document & {
|
row: Document & {
|
||||||
User: Pick<User, 'id' | 'name' | 'email'>;
|
User: Pick<User, 'id' | 'name' | 'email'>;
|
||||||
Recipient: Recipient[];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -29,7 +28,6 @@ export const DataTableActionDropdown = ({ row }: DataTableActionDropdownProps) =
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const recipient = row.Recipient.find((recipient) => recipient.email === session.user.email);
|
|
||||||
// const isRecipient = !!recipient;
|
// const isRecipient = !!recipient;
|
||||||
// const isDraft = row.status === DocumentStatus.DRAFT;
|
// const isDraft = row.status === DocumentStatus.DRAFT;
|
||||||
// const isPending = row.status === DocumentStatus.PENDING;
|
// const isPending = row.status === DocumentStatus.PENDING;
|
||||||
@ -39,15 +37,9 @@ export const DataTableActionDropdown = ({ row }: DataTableActionDropdownProps) =
|
|||||||
const onDownloadClick = async () => {
|
const onDownloadClick = async () => {
|
||||||
let document: DocumentWithData | null = null;
|
let document: DocumentWithData | null = null;
|
||||||
|
|
||||||
if (!recipient) {
|
document = await trpc.document.getDocumentById.query({
|
||||||
document = await trpc.document.getDocumentById.query({
|
id: row.id,
|
||||||
id: row.id,
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
document = await trpc.document.getDocumentByToken.query({
|
|
||||||
token: recipient.token,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const documentData = document?.documentData;
|
const documentData = document?.documentData;
|
||||||
|
|
||||||
|
|||||||
@ -1,56 +0,0 @@
|
|||||||
'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>
|
|
||||||
));
|
|
||||||
};
|
|
||||||
@ -19,7 +19,6 @@ import { LocaleDate } from '~/components/formatter/locale-date';
|
|||||||
|
|
||||||
import { DataTableActionButton } from './data-table-action-button';
|
import { DataTableActionButton } from './data-table-action-button';
|
||||||
import { DataTableActionDropdown } from './data-table-action-dropdown';
|
import { DataTableActionDropdown } from './data-table-action-dropdown';
|
||||||
import { DataTableTitle } from './data-table-title';
|
|
||||||
|
|
||||||
export type DocumentsDataTableProps = {
|
export type DocumentsDataTableProps = {
|
||||||
results: FindResultSet<
|
results: FindResultSet<
|
||||||
@ -60,7 +59,18 @@ export const DocumentsDataTable = ({ results }: DocumentsDataTableProps) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Title',
|
header: 'Title',
|
||||||
cell: ({ row }) => <DataTableTitle row={row.original} />,
|
accessorKey: 'title',
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
title={row.original.title}
|
||||||
|
className="block max-w-[10rem] truncate font-medium hover:underline md:max-w-[20rem]"
|
||||||
|
href={`/documents/${row.original.id}`}
|
||||||
|
>
|
||||||
|
{row.original.title}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Owner',
|
header: 'Owner',
|
||||||
|
|||||||
Reference in New Issue
Block a user