Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: templates #537

Merged
merged 9 commits into from
Dec 21, 2023
Merged

feat: templates #537

merged 9 commits into from
Dec 21, 2023

Conversation

ephraimduncan
Copy link
Collaborator

@ephraimduncan ephraimduncan commented Oct 8, 2023

Summary by CodeRabbit

  • New Features

    • Introducing template management with the ability to create, edit, and delete templates.
    • Users can now save documents as templates for repeated use.
    • Added the functionality to duplicate templates, making it easier to reuse and modify existing templates.
    • New data tables for templates with pagination and actions like editing and deleting.
    • Enhanced document management with the option to create documents from templates.
  • Enhancements

    • Updated navigation with links to template management sections.
    • Improved user interface for template-related actions.
    • Added new icons and labels to better represent template types and statuses.
  • Bug Fixes

    • Corrected typos and improved validation schemas for template creation and editing.
    • Fixed routing issues to ensure proper navigation after template-related actions.
  • Database and Migrations

    • Implemented several database migrations to support new template features, including the addition of new columns and tables.
  • Documentation

    • Updated documentation to reflect new features and changes in template management.

@vercel
Copy link

vercel bot commented Oct 8, 2023

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

Name Status Preview Comments Updated (UTC)
stg-app 🔄 Building (Inspect) Visit Preview 💬 Add feedback Dec 21, 2023 10:39am
stg-marketing ❌ Failed (Inspect) Dec 21, 2023 10:39am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Visit Preview Dec 21, 2023 10:39am
prd-marketing ⬜️ Ignored (Inspect) Visit Preview Dec 21, 2023 10:39am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2023

Walkthrough

The codebase has been updated with functionalities to manage templates, including creating, editing, duplicating, and deleting templates. New properties like templateToken and templateId have been introduced, and components for handling template actions such as saving documents as templates and managing template fields and recipients are added. The database schema has evolved to support these features, and the server-side logic has been updated to handle template-related operations.

Changes

File Path Change Summary
apps/marketing/src/app/(marketing)/singleplayer/client.tsx
apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx
apps/web/src/app/(dashboard)/templates/[id]/edit-template.tsx
apps/web/src/app/(dashboard)/templates/[id]/page.tsx
apps/web/src/app/(dashboard)/templates/data-table-action-dropdown.tsx
apps/web/src/app/(dashboard)/templates/data-table-templates.tsx
apps/web/src/app/(dashboard)/templates/data-table-title.tsx
apps/web/src/app/(dashboard)/templates/delete-template-dialog.tsx
apps/web/src/app/(dashboard)/templates/empty-state.tsx
apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx
apps/web/src/app/(dashboard)/templates/page.tsx
apps/web/src/components/(dashboard)/layout/desktop-nav.tsx
apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx
apps/web/src/components/formatter/template-type.tsx
apps/web/src/components/forms/edit-template/add-template-fields.action.ts
packages/lib/server-only/document/find-documents.ts
packages/lib/server-only/field/get-fields-for-template.ts
packages/lib/server-only/field/set-fields-for-template.ts
packages/lib/server-only/recipient/get-recipients-for-template.ts
packages/lib/server-only/recipient/set-recipients-for-template.ts
packages/lib/server-only/template/create-document-from-template.ts
packages/lib/server-only/template/create-template-from-document.ts
packages/lib/server-only/template/create-template.ts
packages/lib/server-only/template/delete-template.ts
packages/lib/server-only/template/duplicate-template.ts
packages/lib/server-only/template/get-template-by-id.ts
packages/lib/server-only/template/get-templates.ts
packages/prisma/migrations/20231007013737_templates/migration.sql
packages/prisma/migrations/20231007014431_templates_type/migration.sql
packages/prisma/migrations/20231007021427_reuse_document_data/migration.sql
packages/prisma/migrations/20231007033447_remove_inserted_on_template_field/migration.sql
packages/prisma/migrations/20231007080315_document_name_to_template/migration.sql
packages/prisma/migrations/20231007211915_template_created_date/migration.sql
packages/prisma/migrations/20231017041643_placeholder_recipients/migration.sql
packages/prisma/migrations/20231017042227_fix_typo/migration.sql
packages/prisma/migrations/20231019043226_template_recipient_email/migration.sql
packages/prisma/migrations/20231020032507_template_recipient_token/migration.sql
packages/prisma/migrations/20231021193915_template_token_for_recipient/migration.sql
packages/prisma/migrations/20231030061522_recipient_name_not_placeholder/migration.sql
packages/prisma/migrations/20231214081915_remove_template_token_column/migration.sql
packages/prisma/migrations/20231221070056_make_recipient_status_columns_non_null_again/migration.sql
packages/prisma/migrations/20231221101005_add_templates/migration.sql
packages/prisma/schema.prisma
packages/trpc/server/router.ts
packages/trpc/server/singleplayer-router/router.ts
packages/trpc/server/template-router/router.ts
packages/trpc/server/template-router/schema.ts
packages/ui/primitives/document-dropzone.tsx
packages/ui/primitives/document-flow/types.ts
packages/ui/primitives/template-flow/add-template-fields.tsx
packages/ui/primitives/template-flow/add-template-fields.types.ts
packages/ui/primitives/template-flow/add-template-placeholder-recipients.tsx
packages/ui/primitives/template-flow/add-template-placeholder-recipients.types.ts
apps/web/src/app/(dashboard)/documents/duplicate-document-dialog.tsx
apps/web/src/app/(dashboard)/templates/duplicate-template-dialog.tsx
apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx
packages/lib/server-only/admin/get-recipients-stats.ts
Various additions, updates, and modifications across the codebase to support template management and related operations.

"In the land of code and byte,
Templates dance in sheer delight.
🐇 With each commit, we craft and create,
CodeRabbit hops to celebrate!"

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

@ephraimduncan ephraimduncan marked this pull request as ready for review October 31, 2023 10:31
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 47

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 88534fa and 1eeb5fb.
Files selected for processing (57)
  • apps/marketing/src/app/(marketing)/singleplayer/client.tsx (1 hunks)
  • apps/marketing/src/components/(marketing)/single-player-mode/single-player-mode-success.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx (2 hunks)
  • apps/web/src/app/(dashboard)/templates/[id]/edit-template.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/[id]/page.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/data-table-action-dropdown.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/data-table-templates.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/data-table-title.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/delete-template-dialog.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/duplicate-template-dialog.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/empty-state.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/page.tsx (1 hunks)
  • apps/web/src/components/(dashboard)/layout/desktop-nav.tsx (3 hunks)
  • apps/web/src/components/(dashboard)/layout/header.tsx (1 hunks)
  • apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx (2 hunks)
  • apps/web/src/components/formatter/template-type.tsx (1 hunks)
  • apps/web/src/components/forms/edit-template/add-template-fields.action.ts (1 hunks)
  • apps/web/src/components/forms/edit-template/add-template-placeholders.action.ts (1 hunks)
  • packages/lib/server-only/admin/get-recipients-stats.ts (1 hunks)
  • packages/lib/server-only/document/find-documents.ts (2 hunks)
  • packages/lib/server-only/field/get-fields-for-template.ts (1 hunks)
  • packages/lib/server-only/field/remove-signed-field-with-token.ts (1 hunks)
  • packages/lib/server-only/field/set-fields-for-template.ts (1 hunks)
  • packages/lib/server-only/field/sign-field-with-token.ts (1 hunks)
  • packages/lib/server-only/recipient/get-recipients-for-template.ts (1 hunks)
  • packages/lib/server-only/recipient/set-recipients-for-template.ts (1 hunks)
  • packages/lib/server-only/template/create-document-from-template.ts (1 hunks)
  • packages/lib/server-only/template/create-template.ts (1 hunks)
  • packages/lib/server-only/template/delete-template.ts (1 hunks)
  • packages/lib/server-only/template/duplicate-template.ts (1 hunks)
  • packages/lib/server-only/template/get-template-by-id.ts (1 hunks)
  • packages/lib/server-only/template/get-templates.ts (1 hunks)
  • packages/prisma/migrations/20231007013737_templates/migration.sql (1 hunks)
  • packages/prisma/migrations/20231007014431_templates_type/migration.sql (1 hunks)
  • packages/prisma/migrations/20231007021427_reuse_document_data/migration.sql (1 hunks)
  • packages/prisma/migrations/20231007033447_remove_inserted_on_template_field/migration.sql (1 hunks)
  • packages/prisma/migrations/20231007080315_document_name_to_template/migration.sql (1 hunks)
  • packages/prisma/migrations/20231007211915_template_created_date/migration.sql (1 hunks)
  • packages/prisma/migrations/20231017041643_placeholder_recipients/migration.sql (1 hunks)
  • packages/prisma/migrations/20231017042227_fix_typo/migration.sql (1 hunks)
  • packages/prisma/migrations/20231019043226_template_recipient_email/migration.sql (1 hunks)
  • packages/prisma/migrations/20231020032507_template_recipient_token/migration.sql (1 hunks)
  • packages/prisma/migrations/20231021193915_template_token_for_recipient/migration.sql (1 hunks)
  • packages/prisma/migrations/20231030061522_recipient_name_not_placeholder/migration.sql (1 hunks)
  • packages/prisma/migrations/20231208090322_remove_template_specific_models/migration.sql (1 hunks)
  • packages/prisma/schema.prisma (6 hunks)
  • packages/trpc/server/router.ts (2 hunks)
  • packages/trpc/server/template-router/router.ts (1 hunks)
  • packages/trpc/server/template-router/schema.ts (1 hunks)
  • packages/ui/primitives/dialog.tsx (1 hunks)
  • packages/ui/primitives/document-dropzone.tsx (2 hunks)
  • packages/ui/primitives/document-flow/types.ts (1 hunks)
  • packages/ui/primitives/template-flow/add-template-fields.tsx (1 hunks)
  • packages/ui/primitives/template-flow/add-template-fields.types.ts (1 hunks)
  • packages/ui/primitives/template-flow/add-template-placeholder-recipients.tsx (1 hunks)
  • packages/ui/primitives/template-flow/add-template-placeholder-recipients.types.ts (1 hunks)
Files skipped from review due to trivial changes (6)
  • apps/marketing/src/components/(marketing)/single-player-mode/single-player-mode-success.tsx
  • packages/prisma/migrations/20231007014431_templates_type/migration.sql
  • packages/prisma/migrations/20231007080315_document_name_to_template/migration.sql
  • packages/prisma/migrations/20231019043226_template_recipient_email/migration.sql
  • packages/prisma/migrations/20231020032507_template_recipient_token/migration.sql
  • packages/prisma/migrations/20231021193915_template_token_for_recipient/migration.sql
Additional comments: 77
apps/marketing/src/app/(marketing)/singleplayer/client.tsx (2)
  • 151-157: The addition of the templateToken property to the placeholderRecipient object is consistent with the PR's objective of enhancing template functionality. Ensure that this new property is properly integrated and utilized wherever placeholderRecipient is used.

  • 151-157: Verify that all instances of Recipient object creation or manipulation across the codebase have been updated to include the new templateToken property.

apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx (2)
  • 101-102:
    The addition of nonSignedRecipients is a good use of filtering to identify recipients who have not signed the document, which can be used for further actions like resending the document.

  • 131-134:
    Please confirm if the "Duplicate" menu item is intended to be permanently disabled. If it should be conditionally enabled, the disabling logic needs to be implemented.

apps/web/src/app/(dashboard)/templates/data-table-action-dropdown.tsx (2)
  • 26-79: Ensure that the DuplicateTemplateDialog and DeleteTemplateDialog components have proper error handling and state management, especially if they perform asynchronous operations.

  • 32-34: Returning null from a component is a valid way to prevent rendering, but ensure that this is the desired UX when there is no session.

apps/web/src/app/(dashboard)/templates/data-table-title.tsx (1)
  • 14-15: The previous suggestion to provide a fallback or message when there's no session has not been implemented. Consider updating the code to improve the user experience.
  if (!session) {
-   return null;
+   return <p>Please log in to view templates.</p>;
  }
apps/web/src/app/(dashboard)/templates/empty-state.tsx (1)
  • 3-17: The EmptyTemplateState component is well-structured and follows React functional component best practices. The use of the Bird icon from lucide-react and the instructional text provides a clear and friendly user interface for cases where no templates exist.
apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx (1)
  • 1-228: The NewTemplateDialog component is well-structured and follows best practices for form handling, validation, and state management in React. It integrates with the existing design system and uses tRPC for server interactions. Ensure that the new UI components and server-side functions are properly tested, especially the file upload and template creation functionalities, to maintain the application's reliability.
apps/web/src/app/(dashboard)/templates/page.tsx (1)
  • 10-14: Clarify how the searchParams prop is managed and updated, and ensure there's a mechanism in place to trigger re-renders when it changes.
apps/web/src/components/(dashboard)/layout/desktop-nav.tsx (5)
  • 6-7: The addition of Link and usePathname imports is consistent with the new navigation links feature.

  • 16-25: The navigationLinks array is added to store the navigation links, which is a good practice for maintainability and scalability.

  • 50-65: The rendering logic for the navigation links has been refactored to use the navigationLinks array, which is correctly implemented.

  • 58-58: The use of pathname?.startsWith(href) is a good way to set the active class on the current navigation link.

  • 44-47: The use of cn utility function to combine class names is a good practice for conditional class rendering.

apps/web/src/components/(dashboard)/layout/header.tsx (1)
  • 52-52: The addition of the md:ml-8 class to the div element is a styling change that will apply a left margin on medium-sized screens and above. This change seems appropriate for responsive design adjustments.
apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx (3)
  • 7-7: The addition of the FileSpreadsheet import aligns with the new feature implementation.

  • 110-116: The addition of the Templates link in the ProfileDropdown component is correctly implemented and supports the new feature.

  • 107-119: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [4-119]

No further issues or improvements are identified in the ProfileDropdown component related to the new feature addition.

apps/web/src/components/formatter/template-type.tsx (1)
  • 1-50: The TemplateType component and its associated types and constants are well-defined and correctly implemented. The use of types from the Prisma client ensures consistency with the backend schema, and the component's props provide flexibility for styling and behavior. The code is clean, maintainable, and follows best practices for a React component.
apps/web/src/components/forms/edit-template/add-template-placeholders.action.ts (1)
  • 5-5: There appears to be a typo in the type name TAddTemplatePlacholderRecipientsFormSchema. Please verify if the type name should be TAddTemplatePlaceholderRecipientsFormSchema.
packages/lib/server-only/document/find-documents.ts (2)
  • 8-14: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [11-22]

The orderBy property within FindDocumentsOptions has been modified to use column instead of field. Verify that all references to this property have been updated to reflect this change.

Verification successful

The search results show two occurrences of FindDocumentsOptions. The first one is in find-documents.ts, which is the file where the type was changed, and it shows the updated orderBy property using column instead of field. The second occurrence is in get-all-documents.ts, which defines a different FindDocumentsOptions interface without an orderBy property.

Since the ast-grep command did not find any instances of the old field property and the rg command only found the updated usage in find-documents.ts and a different interface in get-all-documents.ts, it seems that the change from field to column has been correctly updated in the codebase.

Based on the information gathered, it appears that all references to the orderBy property within FindDocumentsOptions have been updated to reflect the change from field to column.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for files that might be using the old `field` property.
ast-grep --lang typescript --pattern $'FindDocumentsOptions {
  $$$
  orderBy?: {
    field: $_,
    $$$
  };
  $$$
}'

Length of output: 620



Script:

#!/bin/bash
# Corrected search for files that might be using the old `field` property within `FindDocumentsOptions`.
ast-grep --lang typescript --pattern $'type FindDocumentsOptions = {
  $$$
  orderBy?: {
    field: $_,
    $$$
  };
  $$$
}'

Length of output: 126



Script:

#!/bin/bash
# Search for any TypeScript files that might be using the `FindDocumentsOptions` type to ensure the `orderBy` property is correctly updated.
rg --type ts 'FindDocumentsOptions' -A 10

Length of output: 3052

* 24-25: The `findDocuments` function appears to be correctly implemented with the updated `FindDocumentsOptions` type.
packages/lib/server-only/field/remove-signed-field-with-token.ts (3)
  • 30-36: The added error checks for document existence and completion status are consistent with the PR's objectives and enhance the robustness of the removeSignedFieldWithToken function by ensuring that operations are not performed on non-existent or completed documents.

  • 30-36: Consider verifying that the error handling strategy used here, particularly the error messages, is consistent with the rest of the application. Consistency in error handling can improve maintainability and the debugging process.

Verification successful

The error handling strategy in remove-signed-field-with-token.ts, particularly the error messages, appears to be consistent with the rest of the application. The error messages throughout the codebase follow a similar pattern of specificity and clarity, often including the entity type and its ID for context, which aligns with the approach taken in the file under review.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for similar error patterns to ensure consistency
rg "throw new Error" --type=ts

Length of output: 13219

* 34-36: Ensure that the `Promise.all` does not contain operations that have dependencies on each other, as this could lead to race conditions or unintended side effects if they are executed concurrently.
packages/lib/server-only/field/set-fields-for-template.ts (2)
  • 87-88: The create block in the upsert operation sets customText to an empty string and inserted to false. Verify if these are appropriate default values or if they should be configurable or derived from some other state.

  • 94-98: The Recipient connect block in the create operation uses both id and email to connect to a recipient. Ensure that the logic accounts for cases where signerId or signerEmail might be optional and that the correct fields are used for establishing the connection.

packages/lib/server-only/field/sign-field-with-token.ts (1)
  • 36-42: The addition of error handling for a missing document object and a check for the COMPLETED status of the document before proceeding with the signing process is a good practice to ensure data integrity and prevent illegal state transitions.
packages/lib/server-only/recipient/set-recipients-for-template.ts (1)
  • 79-80: The generation of templateToken for each recipient might be correct, but it's important to verify that this token is intended to be unique per recipient and not per template. If it should be unique per template, this could lead to unintended behavior.
packages/lib/server-only/template/create-template.ts (1)
  • 1-20: The implementation of the createTemplate function aligns with the PR's objectives and correctly uses the Prisma client to interact with the database.
packages/lib/server-only/template/get-template-by-id.ts (1)
  • 1-18: The function getTemplateById is well-structured and uses Prisma's findFirstOrThrow method appropriately to retrieve a template by its ID and the user ID. The use of TypeScript for typing the function parameters with the GetTemplateByIdOptions interface is a good practice for type safety. The function is marked as async and correctly uses await for the asynchronous operation. However, ensure that the calling code is prepared to handle the potential error thrown by findFirstOrThrow when no record is found.
packages/prisma/migrations/20231007013737_templates/migration.sql (6)
  • 7-7: The userId field references the User table. Ensure that the User table's id field is also of type INTEGER to maintain referential integrity.
Verification successful

The output from the script confirms that the id field of the User table is defined as SERIAL and not INTEGER. In PostgreSQL, the SERIAL data type is used for auto-incrementing integer columns and it implies that the column is of type INTEGER internally, but also includes auto-increment functionality.

Given this information, the userId field in the Template table, which is of type INTEGER, should be compatible with the id field of the User table for the purpose of foreign key referencing, as both are integer types. Therefore, the referential integrity between the Template table's userId field and the User table's id field is maintained.

Reply:

The User table's id field is defined as SERIAL, which is compatible with the INTEGER type used for the userId field in the Template table. This ensures referential integrity between these fields. No further action is required.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the User table's id field is of type INTEGER
rg 'CREATE TABLE "User"' -A 10 | rg '"id" INTEGER'

Length of output: 52



Script:

#!/bin/bash
# Search for the CREATE TABLE "User" statement and check the type of the "id" field
rg 'CREATE TABLE "User" {.*"id" INTEGER.*};' -U

Length of output: 192



Script:

#!/bin/bash
# Search for the CREATE TABLE "User" statement in SQL migration files and check the type of the "id" field
rg --type sql 'CREATE TABLE "User".*"id" INTEGER' -U

Length of output: 54



Script:

#!/bin/bash
# Find the SQL migration file(s) that contain the CREATE TABLE "User" statement
fd --type f --extension sql '.*' --exec rg 'CREATE TABLE "User"'

Length of output: 88



Script:

#!/bin/bash
# Find the SQL migration file(s) that contain the CREATE TABLE "User" statement and display the lines after the match to include the id field definition
fd --type f --extension sql '.*' --exec rg 'CREATE TABLE "User"' -A 5

Length of output: 218

* 10-10: The default value for `status` is set to `'PRIVATE'`. Confirm that this default aligns with the application's business logic and privacy requirements.
  • 32-35: The default values for positionX, positionY, width, and height in the TemplateField table are set to 0 and -1. Ensure that these defaults are intentional and documented, as -1 is an unusual default for dimensions.

  • 36-36: The customText field in the TemplateField table is marked as NOT NULL with no default value. This requires that every insert operation must provide a value for customText. Confirm that this is the desired behavior.

  • 43-43: The unique index on templateDataId in the Template table is good for ensuring that each template has a unique data reference. However, ensure that the application logic supports this constraint and that there are no use cases where a template might share data with another template.

  • 46-52: Foreign key constraints are set to ON DELETE CASCADE and ON UPDATE CASCADE. This is a critical behavior that should be confirmed with the application's data management strategy, as it will automatically delete or update related records, which might not always be desirable.

packages/prisma/migrations/20231007211915_template_created_date/migration.sql (1)
  • 8-9: The issue with the updatedAt column not having a default value has not been resolved. Existing rows in the Template table will lack a value for this column, which could lead to errors. Consider implementing the previous suggestion to add a default value or use a trigger to update this field.
packages/prisma/migrations/20231017042227_fix_typo/migration.sql (2)
  • 5-20: Before applying the unique constraint on the templateDocumentDataId column, ensure that there are no existing duplicate values in the table, as this will cause the migration to fail.

  • 22-23: Verify that the ON DELETE CASCADE ON UPDATE CASCADE actions on the foreign key are intended and align with the application's data integrity requirements.

packages/prisma/migrations/20231208090322_remove_template_specific_models/migration.sql (5)
  • 1-6: Before executing this migration, verify that there are backups of the TemplateField and TemplateRecipient tables, and that the data is either no longer needed or has been migrated to a new structure.

  • 6-6: Ensure a pre-migration script is run to identify and resolve any duplicate [templateId,email] entries in the Recipient table before applying the unique constraint.

  • 22-30: Confirm that the application logic has been updated to handle the new templateId column and the nullable state of the previously NOT NULL columns in the Field and Recipient tables.

  • 38-54: Check that the newly created indices and foreign key constraints are correctly set up and reference the intended columns and tables, especially after the schema changes.

  • 47-54: Ensure that the cascading delete and update behavior introduced by the new foreign key constraints is intentional and won't lead to unintended data loss or inconsistency.

packages/prisma/schema.prisma (6)
  • 43-43: The addition of the Template relation to the User model aligns with the PR's objectives to enhance template functionality.

  • 158-158: The addition of the optional Template relation to the DocumentData model aligns with the PR's objectives to allow documents to be associated with templates.

  • 185-207: The changes to the Recipient model, including the addition of templateId, templateToken, and the adjustments to the nullability of certain fields, are consistent with the PR's objectives to link recipients to templates and documents.

  • 228-240: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [220-237]

The changes to the Field model, including the addition of templateId and the new relation to Template, are consistent with the PR's objectives to allow fields to be associated with both documents and templates.

  • 268-287: The introduction of the Template model with its fields and relations is consistent with the PR's objectives to support template functionality within the application.

  • 191-191: The addition of the templateToken field to the Recipient model has been previously discussed and explained by the developers, indicating its purpose in linking recipients to the original template recipients.

packages/trpc/server/router.ts (3)
  • 9-9: The addition of templateRouter to the imports is consistent with the PR's objective to handle template-related operations.

  • 23-23: The integration of templateRouter into the appRouter object is correctly implemented, aligning with the PR's objectives to introduce new routing logic for templates.

  • 6-12: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [6-26]

The changes to router.ts are well-contained and align with the PR's objectives. Ensure that the new templateToken property in the SinglePlayerClient function, as mentioned in the PR overview, is also correctly implemented in the relevant part of the codebase.

packages/trpc/server/template-router/router.ts (1)
  • 1-94: The templateRouter setup and the associated CRUD operations for templates are implemented correctly, following standard practices for a TRPC router in a TypeScript project.
packages/trpc/server/template-router/schema.ts (2)
  • 3-18:
    The Zod schemas for template operations are well-defined. Ensure that the validation rules align with the corresponding database schema and the rest of the application's validation logic.

  • 20-26:
    The inferred types from the Zod schemas are correctly exported. Verify that these types are utilized in the relevant parts of the codebase to maintain type safety.

packages/ui/primitives/dialog.tsx (1)
  • 23-26: The change in z-index to z-[9999] ensures the dialog overlays other elements, but consider verifying that this does not introduce any visual stacking issues with other fixed or absolute elements in the application.
packages/ui/primitives/document-dropzone.tsx (4)
  • 91-91: The addition of the type property to DocumentDropzoneProps is consistent with the PR's objectives to handle different types of documents.

  • 78-85: The DocumentDescription object is a clean way to manage different headlines for the DocumentDropzone component based on the type property.

  • 99-99: Setting the default value of type to 'document' ensures backward compatibility for existing uses of DocumentDropzone where the type may not be provided.

  • 171-171: The use of DocumentDescription[type].headline correctly displays the headline based on the type property. Ensure that the type property is validated elsewhere in the code to only allow 'document' or 'template'.

packages/ui/primitives/template-flow/add-template-fields.tsx (13)
  • 3-35: The imports are well-organized and seem to be relevant to the functionality of the component. It's good to see that unused imports, such as the commented-out Tooltip imports, are being removed to keep the code clean.

  • 41-46: The fontCaveat is defined outside of the component, which is good for performance as it won't be redefined on each render. However, ensure that the Caveat function and the fontCaveat variable are used elsewhere in the application to justify their inclusion.

  • 54-59: The AddTemplateFieldsFormProps type definition is clear and well-defined. It's good to see TypeScript being used to enforce type safety for component props.

  • 62-68: The AddTemplateFieldsFormPartial component is well-structured and the props are destructured, which improves readability.

  • 73-95: The use of useForm from react-hook-form is appropriate for managing form state and handling submissions. The default values are set based on the fields prop, which is a good practice. Ensure that the TAddTemplateFieldsFormSchema type accurately reflects the expected structure of the form data.

  • 109-117: The use of useState for managing local component state is standard in React. The naming of the state variables is clear and indicates their purpose.

  • 124-140: The onMouseMove callback is using useCallback to memoize the function, which can help with performance if the function is passed as a prop to child components or if it's used in a dependency array of effects or other callbacks.

  • 199-227: The onFieldResize callback is quite complex. Consider breaking it down into smaller, more manageable functions. This will improve readability and maintainability.

  • 229-250: The onFieldMove callback is quite complex. Consider breaking it down into smaller, more manageable functions. This will improve readability and maintainability.
  • 252-262: The useEffect hook is used to add and remove event listeners based on the selectedField state. This is a good use of the hook to ensure that event listeners are cleaned up when they are no longer needed.

  • 264-288: The useEffect hook is used to observe changes in the document body and update the fieldBounds ref accordingly. This is a good use of MutationObserver to react to DOM changes. However, ensure that the observed changes are relevant to the component's functionality and that this does not lead to unnecessary updates or performance issues.

  • 290-292: The useEffect hook is used to set the default selected signer. This is a good practice to initialize component state based on props.

  • 294-538: The component's return statement is well-structured and uses conditional rendering effectively. The use of utility classes and conditional class names with cn is a good practice for dynamic styling. Ensure that all the utility classes used are defined and behave as expected.

packages/ui/primitives/template-flow/add-template-fields.types.ts (1)
  • 1-23: The Zod schema and TypeScript type definition for adding template fields appear to be correctly defined and make use of the zod library for runtime validation and TypeScript for compile-time type safety. The use of FieldType from @documenso/prisma/client ensures consistency with the database schema.

@Mythie
Copy link
Collaborator

Mythie commented Dec 14, 2023

Just the last few comments and request to change up the server actions to tRPC endpoints since we've since tossed them 🙏

We're so close now, sorry for taking so long boss 🫡

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1eeb5fb and 82da337.
Files selected for processing (8)
  • apps/marketing/src/app/(marketing)/singleplayer/client.tsx (2 hunks)
  • packages/lib/server-only/recipient/set-recipients-for-template.ts (1 hunks)
  • packages/lib/server-only/template/create-document-from-template.ts (1 hunks)
  • packages/lib/server-only/template/duplicate-template.ts (1 hunks)
  • packages/prisma/migrations/20231214081915_remove_template_token_column/migration.sql (1 hunks)
  • packages/prisma/schema.prisma (6 hunks)
  • packages/trpc/server/singleplayer-router/router.ts (1 hunks)
  • packages/ui/primitives/template-flow/add-template-fields.tsx (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/lib/server-only/template/create-document-from-template.ts
  • packages/lib/server-only/template/duplicate-template.ts
Files skipped from review as they are similar to previous changes (2)
  • apps/marketing/src/app/(marketing)/singleplayer/client.tsx
  • packages/lib/server-only/recipient/set-recipients-for-template.ts
Additional comments: 19
packages/prisma/schema.prisma (5)
  • 43-43: The addition of the Template relation to the User model aligns with the PR's objectives to enhance template functionality.

  • 158-158: The addition of the optional Template relation to the DocumentData model is consistent with the PR's objectives.

  • 263-287: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [185-287]

The changes to the Recipient model, including making certain fields nullable and adding new fields and relations, are in line with the PR's objectives. Ensure that the new unique constraints and indexes are properly reviewed and tested to maintain data integrity and performance.

  • 227-239: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [219-236]

The updates to the Field model, including the addition of templateId and the update to relations, support the new template features as described in the PR.

  • 267-287: The new Template model with its fields and relations is a key addition to support the template functionality as outlined in the PR.
packages/trpc/server/singleplayer-router/router.ts (1)
  • 66-66: The addition of templateId: null is noted. Please ensure that setting this to null is intentional and that it aligns with the current implementation and future plans for template functionality. If this is a placeholder for future work, consider adding a comment or TODO to clarify its purpose.
packages/ui/primitives/template-flow/add-template-fields.tsx (13)
  • 1-35: The imports and component declarations seem to be in order, with no apparent issues regarding unused imports or missing dependencies.

  • 41-46: The fontCaveat is defined but not used within the provided code. If it's not used elsewhere, consider removing it to keep the code clean.

Verification successful

The fontCaveat variable is used in multiple places within the codebase, including within the same file where it is defined. Therefore, it should not be removed. The code does not require any changes regarding this variable.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for usage of `fontCaveat` in the codebase.
rg 'fontCaveat'

Length of output: 1945

* 54-60: The `AddTemplateFieldsFormProps` type definition is clear and well-defined.
  • 62-97: The component AddTemplateFieldsFormPartial is well-structured, and the use of hooks for form management and field arrays is appropriate.

  • 109-117: The state management for selectedField, selectedSigner, and showRecipientsSelector is straightforward and follows React best practices.

  • 124-140: The onMouseMove callback is well-implemented using useCallback for performance optimization.

  • 143-197: The onMouseClick callback is complex and handles several operations. Ensure that all edge cases are covered, especially with the conditional checks and DOM interactions.

  • 199-227: The onFieldResize callback is complex. Consider breaking it down into smaller, more manageable functions. This will improve readability and maintainability.

  • This comment has been made in a previous review and is still valid.
  • 229-250: The onFieldMove callback is complex. Consider breaking it down into smaller, more manageable functions. This will improve readability and maintainability.
  • This comment has been made in a previous review and is still valid.
  • 252-262: The useEffect for adding and removing event listeners is correctly implemented with cleanup to prevent memory leaks.

  • 264-288: The useEffect for observing DOM mutations and setting field bounds is a good use of MutationObserver. Ensure that it does not cause performance issues with frequent DOM changes.

  • 290-292: The useEffect hook that sets the default selected signer is clear and concise.

  • 294-538: The render method is well-organized, and the use of conditional rendering is appropriate. Ensure that all UI components have been tested for proper rendering and functionality.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 82da337 and c40c9b2.
Files selected for processing (1)
  • packages/prisma/schema.prisma (6 hunks)
Additional comments: 4
packages/prisma/schema.prisma (4)
  • 44-44: Adding a new relation Template to the User model is consistent with the PR's objective to introduce template functionality. Ensure that the necessary migrations are created and applied to handle this new relationship in the database.

  • 184-203: The Recipient model has been updated with new fields and relations to support templates. Ensure that the unique and index constraints on templateId and email are appropriate and that they do not conflict with existing constraints.

  • 226-238: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [218-235]

The Field model now includes optional relations to both Document and Template. Verify that the business logic correctly handles cases where a Field might be associated with either a Document or a Template, but not both.

  • 266-286: The new Template model has been added with appropriate fields and relations. Ensure that the TemplateType enum is used correctly throughout the application and that the templateDocumentDataId field is handled properly, especially in terms of deletion behavior.

packages/prisma/schema.prisma Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c40c9b2 and 268a5c6.
Files selected for processing (7)
  • apps/marketing/src/components/constants.ts (1 hunks)
  • apps/web/src/app/(dashboard)/templates/[id]/edit-template.tsx (1 hunks)
  • packages/trpc/server/field-router/router.ts (2 hunks)
  • packages/trpc/server/field-router/schema.ts (1 hunks)
  • packages/trpc/server/recipient-router/router.ts (2 hunks)
  • packages/trpc/server/recipient-router/schema.ts (1 hunks)
  • packages/ui/primitives/template-flow/add-template-placeholder-recipients.types.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/marketing/src/components/constants.ts
Additional comments: 2
packages/trpc/server/recipient-router/schema.ts (1)
  • 26-47: The new ZAddTemplateSignersMutationSchema and its corresponding type TAddTemplateSignersMutationSchema are consistent with the existing patterns and correctly enforce unique emails.
packages/trpc/server/field-router/schema.ts (1)
  • 24-41: The ZAddTemplateFieldsMutationSchema and its corresponding type TAddTemplateFieldsMutationSchema are correctly defined and follow the existing patterns.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 268a5c6 and 7babd82.
Files selected for processing (11)
  • apps/web/src/app/(dashboard)/documents/duplicate-document-dialog.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/data-table-templates.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/delete-template-dialog.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/duplicate-template-dialog.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/new-template-dialog.tsx (1 hunks)
  • packages/lib/server-only/admin/get-recipients-stats.ts (1 hunks)
  • packages/lib/server-only/field/set-fields-for-document.ts (1 hunks)
  • packages/lib/server-only/field/set-fields-for-template.ts (1 hunks)
  • packages/lib/server-only/template/get-templates.ts (1 hunks)
  • packages/prisma/migrations/20231221070056_make_recipient_status_columns_non_null_again/migration.sql (1 hunks)
  • packages/prisma/schema.prisma (6 hunks)
Additional comments: 7
packages/lib/server-only/admin/get-recipients-stats.ts (1)
  • 20-27: Ensure that the aggregation logic in getRecipientsStats correctly handles cases where a recipient may have multiple statuses. If a recipient can only have one status at a time, this logic is correct. Otherwise, the counts may be inflated.
packages/lib/server-only/field/set-fields-for-document.ts (1)
  • 2-3: The change to use the type keyword for importing FieldType is a good practice in TypeScript to ensure that only the type is imported and not the runtime object.
packages/prisma/schema.prisma (5)
  • 44-44: The addition of the Template relation to the User model is consistent with the PR's objectives. Ensure that the cascade behavior is correctly defined for this relation to maintain referential integrity.

  • 157-157: The addition of an optional Template relation to the DocumentData model aligns with the PR's objective. However, consider if there should be any constraints or cascading behaviors defined for this relation.

  • 184-203: The Recipient model now includes a templateId field and a relation to the Template model. Verify that the unique and index constraints are correctly applied and consider the implications of the onDelete behavior for the Template relation.

  • 226-238: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [218-235]

The Field model now includes a templateId field and a relation to the Template model. Ensure that the indexes are correctly defined and review the onDelete behavior for the Template relation.

  • 272-286: The new Template model is introduced with fields and relations that align with the PR's objectives. Ensure that the unique constraint on templateDocumentDataId is appropriate and that the onDelete behavior for the User relation is correctly defined.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7babd82 and 972c20f.
Files selected for processing (1)
  • packages/prisma/migrations/20231221101005_add_templates/migration.sql (1 hunks)
Additional comments: 9
packages/prisma/migrations/20231221101005_add_templates/migration.sql (9)
  • 8-8: Creation of the TemplateType enum is a good practice for ensuring data integrity for the type field in the Template table.

  • 11-11: Verify the impact of dropping the foreign key constraint on the Field table. Ensure that this change is coordinated with any necessary data migrations or application logic updates.

  • 14-15: Adding a templateId column and making documentId nullable in the Field table allows for associating fields with either a document or a template, but not both. Ensure that the application logic enforces this constraint correctly.

  • 19-22: The CHECK constraint added to the Field table is a good practice to ensure data integrity by allowing only one of templateId or documentId to be set.

  • 25-26: Similar to the Field table, adding a templateId column and making documentId nullable in the Recipient table allows for associating recipients with either a document or a template. Verify that the application logic correctly enforces this constraint.

  • 30-33: The CHECK constraint added to the Recipient table is a good practice to ensure data integrity by allowing only one of templateId or documentId to be set.

  • 36-45: The creation of the Template table with appropriate fields and constraints is well-defined and supports the new template functionality.

  • 49-58: The creation of unique and non-unique indexes on the Template, Field, and Recipient tables is a good practice for optimizing query performance.

  • 61-73: The addition of foreign key constraints to the Recipient, Field, and Template tables is a good practice for maintaining referential integrity across the database.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 972c20f and 9ad94f9.
Files selected for processing (2)
  • apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/templates/[id]/page.tsx (1 hunks)
Additional comments: 8
apps/web/src/app/(dashboard)/templates/[id]/page.tsx (6)
  • 1-12: Imports are well-organized and relevant to the functionality of the page.

  • 17-21: The TemplatePageProps type is correctly defined and used to type the component's props.

  • 26-30: Good validation check for templateId to ensure it's a valid number before proceeding with data fetching.

  • 39-41: Proper validation to ensure that the template and its templateDocumentData are present before rendering the component.

  • 45-54: Efficient use of Promise.all to fetch templateRecipients and templateFields concurrently, reducing wait time.

  • 71-78: The EditTemplateForm component is correctly rendered with props derived from the fetched data, ensuring it has all the necessary information to function.

apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx (2)
  • 101-102: The addition of nonSignedRecipients is a logical change that filters out recipients who have signed the document. This ensures that actions such as resending the document are only available to recipients who have not yet signed.

  • 99-105: The logic within DataTableActionDropdown is well-structured, with clear conditions for enabling and disabling menu items based on document status and user role.

@Mythie Mythie merged commit 48cdf43 into main Dec 21, 2023
12 of 13 checks passed
@Mythie Mythie deleted the feat/document-templates branch December 21, 2023 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apps: marketing Issues related to website or marketing app apps: web Issues related to the webapp coderabbit 🚨 migrations 🚨
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants