2024-10-10 20:23:32 +00:00
|
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
|
|
import type { HTMLAttributes } from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
import Link from 'next/link';
|
|
|
|
|
|
|
|
|
|
|
|
import { Trans } from '@lingui/macro';
|
2024-10-11 18:43:09 +00:00
|
|
|
|
import { CheckCircle, EyeIcon, Pencil } from 'lucide-react';
|
2024-10-10 20:23:32 +00:00
|
|
|
|
import { DateTime } from 'luxon';
|
2024-10-11 18:43:09 +00:00
|
|
|
|
import { match } from 'ts-pattern';
|
2024-10-10 20:23:32 +00:00
|
|
|
|
|
2024-10-11 18:43:09 +00:00
|
|
|
|
import { type DocumentData, type Prisma, RecipientRole } from '@documenso/prisma/client';
|
2024-10-10 20:23:32 +00:00
|
|
|
|
import { SignatureIcon } from '@documenso/ui/icons/signature';
|
|
|
|
|
|
import { Button } from '@documenso/ui/primitives/button';
|
2024-10-11 18:43:09 +00:00
|
|
|
|
import {
|
|
|
|
|
|
Sheet,
|
|
|
|
|
|
SheetContent,
|
|
|
|
|
|
SheetDescription,
|
|
|
|
|
|
SheetHeader,
|
|
|
|
|
|
SheetTitle,
|
|
|
|
|
|
SheetTrigger,
|
|
|
|
|
|
} from '@documenso/ui/primitives/sheet';
|
2024-10-10 20:23:32 +00:00
|
|
|
|
|
2024-10-11 18:43:09 +00:00
|
|
|
|
import { DocumentStatus } from './document-status';
|
|
|
|
|
|
|
|
|
|
|
|
type GetNextInboxDocumentResult =
|
|
|
|
|
|
| Prisma.DocumentGetPayload<{
|
2024-10-10 20:23:32 +00:00
|
|
|
|
select: {
|
2024-10-11 18:43:09 +00:00
|
|
|
|
id: true;
|
|
|
|
|
|
createdAt: true;
|
|
|
|
|
|
title: true;
|
|
|
|
|
|
status: true;
|
|
|
|
|
|
Recipient: {
|
|
|
|
|
|
select: {
|
|
|
|
|
|
token: true;
|
|
|
|
|
|
role: true;
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
documentMeta: true;
|
2024-10-10 20:23:32 +00:00
|
|
|
|
};
|
2024-10-11 18:43:09 +00:00
|
|
|
|
}>[]
|
|
|
|
|
|
| null;
|
2024-10-10 20:23:32 +00:00
|
|
|
|
|
|
|
|
|
|
export type NextInboxItemButtonProps = HTMLAttributes<HTMLButtonElement> & {
|
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
|
documentData?: DocumentData;
|
|
|
|
|
|
userEmail: string | undefined;
|
|
|
|
|
|
nextInboxDocument: GetNextInboxDocumentResult;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const NextInboxItemButton = ({
|
|
|
|
|
|
className,
|
|
|
|
|
|
documentData,
|
|
|
|
|
|
nextInboxDocument,
|
|
|
|
|
|
userEmail,
|
|
|
|
|
|
disabled,
|
|
|
|
|
|
...props
|
|
|
|
|
|
}: NextInboxItemButtonProps) => {
|
|
|
|
|
|
return (
|
2024-10-11 18:43:09 +00:00
|
|
|
|
<Sheet>
|
|
|
|
|
|
<SheetTrigger asChild>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className={className}
|
|
|
|
|
|
disabled={disabled || !documentData || !userEmail}
|
|
|
|
|
|
{...props}
|
|
|
|
|
|
>
|
|
|
|
|
|
<SignatureIcon className="mr-2 h-5 w-5" />
|
|
|
|
|
|
<Trans>Sign Next Document</Trans>
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</SheetTrigger>
|
|
|
|
|
|
<SheetContent>
|
|
|
|
|
|
<SheetHeader>
|
|
|
|
|
|
<SheetTitle className="text-2xl">Inbox</SheetTitle>
|
|
|
|
|
|
<SheetDescription>Documents awaiting your signature or review</SheetDescription>
|
|
|
|
|
|
</SheetHeader>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="mt-8 space-y-6">
|
|
|
|
|
|
{nextInboxDocument?.map((document) => {
|
|
|
|
|
|
const recipient = document.Recipient[0];
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div key={document.id} className="flex items-center justify-between space-y-1">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="text-foreground text-lg font-semibold">{document.title}</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center gap-x-2">
|
|
|
|
|
|
<DocumentStatus status={document.status} />
|
2024-10-10 20:23:32 +00:00
|
|
|
|
|
2024-10-11 18:43:09 +00:00
|
|
|
|
{document.createdAt && (
|
|
|
|
|
|
<p className="text-muted-foreground">
|
|
|
|
|
|
<Trans>
|
|
|
|
|
|
Created {DateTime.fromJSDate(document.createdAt).toFormat('LLL ‘yy')}
|
|
|
|
|
|
</Trans>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2024-10-10 20:23:32 +00:00
|
|
|
|
|
2024-10-11 18:43:09 +00:00
|
|
|
|
<Button asChild className="w-28">
|
|
|
|
|
|
<Link href={`/sign/${recipient?.token}`}>
|
|
|
|
|
|
{match(recipient?.role)
|
|
|
|
|
|
.with(RecipientRole.SIGNER, () => (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<Pencil className="-ml-1 mr-2 h-4 w-4" />
|
|
|
|
|
|
<Trans>Sign</Trans>
|
|
|
|
|
|
</>
|
|
|
|
|
|
))
|
|
|
|
|
|
.with(RecipientRole.APPROVER, () => (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<CheckCircle className="-ml-1 mr-2 h-4 w-4" />
|
|
|
|
|
|
<Trans>Approve</Trans>
|
|
|
|
|
|
</>
|
|
|
|
|
|
))
|
|
|
|
|
|
.otherwise(() => (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<EyeIcon className="-ml-1 mr-2 h-4 w-4" />
|
|
|
|
|
|
<Trans>View</Trans>
|
|
|
|
|
|
</>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</Link>
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
2024-10-10 20:23:32 +00:00
|
|
|
|
</div>
|
2024-10-11 18:43:09 +00:00
|
|
|
|
</SheetContent>
|
|
|
|
|
|
</Sheet>
|
2024-10-10 20:23:32 +00:00
|
|
|
|
);
|
|
|
|
|
|
};
|