2023-06-09 18:21:18 +10:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useTransition } from 'react';
|
|
|
|
|
|
|
|
|
|
import Link from 'next/link';
|
|
|
|
|
|
|
|
|
|
import { Loader } from 'lucide-react';
|
|
|
|
|
|
|
|
|
|
import { useUpdateSearchParams } from '@documenso/lib/client-only/hooks/use-update-search-params';
|
|
|
|
|
import { FindResultSet } from '@documenso/lib/types/find-result-set';
|
2023-06-30 23:49:34 +00:00
|
|
|
import { DocumentWithReciepient } from '@documenso/prisma/types/document-with-recipient';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { DataTable } from '@documenso/ui/primitives/data-table';
|
|
|
|
|
import { DataTablePagination } from '@documenso/ui/primitives/data-table-pagination';
|
|
|
|
|
|
2023-06-25 15:14:48 +00:00
|
|
|
import { StackAvatarsWithTooltip } from '~/components/(dashboard)/avatar/stack-avatars-with-tooltip';
|
2023-06-09 18:21:18 +10:00
|
|
|
import { DocumentStatus } from '~/components/formatter/document-status';
|
|
|
|
|
import { LocaleDate } from '~/components/formatter/locale-date';
|
|
|
|
|
|
|
|
|
|
export type DocumentsDataTableProps = {
|
2023-06-25 15:14:48 +00:00
|
|
|
results: FindResultSet<DocumentWithReciepient>;
|
2023-06-09 18:21:18 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const DocumentsDataTable = ({ results }: DocumentsDataTableProps) => {
|
|
|
|
|
const [isPending, startTransition] = useTransition();
|
|
|
|
|
|
|
|
|
|
const updateSearchParams = useUpdateSearchParams();
|
|
|
|
|
|
|
|
|
|
const onPaginationChange = (page: number, perPage: number) => {
|
|
|
|
|
startTransition(() => {
|
|
|
|
|
updateSearchParams({
|
|
|
|
|
page,
|
|
|
|
|
perPage,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="relative">
|
|
|
|
|
<DataTable
|
|
|
|
|
columns={[
|
|
|
|
|
{
|
|
|
|
|
header: 'ID',
|
|
|
|
|
accessorKey: 'id',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
header: 'Title',
|
|
|
|
|
cell: ({ row }) => (
|
|
|
|
|
<Link href={`/documents/${row.original.id}`} className="font-medium hover:underline">
|
|
|
|
|
{row.original.title}
|
|
|
|
|
</Link>
|
|
|
|
|
),
|
|
|
|
|
},
|
2023-06-25 15:14:48 +00:00
|
|
|
{
|
|
|
|
|
header: 'Recipient',
|
|
|
|
|
accessorKey: 'recipient',
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
return <StackAvatarsWithTooltip recipients={row.original.Recipient} />;
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-09 18:21:18 +10:00
|
|
|
{
|
|
|
|
|
header: 'Status',
|
|
|
|
|
accessorKey: 'status',
|
|
|
|
|
cell: ({ row }) => <DocumentStatus status={row.getValue('status')} />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
header: 'Created',
|
|
|
|
|
accessorKey: 'created',
|
|
|
|
|
cell: ({ row }) => <LocaleDate date={row.getValue('created')} />,
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
data={results.data}
|
|
|
|
|
perPage={results.perPage}
|
|
|
|
|
currentPage={results.currentPage}
|
|
|
|
|
totalPages={results.totalPages}
|
|
|
|
|
onPaginationChange={onPaginationChange}
|
|
|
|
|
>
|
|
|
|
|
{(table) => <DataTablePagination table={table} />}
|
|
|
|
|
</DataTable>
|
|
|
|
|
|
|
|
|
|
{isPending && (
|
|
|
|
|
<div className="absolute inset-0 flex items-center justify-center bg-white/50">
|
|
|
|
|
<Loader className="h-8 w-8 animate-spin text-gray-500" />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|