mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
## Description Adds the ability for the document owner to edit recipients and their fields after the document has been sent. A recipient can only be updated or deleted if: - The recipient has not inserted any fields - Has not completed the document <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added new localization messages to clarify user actions regarding document signing. - Enhanced French translations for improved user interaction. - **Improvements** - Updated localization strings in German and English for clearer feedback on signer and recipient statuses. - Improved overall structure of localization files for better maintainability. - **Dependency Updates** - Upgraded `next-axiom` and `remeda` libraries to their latest versions, potentially enhancing performance and stability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Mythie <me@lucasjamessmith.me>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { type Field, type Recipient, RecipientRole, SigningStatus } from '@documenso/prisma/client';
|
|
|
|
/**
|
|
* Whether a recipient can be modified by the document owner.
|
|
*/
|
|
export const canRecipientBeModified = (recipient: Recipient, fields: Field[]) => {
|
|
// Deny if the recipient has already signed the document.
|
|
if (!recipient || recipient.signingStatus === SigningStatus.SIGNED) {
|
|
return false;
|
|
}
|
|
|
|
// Deny if the recipient has inserted any fields.
|
|
if (fields.some((field) => field.recipientId === recipient.id && field.inserted)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
/**
|
|
* Whether a recipient can have their fields modified by the document owner.
|
|
*
|
|
* A recipient can their fields modified if all the conditions are met:
|
|
* - They are not a Viewer or CCer
|
|
* - They can be modified (canRecipientBeModified)
|
|
*/
|
|
export const canRecipientFieldsBeModified = (recipient: Recipient, fields: Field[]) => {
|
|
if (!canRecipientBeModified(recipient, fields)) {
|
|
return false;
|
|
}
|
|
|
|
return recipient.role !== RecipientRole.VIEWER && recipient.role !== RecipientRole.CC;
|
|
};
|