mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
40 lines
879 B
TypeScript
40 lines
879 B
TypeScript
import type { User } from '@prisma/client';
|
|
|
|
import type { EnvelopeWithRecipients } from '@documenso/prisma/types/document-with-recipient';
|
|
|
|
export type MaskRecipientTokensForDocumentOptions<T extends EnvelopeWithRecipients> = {
|
|
document: T;
|
|
user?: Pick<User, 'id' | 'email'>;
|
|
token?: string;
|
|
};
|
|
|
|
export const maskRecipientTokensForDocument = <T extends EnvelopeWithRecipients>({
|
|
document,
|
|
user,
|
|
token,
|
|
}: MaskRecipientTokensForDocumentOptions<T>) => {
|
|
const maskedRecipients = document.recipients.map((recipient) => {
|
|
if (document.userId === user?.id) {
|
|
return recipient;
|
|
}
|
|
|
|
if (recipient.email === user?.email) {
|
|
return recipient;
|
|
}
|
|
|
|
if (recipient.token === token) {
|
|
return recipient;
|
|
}
|
|
|
|
return {
|
|
...recipient,
|
|
token: '',
|
|
};
|
|
});
|
|
|
|
return {
|
|
...document,
|
|
Recipient: maskedRecipients,
|
|
};
|
|
};
|