Skip to content

feat: allow editing pending documents - #1346

Merged
dguyen merged 3 commits into
mainfrom
feat/document-pending-edit
Sep 20, 2024
Merged

dguyen merged 3 commits into
mainfrom
feat/document-pending-edit

Conversation

@dguyen

@dguyen dguyen commented Sep 13, 2024 •

Copy link
Copy Markdown
Collaborator

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

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.

@vercel

vercel Bot commented Sep 13, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
prd-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2024 3:40am
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2024 3:40am
stg-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2024 3:40am
stg-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 20, 2024 3:40am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Sep 20, 2024 3:40am
prd-marketing ⬜️ Ignored (Inspect) Sep 20, 2024 3:40am

@coderabbitai

coderabbitai Bot commented Sep 13, 2024 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request includes updates to the next-axiom and remeda dependencies in the package.json files for both the marketing and web applications. Additionally, it features modifications to localization strings across multiple languages, enhancing clarity and user feedback regarding document signing processes. New messages have been added to improve user interactions, and existing messages have been adjusted for better alignment with the application’s functionality.

Changes

File Path Change Summary
apps/marketing/package.json, apps/web/package.json Updated next-axiom from ^1.1.1 to ^1.5.1 and remeda from ^1.27.1 to ^2.12.1 in respective package.json files.
packages/lib/translations/de/common.po, packages/lib/translations/fr/common.po, packages/lib/translations/en/common.po Updated localization strings for clarity and reorganization, including new messages regarding signer and recipient statuses.
packages/lib/translations/de/marketing.js, packages/lib/translations/en/marketing.js, packages/lib/translations/fr/marketing.js Reformatted and updated JSON structures for marketing messages, enhancing clarity and correcting errors, with new key-value pairs added for improved localization.
packages/ui/primitives/document-flow/add-fields.tsx, packages/ui/primitives/document-flow/add-signers.tsx Introduced new messages regarding recipient modifiability and signer status, improving logic and user feedback in the document flow.

Possibly related PRs

  • fix: show field on pending document #1158: This PR updates the next-axiom dependency in the web application, similar to the main PR which also updates next-axiom in the marketing application.
  • feat: signing order #1290: This PR introduces a feature related to document signing, which may indirectly relate to the updates in dependencies that could affect document handling.
  • chore: add translations #1327: This PR adds translations, which may be relevant as the main PR updates a dependency that could impact localization features.
  • feat: add language switcher #1337: This PR enhances internationalization features, which could be related to the updates in the main PR that involve dependencies affecting language support.
  • feat: add french #1355: This PR adds French translations, which aligns with the internationalization efforts mentioned in the main PR's updates to dependencies.

Suggested labels

🚨 migrations 🚨

Poem

🐰 In the fields of code, where updates play,
New versions hop in, brightening the day.
With messages clearer and translations anew,
Our app dances forward, refreshed and true!
So let’s celebrate changes, both big and small,
For each little tweak makes our journey a ball! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b62dfdc and 127f714.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (7)
  • apps/marketing/package.json (2 hunks)
  • apps/web/package.json (3 hunks)
  • packages/lib/translations/de/common.po (21 hunks)
  • packages/lib/translations/de/marketing.js (1 hunks)
  • packages/lib/translations/en/marketing.js (1 hunks)
  • packages/lib/translations/fr/common.po (21 hunks)
  • packages/lib/translations/fr/marketing.js (1 hunks)
Files skipped from review due to trivial changes (2)
  • apps/marketing/package.json
  • packages/lib/translations/de/marketing.js
Files skipped from review as they are similar to previous changes (3)
  • apps/web/package.json
  • packages/lib/translations/de/common.po
  • packages/lib/translations/en/marketing.js
Additional comments not posted (11)
packages/lib/translations/fr/marketing.js (1)

1-1: LGTM!

The code segment exports a valid JSON object containing French translations. The changes look good.

packages/lib/translations/fr/common.po (10)

85-85: LGTM!

The French translation for "Add myself" looks good.


97-97: LGTM!

The French translation for "Add Signer" looks good.


118-118: LGTM!

The French translation for "Advanced settings" looks good.


156-156: LGTM!

The French translation for "Cannot remove signer" looks good.


177-177: LGTM!

The French translation for "Checkbox" looks good.


206-206: LGTM!

The French translation for "Configure the {0} field" looks good. The placeholder {0} is correctly used.


223-223: LGTM!

The French translation for "Date" looks good.


255-255: LGTM!

The French translation for "Dropdown" looks good.


Line range hint 264-270: LGTM!

The French translation for "Email" looks good and is consistently used across multiple places.


281-281: LGTM!

The French translation for "Enable signing order" looks good.


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions

github-actions Bot commented Sep 13, 2024 •

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions for pull request titles! 💚🚀

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 27

Outside diff range and nitpick comments (14)
packages/lib/utils/recipients.ts (2)

1-1: Ensure consistent import style across the codebase.

Consider using a consistent import style for the @documenso/prisma/client module throughout the codebase. If the codebase predominantly uses named imports, consider updating this import statement to match that style.

-import { type Field, type Recipient, RecipientRole, SigningStatus } from '@documenso/prisma/client';
+import { Field, Recipient, RecipientRole, SigningStatus } from '@documenso/prisma/client';

1-33: Consider adding unit tests.

To ensure the correctness and maintainability of these utility functions, it would be beneficial to add unit tests that cover various scenarios and edge cases. This will help catch any potential issues and serve as documentation for the expected behavior.

packages/ee/server-only/limits/provider/client.tsx (1)

Line range hint 1-78: Consider memoizing the refreshLimits function.

The refreshLimits function is recreated on every render due to its dependency on teamId. This could potentially lead to unnecessary re-creation of the function, especially if teamId remains stable.

To optimize this, consider memoizing refreshLimits using useCallback and providing teamId as a dependency. This way, refreshLimits will only be recreated when teamId changes.

Apply this diff to memoize refreshLimits:

const refreshLimits = useCallback(async () => {
    const newLimits = await getLimits({ teamId });

    setLimits((oldLimits) => {
      if (isDeepEqual(oldLimits, newLimits)) {
        return oldLimits;
      }

      return newLimits;
    });
- }, []);
+ }, [teamId]);
apps/web/package.json (1)

Line range hint 1-77: Consider adding or updating tests.

Given the dependency upgrades in this pull request, it's crucial to ensure that the existing tests continue to pass and that new tests are added to cover any new functionality or changes introduced by the updated libraries.

  • Review the existing test suite and update any tests that may be affected by the upgraded dependencies.
  • Consider adding new tests to verify the behavior and compatibility of the updated libraries within the application.
  • Run the test suite to ensure that all tests pass successfully with the updated dependencies.

Thorough testing will help maintain the stability and reliability of the application after the dependency upgrades.

packages/email/templates/recipient-removed-from-document.tsx (3)

19-19: Consider renaming the type for consistency.

The type DocumentCancelEmailTemplateProps seems to be specific to the RecipientRemovedFromDocumentTemplate component. Consider renaming it to RecipientRemovedFromDocumentTemplateProps for better consistency and clarity.

-export type DocumentCancelEmailTemplateProps = Partial<TemplateDocumentCancelProps>;
+export type RecipientRemovedFromDocumentTemplateProps = Partial<TemplateDocumentCancelProps>;

28-30: Consider using a more robust URL constructor.

The current implementation of getAssetUrl relies on the URL constructor, which may not handle all edge cases properly. Consider using a more robust library like url-parse or url-join to construct the asset URLs.

-  const getAssetUrl = (path: string) => {
-    return new URL(path, assetBaseUrl).toString();
-  };
+  const getAssetUrl = (path: string) => {
+    return urlJoin(assetBaseUrl, path);
+  };

Don't forget to install the url-join package and import it at the top of the file:

+import urlJoin from 'url-join';

78-78: Consider exporting the component directly.

Since the component is already being exported as a named export on line 21, there's no need to have a separate default export. Consider removing this line to avoid confusion and stick with the named export.

-export default RecipientRemovedFromDocumentTemplate;
packages/lib/server-only/recipient/set-recipients-for-document.ts (1)

24-25: Consider moving the email constants to a shared location.

The NEXT_PUBLIC_WEBAPP_URL, FROM_ADDRESS, and FROM_NAME constants are imported from separate files. If these constants are used in multiple places across the codebase, consider moving them to a shared constants file to improve maintainability and avoid duplication.

You can refactor the code like this:

// shared/constants.ts
export const NEXT_PUBLIC_WEBAPP_URL = 'https://example.com';
export const FROM_ADDRESS = '[email protected]';
export const FROM_NAME = 'Documenso';

// current file
import { NEXT_PUBLIC_WEBAPP_URL, FROM_ADDRESS, FROM_NAME } from '../shared/constants';

This way, if the values need to be updated in the future, you only need to change them in one place.

packages/lib/server-only/field/set-fields-for-document.ts (3)

339-352: Consider extracting FieldData type to a shared location.

The FieldData type consolidates the properties of a field, which is a positive change. However, since this type is likely to be used in other parts of the codebase, consider moving it to a shared location, such as a dedicated types file or a common library.

This will promote reusability and maintain a single source of truth for the FieldData type.


105-108: Handle recipient not found error gracefully.

When a recipient is not found for a field, the code throws an AppError with the INVALID_REQUEST error code. This is a good practice to prevent proceeding with invalid data.

However, consider providing a more specific error message or error code to help identify the exact issue when debugging or handling errors. For example, you could use a dedicated error code like RECIPIENT_NOT_FOUND to distinguish this specific error case.


Line range hint 1-28: Organize imports for better readability.

The file imports various dependencies, but the import statements could be organized more effectively to improve readability. Consider the following suggestions:

  1. Group imports by their origin (e.g., external libraries, internal modules).
  2. Sort imports alphabetically within each group.
  3. Add blank lines between groups to visually separate them.

This will make it easier to navigate and maintain the import section of the file.

packages/lib/translations/en/marketing.js (1)

1-1: Consider adding comments to document the purpose of keys.

To improve maintainability and make it easier for developers to understand the context and usage of each key-value pair, consider adding inline comments to document their purpose, especially for less intuitive keys.

For example:

{
  "eK0veR": "Our Enterprise License is great for large organizations looking to switch to Documenso for all their signing needs. It's available for our cloud offering as well as self-hosted setups and offers a wide range of compliance and Adminstration Features.", // Description of the Enterprise License offering
  // ...
}
packages/ui/primitives/document-flow/add-fields.tsx (2)

44-44: Consider providing more context in the alert message.

The Alert component is used to display a warning message when a recipient can no longer be modified. Consider providing more context in the message to help the user understand why the recipient cannot be modified and what actions they can take, if any.


Line range hint 985-1014: Improve the user experience by providing more granular feedback.

The changes introduce a warning alert when a recipient can no longer be modified due to signing a field or completing the document. This enhances the user experience by clearly communicating the state of the recipient's ability to interact with the document.

Consider providing even more granular feedback to the user by specifying which specific action (signing a field or completing the document) caused the recipient to become unmodifiable. This can help the user better understand the current state of the document and the recipients.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7644c0d and b62dfdc.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (15)
  • apps/marketing/package.json (2 hunks)
  • apps/web/package.json (3 hunks)
  • packages/ee/server-only/limits/provider/client.tsx (2 hunks)
  • packages/email/templates/recipient-removed-from-document.tsx (1 hunks)
  • packages/lib/package.json (1 hunks)
  • packages/lib/server-only/field/set-fields-for-document.ts (5 hunks)
  • packages/lib/server-only/recipient/set-recipients-for-document.ts (6 hunks)
  • packages/lib/translations/de/common.po (21 hunks)
  • packages/lib/translations/de/marketing.js (1 hunks)
  • packages/lib/translations/en/common.po (21 hunks)
  • packages/lib/translations/en/marketing.js (1 hunks)
  • packages/lib/utils/recipients.ts (1 hunks)
  • packages/ui/primitives/document-flow/add-fields.tsx (5 hunks)
  • packages/ui/primitives/document-flow/add-signers.tsx (15 hunks)
  • packages/ui/primitives/document-flow/field-item.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/lib/translations/de/marketing.js
Additional comments not posted (60)
packages/lib/utils/recipients.ts (2)

6-18: LGTM!

The canRecipientBeModified function correctly implements the logic to determine if a recipient can be modified based on the provided conditions. The early return statements improve readability and performance.


27-33: LGTM!

The canRecipientFieldsBeModified function correctly builds upon the canRecipientBeModified function and adds the additional check for the recipient's role. The logic is clear and concise.

packages/lib/package.json (1)

51-51: Verify the impact of upgrading the remeda library.

The remeda library has been upgraded from version 1.27.1 to 2.12.1. This is a major version upgrade and may introduce breaking changes.

To assess the impact of this upgrade, run the following script:

If the script reveals any incompatible usages or potential issues, please update the code accordingly to align with the remeda 2.x API.

Verification successful

The upgrade to remeda 2.12.1 appears to be safe.

Based on the analysis of the codebase, the upgrade from remeda 1.x to 2.12.1 should not introduce any breaking changes in your current usage. The functions you're using (prop, sortBy, and isDeepEqual) are not affected by the major version upgrade.

To ensure a smooth transition:

  • Proceed with the upgrade to remeda 2.12.1.
  • After upgrading, thoroughly test the following files that import remeda:
    • packages/ui/primitives/document-flow/add-signers.tsx
    • packages/ui/primitives/document-flow/add-fields.tsx
    • packages/ee/server-only/limits/provider/client.tsx
    • packages/lib/server-only/field/set-fields-for-document.ts

While the upgrade appears safe, it's always a good practice to run your test suite and perform manual testing to catch any unexpected issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Description: 
# - Verify the usage of the `remeda` library across the codebase.
# - Check if the upgrade to version 2.x introduces any breaking changes.

# Test 1: Search for `remeda` imports. 
# Expect: A list of files using the `remeda` library.
echo "Files importing 'remeda':"
rg --type typescript --files-with-matches $'from \'remeda\''

# Test 2: Search for specific `remeda` function usage that might be affected by breaking changes in 2.x. 
# Expect: No results or only valid usages according to the 2.x API.
echo "\nChecking for potentially affected 'remeda' function usage..."

# 2.1 Check for `R.pipe` usage (removed in 2.x)
echo "Occurrences of 'R.pipe':"
rg --type typescript -C 2 $'R\.pipe'

# 2.2 Check for `R.pipeAsync` usage (removed in 2.x)
echo "Occurrences of 'R.pipeAsync':"
rg --type typescript -C 2 $'R\.pipeAsync'

# Add more checks for other potentially affected functions...

echo "Impact verification complete."

Length of output: 668


Script:

#!/bin/bash

# Description: 
# - Verify the usage of the `remeda` library across the codebase.
# - Check if the upgrade to version 2.x introduces any breaking changes.

# Test 1: Search for `remeda` imports in .ts, .tsx, and .js files
echo "Files importing 'remeda':"
rg --files-with-matches -g '*.{ts,tsx,js}' "from 'remeda'"

# Test 2: Search for specific `remeda` function usage that might be affected by breaking changes in 2.x
echo "\nChecking for potentially affected 'remeda' function usage..."

# 2.1 Check for `R.pipe` usage (removed in 2.x)
echo "Occurrences of 'R.pipe':"
rg -C 2 -g '*.{ts,tsx,js}' 'R\.pipe'

# 2.2 Check for `R.pipeAsync` usage (removed in 2.x)
echo "Occurrences of 'R.pipeAsync':"
rg -C 2 -g '*.{ts,tsx,js}' 'R\.pipeAsync'

# 2.3 Check for `R.compact` usage (behavior changed in 2.x)
echo "Occurrences of 'R.compact':"
rg -C 2 -g '*.{ts,tsx,js}' 'R\.compact'

echo "Impact verification complete."

Length of output: 893


Script:

#!/bin/bash

# Description: 
# - Inspect the content of files importing 'remeda'
# - Check for usage of potentially affected functions in remeda 2.x

echo "Inspecting files importing 'remeda':"

files=(
  "packages/ui/primitives/document-flow/add-signers.tsx"
  "packages/ui/primitives/document-flow/add-fields.tsx"
  "packages/ee/server-only/limits/provider/client.tsx"
  "packages/lib/server-only/field/set-fields-for-document.ts"
)

for file in "${files[@]}"; do
  echo "File: $file"
  echo "-------------------"
  rg -C 5 "from 'remeda'" "$file"
  echo -e "\n"
done

echo "Checking for potentially affected remeda functions:"
echo "-------------------"

# List of potentially affected functions in remeda 2.x
affected_functions=(
  "R.omit"
  "R.pick"
  "R.pickBy"
  "R.mapKeys"
  "R.mergeAll"
  "R.zip"
  "R.zipWith"
  "R.zipObj"
  "R.unzip"
)

for func in "${affected_functions[@]}"; do
  echo "Occurrences of '$func':"
  rg -C 2 -g '*.{ts,tsx,js}' "$func"
  echo -e "\n"
done

echo "Inspection complete."

Length of output: 5212

apps/marketing/package.json (1)

37-37: Verify the impact of upgrading next-axiom on the application.

The next-axiom library has been upgraded from version 1.1.1 to 1.5.1. While this change suggests improvements or bug fixes, it's crucial to ensure that the upgrade does not introduce any breaking changes or compatibility issues within the marketing application.

To verify the impact, follow these steps:

  1. Thoroughly review the release notes and changelog of next-axiom for versions 1.2.0 to 1.5.1 to identify any breaking changes or deprecations that may affect the application.

  2. Run the following script to search for usages of next-axiom across the codebase:

  3. For each usage found, verify that the implementation is compatible with the upgraded version and make necessary adjustments if required.

  4. Perform comprehensive testing of the marketing application, focusing on areas that integrate with next-axiom, to ensure that the functionality remains intact and no new issues are introduced due to the version upgrade.

By following these verification steps, you can mitigate the risk of potential issues arising from the next-axiom upgrade and ensure a smooth transition to the newer version.

If you encounter any challenges or need assistance with the verification process, please let me know, and I'll be happy to provide further guidance.

Verification successful

Upgrade impact verified: Focus on AxiomWebVitals and withAxiom

The next-axiom upgrade from 1.1.1 to 1.5.1 affects both the marketing and web apps. The usage is consistent and minimal:

  1. AxiomWebVitals component in layout files:

    • apps/marketing/src/app/layout.tsx
    • apps/web/src/app/layout.tsx
  2. withAxiom function in Next.js config:

    • apps/marketing/next.config.js
    • apps/web/next.config.js

To ensure compatibility:

  1. Check the AxiomWebVitals component usage in both layout files for any breaking changes or new props.
  2. Verify the withAxiom function in next.config.js files for any configuration changes.
  3. Review the changelog for versions 1.2.0 to 1.5.1, focusing on these two main usage points.

The minimal and consistent usage reduces the risk of breaking changes, but thorough testing of both apps is still recommended.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Search for `next-axiom` imports
rg --type typescript --type javascript 'from "next-axiom"' 

# Search for `next-axiom` configurations
rg --type typescript --type javascript 'nextAxiom\(' 

Length of output: 185


Script:

#!/bin/bash

# Search for files with .js, .jsx, .ts, or .tsx extensions
echo "Searching for 'next-axiom' imports and usage:"
fd -e js -e jsx -e ts -e tsx | xargs rg -i "next-axiom"

echo "\nSearching for 'nextAxiom' function calls:"
fd -e js -e jsx -e ts -e tsx | xargs rg -i "nextAxiom\("

echo "\nSearching for any other 'next-axiom' references:"
fd -e js -e jsx -e ts -e tsx -e json | xargs rg -i "next-axiom"

Length of output: 1629

packages/ee/server-only/limits/provider/client.tsx (2)

45-45: LGTM!

The usage of isDeepEqual here is appropriate and should provide a more accurate comparison of the old and new limits. This change aligns with the expected behavior of the LimitsProvider component.


5-5: Verify the impact of the remeda library upgrade.

The change from equals to isDeepEqual is likely due to an upgrade of the remeda library. While this change is generally positive, as it provides a more thorough comparison of limits, it's important to ensure that this change doesn't introduce any unintended side effects or break existing functionality.

Run the following script to analyze the usage of remeda functions across the codebase:

Verification successful

Verified: remeda upgrade consistently applied and isDeepEqual usage is appropriate

The change from equals to isDeepEqual in packages/ee/server-only/limits/provider/client.tsx is consistent with the usage in other parts of the codebase. The isDeepEqual function is being used appropriately for comparing complex objects like limits and field metadata. There's no evidence of unintended side effects or broken functionality due to this change.

Key observations:

  • isDeepEqual is used in two files: client.tsx and set-fields-for-document.ts
  • Other remeda functions (prop and sortBy) are used consistently in other files
  • Remaining equals usage is not from remeda, but likely from custom implementations or other libraries

The upgrade appears to have been applied consistently across the codebase, and the change is likely to provide more thorough comparisons as intended.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze the usage of `remeda` functions.

# Test 1: Search for `remeda` imports. Expect: Consistent version across all files.
rg --type typescript $'from \'remeda\'' 

# Test 2: Search for `equals` usage. Expect: No occurrences, as it has been replaced.
ast-grep --lang typescript --pattern $'equals($_)'

# Test 3: Search for `isDeepEqual` usage. Expect: Usage in relevant comparison scenarios.
ast-grep --lang typescript --pattern $'isDeepEqual($_, $_)'

Length of output: 303


Script:

#!/bin/bash
# Description: Further analyze the usage of `remeda` functions and imports

# Search for `remeda` imports
grep -r "from 'remeda'" --include="*.ts" --include="*.tsx" .

# Double-check for any remaining `equals` usage
grep -r "equals(" --include="*.ts" --include="*.tsx" .

# Investigate `isDeepEqual` usage with context
grep -r -n -C 3 "isDeepEqual(" --include="*.ts" --include="*.tsx" .

# Search for other `remeda` function imports
grep -r "import {.*} from 'remeda'" --include="*.ts" --include="*.tsx" .

Length of output: 2624

apps/web/package.json (2)

56-56: Assess the impact of upgrading remeda on the application.

The remeda library has been upgraded from version ^1.27.1 to ^2.12.1. This is a major version bump, which may introduce breaking changes or require modifications to the existing code that relies on this library.

To assess the impact of the upgrade, run the following script:

If the library is used extensively or if the build fails, review the remeda changelog and migration guide to identify and address any breaking changes or required code modifications.


40-40: Verify the impact of upgrading next-axiom on the application.

The next-axiom library has been upgraded from version ^1.1.1 to ^1.5.1. While this update likely includes improvements and bug fixes, it's important to ensure that the new version is compatible with the application and doesn't introduce any breaking changes.

To verify the impact of the upgrade, run the following script:

If the library is used extensively or if the build fails, consider reviewing the changelog and migration guide of next-axiom to identify and address any potential issues.

Verification successful

To gather the necessary information about the usage of next-axiom in the codebase, I'll generate new shell scripts that should work in the given environment. These scripts will help us identify where and how next-axiom is being used.

These scripts should help us identify the usage of next-axiom in the codebase, allowing us to better assess the potential impact of the upgrade.


The next-axiom upgrade appears to have minimal impact on the application.

The upgrade from version ^1.1.1 to ^1.5.1 is a minor version bump, which typically indicates backward-compatible changes. Based on the analysis:

  • next-axiom is primarily used for configuration (withAxiom in next.config.js) and web vitals tracking (AxiomWebVitals in layout.tsx).
  • No direct usage of logging functions was found, suggesting limited use of advanced features.
  • The new version (^1.5.1) is consistently applied across all relevant files.

To ensure a smooth upgrade:

  1. Review the next-axiom changelog for any new features or improvements that could benefit your application.
  2. Perform basic testing of the application, focusing on areas that might interact with next-axiom (e.g., performance monitoring, error tracking).
  3. If you use any advanced features of next-axiom not detected in this analysis, pay extra attention to those during testing.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and compatibility of the `next-axiom` library.

# Test 1: Search for the library's usage in the codebase.
rg --type typescript -A 5 $'next-axiom'

# Test 2: Check if the application builds successfully with the new version.
npm run build

Length of output: 160


Script:

#!/bin/bash
# Search for next-axiom usage in the codebase

# Using ripgrep to find any mention of next-axiom
echo "Searching for next-axiom mentions:"
rg "next-axiom" -C 5

# Using ast-grep to find import statements for next-axiom
echo "Searching for next-axiom import statements:"
ast-grep --lang javascript --pattern 'import $_ from "next-axiom"'

# Using ast-grep to find require statements for next-axiom
echo "Searching for next-axiom require statements:"
ast-grep --lang javascript --pattern 'const $_ = require("next-axiom")'

# Search for specific next-axiom function calls or usage
echo "Searching for specific next-axiom usage:"
rg "withAxiom|log\.(debug|info|warn|error)" -C 5

Length of output: 8948

packages/email/templates/recipient-removed-from-document.tsx (3)

21-25: LGTM!

The component props and their default values are properly defined.


32-76: LGTM!

The component structure and styling look good. The use of imported components and Tailwind CSS classes ensures a consistent and visually appealing email template.


1-1: Verify the import path for the Tailwind config.

Ensure that the import path @documenso/tailwind-config is correct and the package is properly installed in the project.

Run the following script to verify the import:

Verification successful

Import path for Tailwind config is correct

The import statement import config from '@documenso/tailwind-config'; in packages/email/templates/recipient-removed-from-document.tsx is correct. The package @documenso/tailwind-config exists as a local package within the monorepo and is properly referenced in multiple package.json files across the project.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the import path for the Tailwind config.

# Test: Check if the package exists. Expect: Package found.
fd --type file --regex '.*@documenso/tailwind-config.*'

Length of output: 57


Script:

#!/bin/bash
# Description: Verify the Tailwind config import and search for related files

# Search for the specific import statement in the file
echo "Searching for import statement:"
rg "import .* from '@documenso/tailwind-config'" packages/email/templates/recipient-removed-from-document.tsx

# Search for any occurrences of 'tailwind-config' in the codebase
echo "Searching for tailwind-config in the codebase:"
rg "tailwind-config" -l

# Check package.json files for references to tailwind-config
echo "Checking package.json files:"
fd package.json --exec rg "tailwind-config" {}

Length of output: 2124

packages/ui/primitives/document-flow/field-item.tsx (2)

213-213: LGTM!

The addition of the data-field-id attribute is a good practice for improving the component's accessibility and integration with other parts of the application. It provides a unique identifier for the field item, which can be useful for DOM interactions and JavaScript functionalities that rely on data attributes.


Line range hint 1-212: Verify the impact of the data-field-id attribute on the codebase.

The addition of the data-field-id attribute is a minor change that should not affect the existing functionality. However, it's important to ensure that this change does not introduce any unintended consequences or break any existing code that relies on the FieldItem component.

To verify the impact, run the following script:

If the above tests pass without any issues, it indicates that the data-field-id attribute addition is safe and does not introduce any breaking changes.

Also applies to: 214-285

packages/lib/server-only/recipient/set-recipients-for-document.ts (5)

278-308: Excellent addition of email notifications for removed recipients!

Sending email notifications to recipients who have been removed from the document is a thoughtful feature. It keeps them informed about the changes and provides transparency.

The implementation looks solid:

  • It correctly checks if the recipient had been sent the document before sending the notification.
  • It uses the RecipientRemovedFromDocumentTemplate to generate the email content.
  • It passes the necessary data to the template.
  • It sends the email using the configured mailer service.

63-65: Ensure the included Field data is used efficiently.

The code includes the Field relation when querying the document:

include: {
  Field: true,
},

However, it's unclear if all the fields of the Field relation are necessary for the current operation. Fetching unnecessary data can impact performance.

Please review the usage of the Field data and consider:

  1. If all the fetched fields are actually used in the code.
  2. If any specific fields can be selected instead of fetching the entire Field object.

To verify the usage of the Field data, run the following script:

Review the results and optimize the Field data fetching if necessary.

Verification successful

The inclusion of Field data appears necessary and efficiently used.

After reviewing the code, the inclusion of the Field relation in the document query is justified. Here's why:

  1. The document.Field is used in the canRecipientBeModified function, which checks if a recipient can be modified based on the document's fields.
  2. There's no evidence of unnecessary data fetching or inefficient use of the Field data.
  3. The code handles field deletion for specific recipient role changes, indicating careful management of field data.

Given these observations, the current implementation seems appropriate for the use case. No changes are required at this time.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `Field` data.

# Test: Search for the usage of the `Field` relation.
# Expect: The fetched fields should be used efficiently in the code.
rg --type typescript -A 10 $'document.Field'

Length of output: 78


Script:

#!/bin/bash
# Description: Verify the usage of the `Field` data.

# Search for usage of document.Field and document?.Field across all files
echo "Searching for document.Field usage:"
rg -i -C 5 'document\.Field|document\?\.Field'

# Search for Field usage in the specific file under review
echo "Searching for Field usage in the specific file:"
rg -i -C 5 'Field' packages/lib/server-only/recipient/set-recipients-for-document.ts

Length of output: 2353


326-348: Ensure all relevant recipient fields are compared.

The hasRecipientBeenChanged function compares the relevant fields of the existing recipient with the new recipient data to determine if any changes have occurred. This is crucial for validating recipient modifications.

Please verify that all the fields that should be compared are included in this function. If any field is missing, it could lead to incorrect change detection.

To verify that all relevant fields are compared, run the following script:

Compare the fields being compared in hasRecipientBeenChanged with the fields defined in the RecipientData type. If any field is missing, please add it to the comparison.

Verification successful

All relevant recipient fields are being compared.

The hasRecipientBeenChanged function compares all the essential fields from the RecipientData type:

  • email
  • name
  • role
  • signingOrder
  • actionAuth

The id field is not compared, but this is likely intentional as it's an optional field and may not be relevant for determining if the recipient's details have changed.

The implementation appears to be consistent with the comment above the RecipientData type, which suggests updating the function when the type changes.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all relevant recipient fields are compared in `hasRecipientBeenChanged`.

# Test: Search for the `hasRecipientBeenChanged` function.
# Expect: It should compare all the fields present in the `RecipientData` type.
rg --type typescript -A 20 $'hasRecipientBeenChanged'

Length of output: 87


Script:

#!/bin/bash
# Search for RecipientData type and hasRecipientBeenChanged function
rg -A 20 'type RecipientData'
rg -A 20 'const hasRecipientBeenChanged'

Length of output: 3230


123-144: Verify the logic for handling existing recipients.

The code correctly handles existing recipients by checking if they have been modified and if they can be modified based on their interaction with the document. It throws an appropriate error if an invalid modification is attempted.

To verify the logic, run the following script:

Verification successful

Verification of recipient modification logic is successful.

The implementation in packages/lib/server-only/recipient/set-recipients-for-document.ts correctly handles existing recipients:

  1. It checks if the recipient has been changed.
  2. It verifies if the recipient can be modified using canRecipientBeModified(existing, document.Field).
  3. If modification is not allowed, it throws an AppError with AppErrorCode.INVALID_REQUEST and an appropriate message.

This logic is consistent with the usage of canRecipientBeModified throughout the codebase, ensuring that recipients who have already interacted with the document cannot be modified.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic for handling existing recipients.

# Test 1: Search for the `canRecipientBeModified` function usage. 
# Expect: It should be called with the correct arguments.
rg --type typescript -A 5 $'canRecipientBeModified'

# Test 2: Search for the error thrown when a recipient cannot be modified.
# Expect: The error should have the correct code and message.
rg --type typescript -A 5 $'AppErrorCode.INVALID_REQUEST'

Length of output: 177


Script:

#!/bin/bash
# Description: Verify the logic for handling existing recipients.

# Test 1: Search for the `canRecipientBeModified` function usage.
rg -A 5 'canRecipientBeModified'

# Test 2: Search for the error thrown when a recipient cannot be modified.
rg -A 5 'AppErrorCode.INVALID_REQUEST'

# Test 3: Use ast-grep to find the specific function call pattern
ast-grep --lang javascript --pattern 'canRecipientBeModified($_, $_)'

# Test 4: Use ast-grep to find the error throwing pattern
ast-grep --lang javascript --pattern 'throw new AppError(AppErrorCode.INVALID_REQUEST, $_)'

Length of output: 23699


4-6: Verify the imported email templates and services are used correctly.

The code imports the following email-related modules:

  • mailer from @documenso/email/mailer
  • render from @documenso/email/render
  • RecipientRemovedFromDocumentTemplate from @documenso/email/templates/recipient-removed-from-document

Please ensure that:

  1. The mailer service is properly configured and can send emails.
  2. The render function is used correctly to generate the email content.
  3. The RecipientRemovedFromDocumentTemplate is the correct template for notifying removed recipients.

To verify the usage of the imported email modules, run the following script:

Review the results to ensure the imported modules are used correctly. If any discrepancies are found, please investigate and fix them.

Verification successful

Verified: Email templates and services are used correctly.

The imported email-related modules are used appropriately throughout the codebase:

  1. The mailer service is properly configured and used to send emails with correct arguments.
  2. The render function is consistently used to generate both HTML and plain text versions of email content.
  3. The RecipientRemovedFromDocumentTemplate is correctly imported and used for notifying removed recipients.

No issues were found, and the implementation appears to be correct and consistent.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the imported email modules.

# Test 1: Search for the usage of the `mailer` service.
# Expect: It should be used to send emails with the correct arguments.
rg --type typescript -A 10 $'mailer.sendMail'

# Test 2: Search for the usage of the `render` function.
# Expect: It should be used to generate the email content with the correct arguments.
rg --type typescript -A 5 $'render\('

# Test 3: Search for the usage of the `RecipientRemovedFromDocumentTemplate`.
# Expect: It should be used as the template for removed recipient notifications.
rg --type typescript -A 5 $'RecipientRemovedFromDocumentTemplate'

Length of output: 253


Script:

#!/bin/bash
# Description: Verify the usage of the imported email modules using fd and grep.

# Test 1: Search for the usage of the `mailer` service.
echo "Searching for mailer.sendMail usage:"
fd -e ts -e tsx | xargs grep -ni -A 10 "mailer\.sendMail" || echo "No matches found for mailer.sendMail"

# Test 2: Search for the usage of the `render` function.
echo "Searching for render function usage:"
fd -e ts -e tsx | xargs grep -ni -A 5 "render(" || echo "No matches found for render("

# Test 3: Search for the usage of the `RecipientRemovedFromDocumentTemplate`.
echo "Searching for RecipientRemovedFromDocumentTemplate usage:"
fd -e ts -e tsx | xargs grep -ni -A 5 "RecipientRemovedFromDocumentTemplate" || echo "No matches found for RecipientRemovedFromDocumentTemplate"

Length of output: 34959

packages/lib/server-only/field/set-fields-for-document.ts (3)

98-127: Ensure recipient existence and field modification validity.

The changes introduce important validation checks:

  1. Each field must have an associated recipient. If a recipient is not found, an error is thrown.
  2. If a field has been modified and the recipient's status does not allow field modifications, an error is thrown.

These checks enhance the robustness of the function by preventing invalid field modifications.


110-120: Verify error handling for recipient interaction check.

The code introduces a check to prevent modifying a field if the recipient has already interacted with the document. This is a crucial validation to maintain data integrity.

Please ensure that this error is properly handled and communicated to the user in a clear and actionable manner. Consider testing various scenarios where a recipient has interacted with the document to confirm that the error is thrown correctly and the user receives an appropriate message.


354-367: Verify hasFieldBeenChanged usage across the codebase.

The new hasFieldBeenChanged function compares the current and new field data to determine if a field has been modified. This is a critical piece of logic that affects the behavior of the setFieldsForDocument function.

Please ensure that this function is used consistently and correctly throughout the codebase, especially in any other places where field modifications are handled.

Run the following script to verify the usage of hasFieldBeenChanged:

Verification successful

Verified: hasFieldBeenChanged is used correctly and consistently

The hasFieldBeenChanged function is used appropriately within the setFieldsForDocument function in the same file. It's utilized to check if an existing field has been modified before applying changes, which is crucial for preventing modifications to fields where recipients have already interacted with the document.

Key observations:

  • The function is only used locally within the file, which is suitable for its purpose.
  • There's a helpful comment above the FieldData type definition, indicating that the hasFieldBeenChanged function should be updated if the type changes.

No issues were found with the implementation or usage of the hasFieldBeenChanged function.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `hasFieldBeenChanged` function across the codebase.

# Test: Search for the function usage. Expect: Only valid usage patterns.
rg --type typescript -A 5 $'hasFieldBeenChanged'

Length of output: 82


Script:

#!/bin/bash
# Description: Search for usage of `hasFieldBeenChanged` function in TypeScript files

# Find all TypeScript files and search for 'hasFieldBeenChanged'
fd -e ts -x grep -n -A 5 'hasFieldBeenChanged' {} || echo "No matches found"

# Additionally, let's check the content of the file we're reviewing
cat packages/lib/server-only/field/set-fields-for-document.ts

Length of output: 11877

packages/lib/translations/en/marketing.js (2)

1-1: LGTM!

The changes to the messages object look good. The JSON structure is valid and the modifications enhance clarity and expand functionality.


1-1: Verify the impact of localization changes.

The changes to the localization strings can potentially impact the user experience across the application. It's crucial to thoroughly test the affected user flows to ensure that the modifications are rendering correctly and conveying the intended meaning effectively.

Run the following script to identify the usage of the modified keys across the codebase:

Review the results to assess the impact and plan comprehensive testing of the affected areas.

packages/ui/primitives/document-flow/add-signers.tsx (14)

19-19: LGTM!

The import statement for canRecipientBeModified utility function is correct.


Line range hint 191-198: Verify the error handling for removing a signer.

The code correctly prevents removing a signer who has already signed the document and displays an appropriate error message using the toast function.


237-238: Verify the logic for updating signing orders.

The code correctly updates the signing orders of the remaining signers when a signer is removed, considering the canRecipientBeModified status of each signer.


272-272: Verify the onDragEnd callback dependencies.

The onDragEnd callback has the correct dependencies in its dependency array, including the form, canRecipientBeModified, and watchedSigners.


317-329: Verify the logic for updating signing orders during drag and drop.

The code correctly updates the signing orders of the signers when they are reordered using drag and drop, considering the canRecipientBeModified status of each signer.


338-338: Verify the updateSigningOrders callback dependencies.

The updateSigningOrders callback has the correct dependencies in its dependency array, including the form and canRecipientBeModified.


429-429: Verify the logic for disabling drag and drop.

The code correctly disables drag and drop for signers who cannot be modified based on the canRecipientBeModified function.


445-445: Verify the logic for disabling the signer form fields.

The code correctly disables the signer form fields for signers who cannot be modified based on the canRecipientBeModified function.


478-478: Verify the logic for disabling the signing order input.

The code correctly disables the signing order input for signers who cannot be modified based on the canRecipientBeModified function.


512-512: Verify the logic for disabling the email input.

The code correctly disables the email input for signers who cannot be modified based on the canRecipientBeModified function.


546-546: Verify the logic for disabling the name input.

The code correctly disables the name input for signers who cannot be modified based on the canRecipientBeModified function.


574-574: Verify the logic for disabling the action auth select.

The code correctly disables the action auth select for signers who cannot be modified based on the canRecipientBeModified function.


597-597: Verify the logic for disabling the recipient role select.

The code correctly disables the recipient role select for signers who cannot be modified based on the canRecipientBeModified function.


613-614: Verify the logic for disabling the remove signer button.

The code correctly disables the remove signer button for signers who cannot be modified based on the canRecipientBeModified function and when there is only one signer remaining.

packages/lib/translations/en/common.po (20)

80-80: LGTM!

The translation for "Add myself" is correct.


92-92: LGTM!

The translation for "Add Signer" is correct.


113-113: LGTM!

The translation for "Advanced settings" is correct.


176-176: LGTM!

The translation for "Checkbox" is correct.


222-222: LGTM!

The translation for "Date" is correct.


254-254: LGTM!

The translation for "Dropdown" is correct.


Line range hint 263-269: LGTM!

The translations for "Email" and "Name" are correct.


280-280: LGTM!

The translation for "Enable signing order" is correct.


382-385: LGTM!

The translations for "Name" are correct.


404-404: LGTM!

The translation for "No recipient matching this description was found." is correct.


409-409: LGTM!

The translation for "No recipients with this role" is correct.


434-434: LGTM!

The translation for "Number" is correct.


469-469: LGTM!

The translation for "Radio" is correct.


505-505: LGTM!

The translation for "Remove" is correct.


567-567: LGTM!

The translation for "Show advanced settings" is correct.


576-576: LGTM!

The translation for "Signature" is correct.


624-624: LGTM!

The translation for "Text" is correct.


685-685: LGTM!

The translation for "This document has already been sent to this recipient. You can no longer edit this recipient." is correct.


697-699: LGTM!

The new translation "This recipient can no longer be modified as they have signed a field, or completed the document." is correct.


722-722: LGTM!

The translation for "To proceed further, please set at least one value for the {0} field." is correct.

packages/ui/primitives/document-flow/add-fields.tsx (3)

231-237: Verify the logic for determining if fields are disabled.

The isFieldsDisabled variable is now determined using the canRecipientFieldsBeModified function, which checks if the selected recipient can modify fields based on their current state. This improves the clarity and maintainability of the code.


35-38: Verify the usage of the imported utility functions.

The imported utility functions canRecipientBeModified and canRecipientFieldsBeModified are used to determine if a recipient can be modified or if their fields can be modified. Ensure that these functions are being used correctly throughout the codebase.

Run the following script to verify the usage of these functions:

Verification successful

Verification of imported utility functions successful

The imported utility functions canRecipientBeModified and canRecipientFieldsBeModified are being used correctly throughout the codebase. Key observations:

  • Both functions are defined in packages/lib/utils/recipients.ts and imported where needed.
  • canRecipientBeModified is extensively used in UI components, particularly in add-signers.tsx and add-fields.tsx, to control UI interactions and form submissions based on recipient modifiability.
  • canRecipientFieldsBeModified is used in add-fields.tsx and server-side logic in set-fields-for-document.ts to manage field modifications.
  • The usage is consistent across client-side and server-side code, ensuring uniform behavior in recipient and field modification checks.

The implementation and usage of these functions appear to be correct and in line with their intended purpose of managing recipient and field modifications in the document flow.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `canRecipientBeModified` and `canRecipientFieldsBeModified` functions.

# Test 1: Search for the usage of `canRecipientBeModified`. 
# Expect: Should be used with a recipient object and a fields array.
rg --type typescript -A 5 $'canRecipientBeModified'

# Test 2: Search for the usage of `canRecipientFieldsBeModified`.
# Expect: Should be used with a recipient object and a fields array. 
rg --type typescript -A 5 $'canRecipientFieldsBeModified'

Length of output: 177


Script:

#!/bin/bash

# Search for usage of canRecipientBeModified
echo "Usage of canRecipientBeModified:"
rg 'canRecipientBeModified' -g '*.{ts,tsx}' -A 5

echo "\nUsage of canRecipientFieldsBeModified:"
rg 'canRecipientFieldsBeModified' -g '*.{ts,tsx}' -A 5

echo "\nDefinition of canRecipientBeModified:"
ast-grep --lang typescript --pattern 'export function canRecipientBeModified($_) { $$$ }'

echo "\nDefinition of canRecipientFieldsBeModified:"
ast-grep --lang typescript --pattern 'export function canRecipientFieldsBeModified($_) { $$$ }'

Length of output: 17626


576-577: Verify the usage of canRecipientBeModified function.

The canRecipientBeModified function is used to determine if a field should be disabled based on the selected recipient's ability to be modified. Ensure that this function is being used correctly and consistently throughout the codebase.

Run the following script to verify the usage of this function:

Verification successful

To gather the necessary information for verifying the usage of canRecipientBeModified, I'll generate new shell scripts to search for its usage and definition.


Based on the analysis of the canRecipientBeModified function usage across the codebase, I can provide a final response to the review comment.

Verified: canRecipientBeModified function is used correctly and consistently.

The canRecipientBeModified function is defined in packages/lib/utils/recipients.ts and takes two parameters: recipient and fields. Its usage in the file under review (packages/ui/primitives/document-flow/add-fields.tsx) is correct, as it's called with both selectedSigner and fields as arguments.

This usage is consistent with other occurrences in the codebase, such as in:

  • packages/ui/primitives/document-flow/add-signers.tsx
  • packages/lib/server-only/recipient/set-recipients-for-document.ts

The function is properly imported and utilized in various components and utilities, demonstrating good code organization and reusability.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `canRecipientBeModified` function.

# Test: Search for the usage of `canRecipientBeModified`. 
# Expect: Should be used with a recipient object and a fields array.
rg --type typescript -A 5 $'canRecipientBeModified'

Length of output: 85


Script:

#!/bin/bash
# Search for usage of canRecipientBeModified in .ts and .tsx files
echo "Searching for canRecipientBeModified usage:"
fd -e ts -e tsx --exec grep -n "canRecipientBeModified" {} +

# Search for the definition of canRecipientBeModified
echo -e "\nSearching for canRecipientBeModified definition:"
fd -e ts -e tsx --exec grep -n "function canRecipientBeModified" {} +

Length of output: 72585

Comment on lines +1 to +33
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;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Utility functions are used, but manual checks still exist

The utility functions canRecipientBeModified and canRecipientFieldsBeModified are being used in multiple files across the codebase, including UI components and server-side logic. However, there are still instances of manual checks for recipient roles, signing status, and field insertion. Consider reviewing the following:

  • Examine manual implementations in server-side logic (e.g., in packages/lib/server-only/ directory) to determine if they can be replaced with the utility functions.
  • Review specific use cases in UI components (e.g., in apps/web/src/app/ directory) where manual checks are still being performed.
  • Evaluate if the remaining manual implementations serve a specific purpose that the utility functions don't cover.

Consistent use of these utility functions could improve code maintainability and reduce the risk of inconsistent behavior.

Analysis chain

Verify the usage of these utility functions.

The introduced utility functions encapsulate the logic for determining the modifiability of recipients and their fields. It's important to ensure that these functions are being used consistently throughout the codebase wherever recipient modification checks are required.

Run the following script to verify the usage of these utility functions:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `canRecipientBeModified` and `canRecipientFieldsBeModified` functions.

# Test 1: Search for manual checks on recipient's signing status or field insertion. 
# Expect: No occurrences of manual checks, only usage of the utility functions.
rg --type typescript -A 5 $'recipient\.signingStatus|field\.recipientId.*field\.inserted'

# Test 2: Search for manual checks on recipient's role.
# Expect: No occurrences of manual role checks, only usage of the utility functions.
rg --type typescript -A 5 $'recipient\.role.*RecipientRole\.(VIEWER|CC)'

Length of output: 234


Script:

#!/bin/bash
# Description: Verify the usage of canRecipientBeModified and canRecipientFieldsBeModified functions

# Search for usage of canRecipientBeModified
echo "Searching for usage of canRecipientBeModified:"
rg "canRecipientBeModified" -n

echo "\nSearching for usage of canRecipientFieldsBeModified:"
rg "canRecipientFieldsBeModified" -n

echo "\nSearching for imports of these functions:"
rg "import.*canRecipientBeModified|import.*canRecipientFieldsBeModified" -n

echo "\nSearching for potential manual implementations:"
rg "recipient\.signingStatus.*SigningStatus\.SIGNED|field\.recipientId.*field\.inserted|recipient\.role.*(RecipientRole\.VIEWER|RecipientRole\.CC)" -n

Length of output: 9970

msgstr ""

#: packages/ui/primitives/document-flow/add-signers.tsx:653
#: packages/ui/primitives/document-flow/add-signers.tsx:662

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Übersetzung für "Add myself" fehlt.

Die Übersetzung für die Zeichenfolge "Add myself" fehlt in der deutschen Lokalisierungsdatei.

Fügen Sie die folgende Übersetzung hinzu:

msgid "Add myself"
msgstr "Mich selbst hinzufügen"

msgstr ""

#: packages/ui/primitives/document-flow/add-signers.tsx:642
#: packages/ui/primitives/document-flow/add-signers.tsx:651

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Übersetzung für "Add Signer" fehlt.

Die Übersetzung für die Zeichenfolge "Add Signer" fehlt in der deutschen Lokalisierungsdatei.

Fügen Sie die folgende Übersetzung hinzu:

msgid "Add Signer"
msgstr "Unterzeichner hinzufügen"

msgstr ""

#: packages/ui/primitives/document-flow/add-fields.tsx:522
#: packages/ui/primitives/document-flow/add-fields.tsx:527

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Übersetzung für "Advanced settings" fehlt.

Die Übersetzung für die Zeichenfolge "Advanced settings" fehlt in der deutschen Lokalisierungsdatei.

Fügen Sie die folgende Übersetzung hinzu:

msgid "Advanced settings"
msgstr "Erweiterte Einstellungen"

msgstr ""

#: packages/ui/primitives/document-flow/add-signers.tsx:194
#: packages/ui/primitives/document-flow/add-signers.tsx:193

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Übersetzung für "Cannot remove signer" fehlt.

Die Übersetzung für die Zeichenfolge "Cannot remove signer" fehlt in der deutschen Lokalisierungsdatei.

Fügen Sie die folgende Übersetzung hinzu:

msgid "Cannot remove signer"
msgstr "Unterzeichner kann nicht entfernt werden"

Comment on lines +698 to +700
#: packages/ui/primitives/document-flow/add-fields.tsx:1007
msgid "This recipient can no longer be modified as they have signed a field, or completed the document."
msgstr ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Übersetzung für "This recipient can no longer be modified as they have signed a field, or completed the document." fehlt.

Die Übersetzung für die Zeichenfolge "This recipient can no longer be modified as they have signed a field, or completed the document." fehlt in der deutschen Lokalisierungsdatei.

Fügen Sie die folgende Übersetzung hinzu:

msgid "This recipient can no longer be modified as they have signed a field, or completed the document."
msgstr "Dieser Empfänger kann nicht mehr geändert werden, da er ein Feld unterschrieben oder das Dokument abgeschlossen hat."

Comment thread packages/lib/translations/de/common.po Outdated
Comment on lines +702 to +705
#: packages/ui/primitives/document-flow/add-signers.tsx:165
#~ msgid "This signer has already received the document."
#~ msgstr "Dieser Unterzeichner hat das Dokument bereits erhalten."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entfernen Sie die auskommentierte Übersetzung.

Die Übersetzung für "This signer has already received the document." ist auskommentiert und sollte entfernt werden, da sie nicht mehr verwendet wird.

Entfernen Sie die folgenden Zeilen:

#~ msgid "This signer has already received the document."
#~ msgstr "Dieser Unterzeichner hat das Dokument bereits erhalten."

Comment on lines +706 to +707
#: packages/ui/primitives/document-flow/add-signers.tsx:194
msgid "This signer has already signed the document."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Übersetzung für "This signer has already signed the document." fehlt.

Die Übersetzung für die Zeichenfolge "This signer has already signed the document." fehlt in der deutschen Lokalisierungsdatei.

Fügen Sie die folgende Übersetzung hinzu:

msgid "This signer has already signed the document."
msgstr "Dieser Unterzeichner hat das Dokument bereits unterschrieben."

msgstr ""

#: packages/ui/primitives/document-flow/add-fields.tsx:983
#: packages/ui/primitives/document-flow/add-fields.tsx:990

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Übersetzung für "To proceed further, please set at least one value for the {0} field." fehlt.

Die Übersetzung für die Zeichenfolge "To proceed further, please set at least one value for the {0} field." fehlt in der deutschen Lokalisierungsdatei.

Fügen Sie die folgende Übersetzung hinzu:

msgid "To proceed further, please set at least one value for the {0} field."
msgstr "Um fortzufahren, legen Sie bitte mindestens einen Wert für das {0}-Feld fest."

Comment on lines +163 to +175
const canRecipientBeModified = (recipientId?: number) => {
if (recipientId === undefined) {
return true;
}

return recipients.some(
(recipient) =>
recipient.id === id &&
recipient.sendStatus === SendStatus.SENT &&
recipient.role !== RecipientRole.CC,
);
},
[recipients],
);
const recipient = recipients.find((recipient) => recipient.id === recipientId);

if (!recipient) {
return false;
}

return utilCanRecipientBeModified(recipient, fields);
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor the canRecipientBeModified function.

The canRecipientBeModified function can be simplified by using the utilCanRecipientBeModified utility function directly, without the need for additional checks.

Apply this diff to refactor the function:

-const canRecipientBeModified = (recipientId?: number) => {
-  if (recipientId === undefined) {
-    return true;
-  }
-
-  const recipient = recipients.find((recipient) => recipient.id === recipientId);
-
-  if (!recipient) {
-    return false;
-  }
-
-  return utilCanRecipientBeModified(recipient, fields);
-};
+const canRecipientBeModified = (recipientId?: number) => {
+  const recipient = recipients.find((recipient) => recipient.id === recipientId);
+  return recipient ? utilCanRecipientBeModified(recipient, fields) : true;
+};
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const canRecipientBeModified = (recipientId?: number) => {
if (recipientId === undefined) {
return true;
}
return recipients.some(
(recipient) =>
recipient.id === id &&
recipient.sendStatus === SendStatus.SENT &&
recipient.role !== RecipientRole.CC,
);
},
[recipients],
);
const recipient = recipients.find((recipient) => recipient.id === recipientId);
if (!recipient) {
return false;
}
return utilCanRecipientBeModified(recipient, fields);
};
const canRecipientBeModified = (recipientId?: number) => {
const recipient = recipients.find((recipient) => recipient.id === recipientId);
return recipient ? utilCanRecipientBeModified(recipient, fields) : true;
};

This branch was successfully deployed

4 active deployments
Preview – prd-docs — 127f7143 Deployed Sep 20, 2024 by vercel[bot]
Preview – stg-docs — 127f7143 Deployed Sep 20, 2024 by vercel[bot]
Preview – stg-app — 127f7143 Deployed Sep 20, 2024 by vercel[bot]
Preview – stg-marketing — 127f7143 Deployed Sep 20, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants