Repository navigation
feat: send custom email to signers of direct template documents - #1215
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughRecent updates address several functional and structural changes across different modules. These involve introducing new variables, adding parameters for improved functionality, eliminating unnecessary logging, and allowing optional customization of email templates. Specifically, the changes enhance template customization, refine recipient handling, and bolster email generation, aiming to improve overall application robustness and user experience. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Frontend
participant Backend
User->>+Frontend: Initiates document creation
Frontend->>+Backend: Sends document creation request with fullName, directRecipientName
Backend->>Backend: Process document creation, updates documentMeta, logs creation
Backend-->>-Frontend: Returns document creation status
Frontend-->>-User: Displays confirmation
sequenceDiagram
participant User
participant EmailService
participant TemplateDocumentCompleted
User->>+EmailService: Document completed
EmailService->>+TemplateDocumentCompleted: Load email template with optional customBody
TemplateDocumentCompleted-->>-EmailService: Render customized email
EmailService-->>-User: Sends customized completion email
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
|
🚨 @ephraimduncan has 7 pull requests awaiting review. Please consider reviewing them when possible. 🚨 |
|
🚨 @ephraimduncan has 7 pull requests awaiting review. Please consider reviewing them when possible. 🚨 |
There was a problem hiding this comment.
Actionable comments posted: 3
Outside diff range and nitpick comments (1)
packages/email/templates/document-completed.tsx (1)
16-16: Optional prop should be last in the destructuring.For better readability, the optional
customBodyprop should be listed last in the destructuring.- downloadLink = 'https://documenso.com', documentName = 'Open Source Pledge.pdf', assetBaseUrl = 'http://localhost:3002', customBody, + customBody, downloadLink = 'https://documenso.com', documentName = 'Open Source Pledge.pdf', assetBaseUrl = 'http://localhost:3002',
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- apps/web/src/app/(recipient)/d/[token]/direct-template.tsx (2 hunks)
- packages/email/template-components/template-document-completed.tsx (2 hunks)
- packages/email/templates/document-completed.tsx (2 hunks)
- packages/lib/server-only/document/move-document-to-team.ts (1 hunks)
- packages/lib/server-only/document/send-completed-email.ts (5 hunks)
- packages/lib/server-only/template/create-document-from-direct-template.ts (5 hunks)
- packages/trpc/server/template-router/router.ts (1 hunks)
- packages/trpc/server/template-router/schema.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- packages/lib/server-only/document/move-document-to-team.ts
Additional comments not posted (13)
packages/email/templates/document-completed.tsx (1)
8-10: LGTM! But verify the usage of the new prop.The code changes are approved.
However, ensure that all usages of
DocumentCompletedEmailTemplateare updated to handle the newcustomBodyprop.Verification successful
The
customBodyprop is being utilized correctly.The
customBodyprop was found being used in theDocumentCompletedEmailTemplatecomponent in the filepackages/lib/server-only/document/send-completed-email.ts.
packages/lib/server-only/document/send-completed-email.tsScripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of `DocumentCompletedEmailTemplate` are updated to handle the new `customBody` prop. # Test: Search for the component usage. Expect: All usages handle the new `customBody` prop. rg --type tsx $'DocumentCompletedEmailTemplate'Length of output: 74
Script:
#!/bin/bash # Description: Verify all usages of `DocumentCompletedEmailTemplate` are updated to handle the new `customBody` prop. # Test: Search for the component usage. Expect: All usages handle the new `customBody` prop. rg 'DocumentCompletedEmailTemplate'Length of output: 1103
Script:
#!/bin/bash # Description: Verify if the `customBody` prop is used in the identified files where `DocumentCompletedEmailTemplate` is used. # Search for `customBody` usage in the identified files rg 'customBody' packages/email/templates/document-created-from-direct-template.tsx packages/lib/server-only/document/send-completed-email.tsLength of output: 218
packages/email/template-components/template-document-completed.tsx (1)
8-8: LGTM! But verify the usage of the new prop.The code changes are approved.
However, ensure that all usages of
TemplateDocumentCompletedare updated to handle the newcustomBodyprop.Verification successful
The new
customBodyprop is correctly handled in the codebase.
- The
customBodyprop is properly passed to theTemplateDocumentCompletedcomponent inpackages/email/templates/document-completed.tsx.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of `TemplateDocumentCompleted` are updated to handle the new `customBody` prop. # Test: Search for the component usage. Expect: All usages handle the new `customBody` prop. rg --type tsx $'TemplateDocumentCompleted'Length of output: 69
Script:
#!/bin/bash # Description: Verify all usages of `TemplateDocumentCompleted` are updated to handle the new `customBody` prop. # Test: Search for the component usage. Expect: All usages handle the new `customBody` prop. rg 'TemplateDocumentCompleted'Length of output: 1005
Script:
#!/bin/bash # Extract and review lines around the usage of `TemplateDocumentCompleted` in packages/email/templates/document-completed.tsx # Display lines around the usage of TemplateDocumentCompleted rg 'TemplateDocumentCompleted' -A 5 -B 5 packages/email/templates/document-completed.tsxLength of output: 1119
packages/trpc/server/template-router/schema.ts (1)
20-20: LGTM!The code changes are approved.
apps/web/src/app/(recipient)/d/[token]/direct-template.tsx (1)
45-45: LGTM! But verify the usage of the new parameter.The code changes are approved.
However, ensure that all usages of
createDocumentFromDirectTemplateare updated to handle the newdirectRecipientNameparameter.packages/lib/server-only/document/send-completed-email.ts (2)
7-7: LGTM!The code changes are approved.
14-14: Verify the usage of the new function.Ensure that all usages of
renderCustomEmailTemplateare correct.Verification successful
All usages of
renderCustomEmailTemplateare correct.Each usage of the
renderCustomEmailTemplatefunction passes a string as the first argument and an object as the second argument, which aligns with the function's definition.
send-completed-email.ts
- Lines: 14, 25
resend-document.tsx
- Lines: 14, 25
send-signing-email.ts
- Lines: 14, 25
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of `renderCustomEmailTemplate` are correct. # Test: Search for the function usage. Expect: All usages are correct. rg --type ts $'renderCustomEmailTemplate'Length of output: 1328
Script:
#!/bin/bash # Retrieve the definition of `renderCustomEmailTemplate` ast-grep --lang typescript --pattern $'export const renderCustomEmailTemplate = <T extends Record<string, string>>($_) => $_' packages/lib/utils/render-custom-email-template.tsLength of output: 177
Script:
#!/bin/bash # Retrieve the definition of `renderCustomEmailTemplate` with a simpler pattern ast-grep --lang typescript --pattern $'export const renderCustomEmailTemplate = $_' packages/lib/utils/render-custom-email-template.tsLength of output: 1045
Script:
#!/bin/bash # Verify the arguments passed to `renderCustomEmailTemplate` in each usage # Check usage in `send-completed-email.ts` rg --multiline --multiline-dotall --context 5 'renderCustomEmailTemplate' packages/lib/server-only/document/send-completed-email.ts # Check usage in `resend-document.tsx` rg --multiline --multiline-dotall --context 5 'renderCustomEmailTemplate' packages/lib/server-only/document/resend-document.tsx # Check usage in `send-signing-email.ts` rg --multiline --multiline-dotall --context 5 'renderCustomEmailTemplate' packages/lib/jobs/definitions/send-signing-email.tsLength of output: 4533
packages/trpc/server/template-router/router.ts (2)
62-68: EnsuredirectRecipientNameis validated.The
directRecipientNameis added as an optional field to the input schema. Ensure that the validation logic is correctly handling optional fields and that the value is properly sanitized.
73-73: Ensure backward compatibility.Adding
directRecipientNameas an optional field should not break existing functionality. Verify that the function handles cases wheredirectRecipientNameis not provided.Verification successful
Ensure backward compatibility.
Adding
directRecipientNameas an optional field does not break existing functionality. ThecreateDocumentFromDirectTemplatefunction handles cases wheredirectRecipientNameis not provided by using fallbacks and checks.
- The
directRecipientNameparameter is optional in theCreateDocumentFromDirectTemplateOptionstype.- The function assigns
directRecipientNamewith a fallback touser?.name.- Additional checks ensure that if
directRecipientNameis undefined, it is assigned a value fromsignedFieldValue.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `createDocumentFromDirectTemplate` handles cases where `directRecipientName` is not provided. # Test: Search for function usage and check for backward compatibility. Expect: No breaking changes. rg --type js --pattern 'createDocumentFromDirectTemplate'Length of output: 469
Script:
#!/bin/bash # Description: Verify that `createDocumentFromDirectTemplate` handles cases where `directRecipientName` is not provided. # Test: Search for function usage and check for backward compatibility. Expect: No breaking changes. rg 'createDocumentFromDirectTemplate'Length of output: 1016
Script:
#!/bin/bash # Description: Check the implementation of `createDocumentFromDirectTemplate` and its usages to ensure backward compatibility. # Inspect the implementation of `createDocumentFromDirectTemplate` rg -A 10 'export const createDocumentFromDirectTemplate' packages/lib/server-only/template/create-document-from-direct-template.ts # Inspect the usage in `router.ts` rg -A 10 'createDocumentFromDirectTemplate' packages/trpc/server/template-router/router.ts # Inspect the usage in `direct-template.tsx` rg -A 10 'createDocumentFromDirectTemplate' apps/web/src/app/\(recipient\)/d/\[token\]/direct-template.tsxLength of output: 3360
Script:
#!/bin/bash # Description: Check the type definition of `CreateDocumentFromDirectTemplateOptions` and the logic handling `directRecipientName`. # Inspect the type definition of `CreateDocumentFromDirectTemplateOptions` rg -A 10 'CreateDocumentFromDirectTemplateOptions' packages/lib/server-only/template/create-document-from-direct-template.ts # Inspect the function logic handling `directRecipientName` rg -A 20 'directRecipientName' packages/lib/server-only/template/create-document-from-direct-template.tsLength of output: 4257
packages/lib/server-only/template/create-document-from-direct-template.ts (5)
137-138: Ensure email message and subject are correctly set.The
metaEmailMessageandmetaEmailSubjectare set fromtemplate.templateMeta. Ensure that these values are correctly set and used in the email template.Verification successful
Verified that
metaEmailMessageandmetaEmailSubjectare correctly set and used.The
metaEmailMessageandmetaEmailSubjectare assigned fromtemplate.templateMetawith appropriate default values and are used correctly in the email template.
packages/lib/server-only/template/create-document-from-direct-template.ts:
- Lines 137-138: Assignments
- Lines 141-142: Usage
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `metaEmailMessage` and `metaEmailSubject` are correctly set and used. # Test: Search for assignment and usage of `metaEmailMessage` and `metaEmailSubject`. Expect: Correct assignment and usage. rg --type js --pattern 'metaEmailMessage|metaEmailSubject'Length of output: 472
Script:
#!/bin/bash # Description: Verify that `metaEmailMessage` and `metaEmailSubject` are correctly set and used. # Test: Search for assignment and usage of `metaEmailMessage` and `metaEmailSubject`. Expect: Correct assignment and usage. rg 'metaEmailMessage|metaEmailSubject'Length of output: 544
42-42: EnsuredirectRecipientNameis optional.The
directRecipientNamefield is added as an optional field in theCreateDocumentFromDirectTemplateOptionstype. Ensure that this field is properly handled as optional throughout the code.Verification successful
Ensure
directRecipientNameis optional.The
directRecipientNamefield is added as an optional field in theCreateDocumentFromDirectTemplateOptionstype. The following usages in thecreate-document-from-direct-template.tsfile indicate that the field is properly handled as optional:
- The field is defined as optional:
directRecipientName?: string;- Default value assignment:
const directRecipientName = user?.name || initialDirectRecipientName;- Conditional checks:
if (templateField.type === FieldType.NAME && directRecipientName === undefined) {These usages ensure that the
directRecipientNamefield is correctly managed as an optional field throughout the code.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `directRecipientName` is properly handled as an optional field. # Test: Search for usage of `CreateDocumentFromDirectTemplateOptions`. Expect: Proper handling of optional field. rg --type js --pattern 'CreateDocumentFromDirectTemplateOptions'Length of output: 476
Script:
#!/bin/bash # Description: Verify that `directRecipientName` is properly handled as an optional field. # Test: Search for usage of `CreateDocumentFromDirectTemplateOptions`. Expect: Proper handling of optional field. rg 'CreateDocumentFromDirectTemplateOptions'Length of output: 297
Script:
#!/bin/bash # Description: Verify that `directRecipientName` is properly handled as an optional field. # Test: Search for usage of `directRecipientName` within the `create-document-from-direct-template.ts` file. rg 'directRecipientName' packages/lib/server-only/template/create-document-from-direct-template.tsLength of output: 432
257-263: Ensure document metadata is correctly created.The document metadata is created with
timezone,dateFormat,message, andsubject. Ensure that these values are correctly set and used in the document creation process.Verification successful
Document metadata is correctly created and used.
The metadata fields (
timezone,dateFormat,message, andsubject) are properly assigned and utilized across the codebase.
packages/ui/primitives/document-flow/add-settings.tsxpackages/ui/primitives/document-flow/add-subject.tsxpackages/lib/server-only/template/create-document-from-direct-template.tspackages/lib/server-only/template/create-document-from-template.tspackages/app-tests/e2e/templates/create-document-from-template.spec.tsScripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that document metadata is correctly created and used. # Test: Search for assignment and usage of document metadata fields. Expect: Correct assignment and usage. rg --type js --pattern 'documentMeta'Length of output: 449
Script:
#!/bin/bash # Description: Verify that document metadata is correctly created and used. # Test: Search for assignment and usage of document metadata fields. Expect: Correct assignment and usage. rg 'documentMeta'Length of output: 10193
115-115: EnsuredirectRecipientNameis correctly set.The
directRecipientNameis set touser?.nameorinitialDirectRecipientName. Ensure that this logic correctly handles cases where both values are undefined.Verification successful
Verification Successful:
directRecipientNameis correctly set.The logic for setting
directRecipientNameusinguser?.name || initialDirectRecipientNamecorrectly handles cases where both values are undefined. The subsequent usage ofdirectRecipientNameis consistent with this assignment.
- Location:
packages/lib/server-only/template/create-document-from-direct-template.tsScripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `directRecipientName` is correctly set and used. # Test: Search for assignment and usage of `directRecipientName`. Expect: Correct assignment and usage. rg --type js --pattern 'directRecipientName'Length of output: 456
Script:
#!/bin/bash # Description: Verify that `directRecipientName` is correctly set and used. # Test: Search for assignment and usage of `directRecipientName`. Expect: Correct assignment and usage. rg 'directRecipientName'Length of output: 1149
Script:
#!/bin/bash # Description: Extract lines around the occurrences of `directRecipientName` in `create-document-from-direct-template.ts` for detailed inspection. # Extract lines around the occurrences of `directRecipientName` in the specified file. rg -A 3 -B 3 'directRecipientName' packages/lib/server-only/template/create-document-from-direct-template.tsLength of output: 1443
61-61: EnsureinitialDirectRecipientNameis correctly assigned.The
initialDirectRecipientNameis derived fromdirectRecipientNameor set to 'Default Name'. Ensure that this assignment logic is correct and does not introduce any bugs.
….tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/email/template-components/template-document-completed.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/email/template-components/template-document-completed.tsx
There was a problem hiding this comment.
Actionable comments posted: 0
Outside diff range and nitpick comments (2)
packages/lib/server-only/document/send-completed-email.ts (2)
44-44: Consider extracting the condition to a variable.For better readability, consider extracting the
isDirectTemplatecondition to a variable.- const isDirectTemplate = document?.source === DocumentSource.TEMPLATE_DIRECT_LINK; + const isDirectTemplate = document.source === DocumentSource.TEMPLATE_DIRECT_LINK;
114-119: Consider moving the custom email template data to a separate function.For better readability and maintainability, consider moving the custom email template data creation to a separate function.
- const customEmailTemplate = { - 'signer.name': recipient.name, - 'signer.email': recipient.email, - 'document.name': document.title, - }; + const customEmailTemplate = createCustomEmailTemplateData(recipient, document);function createCustomEmailTemplateData(recipient, document) { return { 'signer.name': recipient.name, 'signer.email': recipient.email, 'document.name': document.title, }; }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/lib/server-only/document/send-completed-email.ts (5 hunks)
Additional comments not posted (5)
packages/lib/server-only/document/send-completed-email.ts (5)
7-7: ImportDocumentSourceis used correctly.The
DocumentSourceimport is used to check if the document is a direct template.
14-14: ImportrenderCustomEmailTemplateis used correctly.The
renderCustomEmailTemplateimport is used to render custom email templates.
28-28: EnsuredocumentMetais populated correctly.The inclusion of
documentMetain theprisma.document.findUniquequery is necessary for accessing custom email metadata.
126-129: Ensure custom email body rendering is correct.The custom email body is rendered correctly based on the
isDirectTemplatecondition.
143-146: Ensure custom email subject rendering is correct.The custom email subject is rendered correctly based on the
isDirectTemplatecondition.
Description
Introduces customization options for the document completion email template to allow for custom email bodies and subjects for documents created from direct templates.
Testing Performed
Checklist
Summary by CodeRabbit
New Features
customBodyprop in email templates, allowing for custom messages in email notifications.Bug Fixes
Refactor