import { Trans } from '@lingui/react/macro'; import { ReadStatus, RecipientRole, SigningStatus } from '@prisma/client'; import { ArrowRight, EyeIcon, XCircle } from 'lucide-react'; import { match } from 'ts-pattern'; import type { DocumentAndSender } from '@documenso/lib/server-only/document/get-document-by-token'; import type { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token'; import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert'; import { Badge } from '@documenso/ui/primitives/badge'; import { Button } from '@documenso/ui/primitives/button'; import { Progress } from '@documenso/ui/primitives/progress'; // Get the return type from getRecipientByToken type RecipientWithFields = Awaited>; interface DocumentEnvelope { document: DocumentAndSender; recipient: RecipientWithFields; } interface MultiSignDocumentListProps { envelopes: DocumentEnvelope[]; onDocumentSelect: (document: DocumentEnvelope['document']) => void; } export function MultiSignDocumentList({ envelopes, onDocumentSelect }: MultiSignDocumentListProps) { // Calculate progress const completedDocuments = envelopes.filter( (envelope) => envelope.recipient.signingStatus === SigningStatus.SIGNED, ); const totalDocuments = envelopes.length; const progressPercentage = (completedDocuments.length / totalDocuments) * 100; // Find next document to sign (first one that's not signed and not rejected) const nextDocumentToSign = envelopes.find( (envelope) => envelope.recipient.signingStatus !== SigningStatus.SIGNED && envelope.recipient.signingStatus !== SigningStatus.REJECTED, ); const allDocumentsCompleted = completedDocuments.length === totalDocuments; const hasAssistantOrCcRecipient = envelopes.some( (envelope) => envelope.recipient.role === RecipientRole.ASSISTANT || envelope.recipient.role === RecipientRole.CC, ); function handleView(doc: DocumentEnvelope['document']) { onDocumentSelect(doc); } function handleNextDocument() { if (nextDocumentToSign) { onDocumentSelect(nextDocumentToSign.document); } } if (hasAssistantOrCcRecipient) { return (

It looks like we ran into an issue!

One of the documents in the current bundle has a signing role that is not compatible with the current signing experience.

Assistants and Copy roles are currently not compatible with the multi-sign experience.

Please contact the site owner for further assistance.

); } return (

Sign Documents

You have been requested to sign the following documents. Review each document carefully and complete the signing process.

{/* Progress Section */}
Progress {completedDocuments.length} of {totalDocuments} completed
{envelopes.map((envelope) => (
{envelope.document.title} {match(envelope.recipient) .with({ signingStatus: SigningStatus.SIGNED }, () => ( Completed )) .with({ signingStatus: SigningStatus.REJECTED }, () => ( Rejected )) .with({ readStatus: ReadStatus.OPENED }, () => ( Viewed )) .otherwise(() => null)}
))}
{/* Next Document Button */} {!allDocumentsCompleted && nextDocumentToSign && (
)} {allDocumentsCompleted && ( All documents have been completed! Thank you for completing the signing process. )}
); }