From 08d3d6a80a8b1de82ccb78921567d864e691db3f Mon Sep 17 00:00:00 2001 From: Mythie Date: Tue, 31 Dec 2024 14:54:19 +1100 Subject: [PATCH] fix: improve recipient status display Improves the display of the recipients status when distribution method is set to none. Previously we had a ton of checks for sendStatus = SENT which will never trigger when distributing manually causing some confusion. --- packages/lib/client-only/recipient-type.ts | 20 ++++++++++++------- .../server-only/document/viewed-document.ts | 4 +++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/lib/client-only/recipient-type.ts b/packages/lib/client-only/recipient-type.ts index 627765dff..ddce3e20f 100644 --- a/packages/lib/client-only/recipient-type.ts +++ b/packages/lib/client-only/recipient-type.ts @@ -1,5 +1,11 @@ import type { Recipient } from '@documenso/prisma/client'; -import { ReadStatus, RecipientRole, SendStatus, SigningStatus } from '@documenso/prisma/client'; +import { + DocumentDistributionMethod, + ReadStatus, + RecipientRole, + SendStatus, + SigningStatus, +} from '@documenso/prisma/client'; export enum RecipientStatusType { COMPLETED = 'completed', @@ -9,11 +15,11 @@ export enum RecipientStatusType { REJECTED = 'rejected', } -export const getRecipientType = (recipient: Recipient) => { - if ( - recipient.role === RecipientRole.CC || - (recipient.sendStatus === SendStatus.SENT && recipient.signingStatus === SigningStatus.SIGNED) - ) { +export const getRecipientType = ( + recipient: Recipient, + distributionMethod: DocumentDistributionMethod = DocumentDistributionMethod.EMAIL, +) => { + if (recipient.role === RecipientRole.CC || recipient.signingStatus === SigningStatus.SIGNED) { return RecipientStatusType.COMPLETED; } @@ -22,7 +28,6 @@ export const getRecipientType = (recipient: Recipient) => { } if ( - recipient.sendStatus === SendStatus.SENT && recipient.readStatus === ReadStatus.OPENED && recipient.signingStatus === SigningStatus.NOT_SIGNED ) { @@ -30,6 +35,7 @@ export const getRecipientType = (recipient: Recipient) => { } if ( + distributionMethod === DocumentDistributionMethod.EMAIL && recipient.sendStatus === SendStatus.SENT && recipient.signingStatus === SigningStatus.NOT_SIGNED ) { diff --git a/packages/lib/server-only/document/viewed-document.ts b/packages/lib/server-only/document/viewed-document.ts index 7d20c9521..b20dc9412 100644 --- a/packages/lib/server-only/document/viewed-document.ts +++ b/packages/lib/server-only/document/viewed-document.ts @@ -2,7 +2,7 @@ import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-log import type { RequestMetadata } from '@documenso/lib/universal/extract-request-metadata'; import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs'; import { prisma } from '@documenso/prisma'; -import { ReadStatus } from '@documenso/prisma/client'; +import { ReadStatus, SendStatus } from '@documenso/prisma/client'; import { WebhookTriggerEvents } from '@documenso/prisma/client'; import type { TDocumentAccessAuthTypes } from '../../types/document-auth'; @@ -39,6 +39,8 @@ export const viewedDocument = async ({ id: recipient.id, }, data: { + // This handles cases where distribution is done manually + sendStatus: SendStatus.SENT, readStatus: ReadStatus.OPENED, }, });