From 193325717d7970a99bfb79be92a845966d9f030e Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Wed, 23 Apr 2025 21:40:42 +1000 Subject: [PATCH 1/4] fix: rework fields (#1697) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rework: - Field styling to improve visibility - Field insertions, better alignment, centering and overflows ## Changes General changes: - Set default text alignment to left if no meta found - Reduce borders and rings around fields to allow smaller fields - Removed lots of redundant duplicated code surrounding field rendering - Make fields more consistent across viewing, editing and signing - Add more transparency to fields to allow users to see under fields - No more optional/required/etc colors when signing, required fields will be highlighted as orange when form is "validating" Highlighted internal changes: - Utilize native PDF fields to insert text, instead of drawing text - Change font auto scaling to only apply to when the height overflows AND no custom font is set ⚠️ Multiline changes: Multi line is enabled for a field under these conditions 1. Field content exceeds field width 2. Field includes a new line 3. Field type is TEXT ## [BEFORE] Field UI Signing ![image](https://github.com/user-attachments/assets/ea002743-faeb-477c-a239-3ed240b54f55) ## [AFTER] Field UI Signing ![image](https://github.com/user-attachments/assets/0f8eb252-4cf3-4d96-8d4f-cd085881b78c) ## [BEFORE] Signing a checkbox ![image](https://github.com/user-attachments/assets/4567d745-e1da-4202-a758-5d3c178c930e) ![image](https://github.com/user-attachments/assets/c25068e7-fe80-40f5-b63a-e8a0d4b38b6c) ## [AFTER] Signing a checkbox ![image](https://github.com/user-attachments/assets/effa5e3d-385a-4c35-bc8a-405386dd27d6) ![image](https://github.com/user-attachments/assets/64be34a9-0b32-424d-9264-15361c03eca5) ## [BEFORE] What a 2nd recipient sees once someone else signed a document ![image](https://github.com/user-attachments/assets/21c21ae2-fc62-4ccc-880a-46aab012aa70) ## [AFTER] What a 2nd recipient sees once someone else signed a document ![image](https://github.com/user-attachments/assets/ae51677b-f1d5-4008-a7fd-756533166542) ## **[BEFORE]** Inserting fields ![image](https://github.com/user-attachments/assets/1a8bb8da-9a15-4deb-bc28-eb349414465c) ## **[AFTER]** Inserting fields ![image](https://github.com/user-attachments/assets/c52c5238-9836-45aa-b8a4-bc24a3462f40) ## Overflows, multilines and field alignments testing Debugging borders: - Red border = The original field placement without any modifications - Blue border = The available space to overflow ### Single line overflows and field alignments This is left aligned fields, overflow will always go to the end of the page and will not wrap ![image](https://github.com/user-attachments/assets/47003658-783e-4f9c-adbf-c4686804d98f) This is center aligned fields, the max width is the closest edge to the page * 2 ![image](https://github.com/user-attachments/assets/05a38093-75d6-4600-bae2-21ecff63e115) This is right aligned text, the width will extend all the way to the left hand side of the page ![image](https://github.com/user-attachments/assets/6a9d84a8-4166-4626-9fb3-1577fac2571e) ### Multiline line overflows and field alignments These are text fields that can be overflowed ![image](https://github.com/user-attachments/assets/f7b5456e-2c49-48b2-8d4c-ab1dc3401644) Another example of left aligned text overflows with more text ![image](https://github.com/user-attachments/assets/3db6b35e-4c8d-4ffe-8036-0da760d9c167) --- .../dialogs/template-bulk-send-dialog.tsx | 2 +- .../embed/authoring/configure-fields-view.tsx | 6 +- .../embed/embed-document-signing-page.tsx | 2 +- .../direct-template-configure-form.tsx | 23 +- .../document-signing-checkbox-field.tsx | 42 +- .../document-signing-complete-dialog.tsx | 2 +- .../document-signing-date-field.tsx | 10 +- .../document-signing-dropdown-field.tsx | 10 +- .../document-signing-email-field.tsx | 35 +- .../document-signing-field-container.tsx | 52 ++- .../document-signing-fields.tsx | 51 +++ .../document-signing-initials-field.tsx | 24 +- .../document-signing-name-field.tsx | 39 +- .../document-signing-number-field.tsx | 47 +-- .../document-signing-page-view.tsx | 8 +- .../document-signing-radio-field.tsx | 48 ++- .../document-signing-signature-field.tsx | 6 +- .../document-signing-text-field.tsx | 61 +-- .../document/document-read-only-fields.tsx | 171 -------- .../general/legacy-field-warning-popover.tsx | 112 +++++ .../_authenticated+/documents.$id._index.tsx | 12 +- .../_authenticated+/documents.$id.edit.tsx | 55 ++- .../_authenticated+/templates.$id._index.tsx | 5 +- .../_authenticated+/templates.$id.edit.tsx | 9 +- .../internal/seal-document.handler.ts | 5 +- .../lib/server-only/document/seal-document.ts | 5 +- .../server-only/document/update-document.ts | 5 +- .../server-only/pdf/insert-field-in-pdf.ts | 310 ++++++++++++-- .../pdf/legacy-insert-field-in-pdf.ts | 395 ++++++++++++++++++ .../create-document-from-template-legacy.ts | 1 + .../template/create-document-from-template.ts | 1 + .../server-only/template/update-template.ts | 2 + packages/lib/types/document.ts | 2 + packages/lib/types/template.ts | 2 + .../migration.sql | 5 + .../migration.sql | 5 + packages/prisma/schema.prisma | 11 +- packages/tailwind-config/index.cjs | 8 + .../document-router/update-document.types.ts | 1 + .../trpc/server/template-router/schema.ts | 1 + .../document/document-read-only-fields.tsx | 170 ++++++++ packages/ui/components/field/field.tsx | 106 ++--- packages/ui/lib/recipient-colors.ts | 95 +++++ packages/ui/lib/signer-colors.ts | 108 ----- .../primitives/document-flow/add-fields.tsx | 24 +- .../primitives/document-flow/add-settings.tsx | 16 +- .../primitives/document-flow/add-signers.tsx | 16 +- .../primitives/document-flow/add-subject.tsx | 16 +- .../advanced-fields/checkbox.tsx | 46 -- .../document-flow/advanced-fields/radio.tsx | 49 --- .../document-flow/field-content.tsx | 188 +++++++++ .../primitives/document-flow/field-icon.tsx | 72 ---- .../field-item-advanced-settings.tsx | 12 +- .../primitives/document-flow/field-item.tsx | 73 ++-- .../document-flow/show-field-item.tsx | 49 --- packages/ui/primitives/element-visible.tsx | 7 +- packages/ui/primitives/popover.tsx | 5 +- packages/ui/primitives/recipient-selector.tsx | 10 +- .../template-flow/add-template-fields.tsx | 176 ++++---- .../add-template-placeholder-recipients.tsx | 17 +- .../template-flow/add-template-settings.tsx | 16 +- packages/ui/styles/theme.css | 27 +- 62 files changed, 1819 insertions(+), 1070 deletions(-) create mode 100644 apps/remix/app/components/general/document-signing/document-signing-fields.tsx delete mode 100644 apps/remix/app/components/general/document/document-read-only-fields.tsx create mode 100644 apps/remix/app/components/general/legacy-field-warning-popover.tsx create mode 100644 packages/lib/server-only/pdf/legacy-insert-field-in-pdf.ts create mode 100644 packages/prisma/migrations/20250423062206_add_legacy_field_insertion_column/migration.sql create mode 100644 packages/prisma/migrations/20250423062248_set_legacy_field_insert_default_to_false/migration.sql create mode 100644 packages/ui/components/document/document-read-only-fields.tsx create mode 100644 packages/ui/lib/recipient-colors.ts delete mode 100644 packages/ui/lib/signer-colors.ts delete mode 100644 packages/ui/primitives/document-flow/advanced-fields/checkbox.tsx delete mode 100644 packages/ui/primitives/document-flow/advanced-fields/radio.tsx create mode 100644 packages/ui/primitives/document-flow/field-content.tsx delete mode 100644 packages/ui/primitives/document-flow/field-icon.tsx delete mode 100644 packages/ui/primitives/document-flow/show-field-item.tsx diff --git a/apps/remix/app/components/dialogs/template-bulk-send-dialog.tsx b/apps/remix/app/components/dialogs/template-bulk-send-dialog.tsx index d210550c6..cd700ac1e 100644 --- a/apps/remix/app/components/dialogs/template-bulk-send-dialog.tsx +++ b/apps/remix/app/components/dialogs/template-bulk-send-dialog.tsx @@ -114,7 +114,7 @@ export const TemplateBulkSendDialog = ({ {trigger ?? ( - diff --git a/apps/remix/app/components/embed/authoring/configure-fields-view.tsx b/apps/remix/app/components/embed/authoring/configure-fields-view.tsx index 24b4801c1..68d833d38 100644 --- a/apps/remix/app/components/embed/authoring/configure-fields-view.tsx +++ b/apps/remix/app/components/embed/authoring/configure-fields-view.tsx @@ -16,7 +16,7 @@ import { type TFieldMetaSchema, ZFieldMetaSchema } from '@documenso/lib/types/fi import { base64 } from '@documenso/lib/universal/base64'; import { nanoid } from '@documenso/lib/universal/id'; import { ADVANCED_FIELD_TYPES_WITH_OPTIONAL_SETTING } from '@documenso/lib/utils/advanced-fields-helpers'; -import { useSignerColors } from '@documenso/ui/lib/signer-colors'; +import { useRecipientColors } from '@documenso/ui/lib/recipient-colors'; import { cn } from '@documenso/ui/lib/utils'; import { Button } from '@documenso/ui/primitives/button'; import { FieldItem } from '@documenso/ui/primitives/document-flow/field-item'; @@ -162,7 +162,7 @@ export const ConfigureFieldsView = ({ }); const selectedRecipientIndex = recipients.findIndex((r) => r.id === selectedRecipient?.id); - const selectedSignerStyles = useSignerColors( + const selectedRecipientStyles = useRecipientColors( selectedRecipientIndex === -1 ? 0 : selectedRecipientIndex, ); @@ -505,7 +505,7 @@ export const ConfigureFieldsView = ({
- {isDocumentPdfLoaded && - directTemplateRecipient.fields.map((field, index) => ( - - ))} + {isDocumentPdfLoaded && ( + recipient.id)} + showRecipientColors={true} + /> + )}
{ try { + // Do nothing, this should only happen when the user clicks the field, but + // misses the checkbox which triggers this callback. + if (checkedValues.length === 0) { + return; + } + if (!isLengthConditionMet) { return; } @@ -270,21 +276,26 @@ export const DocumentSigningCheckboxField = ({ {validationSign?.label} {checkboxValidationLength} )} -
+
{values?.map((item: { id: number; value: string; checked: boolean }, index: number) => { const itemValue = item.value || `empty-value-${item.id}`; return ( -
+
handleCheckboxChange(item.value, item.id)} /> - + {!item.value.includes('empty-value-') && item.value && ( + + )}
); })} @@ -293,22 +304,27 @@ export const DocumentSigningCheckboxField = ({ )} {field.inserted && ( -
+
{values?.map((item: { id: number; value: string; checked: boolean }, index: number) => { const itemValue = item.value || `empty-value-${item.id}`; return ( -
+
void handleCheckboxOptionClick(item)} /> - + {!item.value.includes('empty-value-') && item.value && ( + + )}
); })} diff --git a/apps/remix/app/components/general/document-signing/document-signing-complete-dialog.tsx b/apps/remix/app/components/general/document-signing/document-signing-complete-dialog.tsx index 6dd9ba3e6..a14f9719c 100644 --- a/apps/remix/app/components/general/document-signing/document-signing-complete-dialog.tsx +++ b/apps/remix/app/components/general/document-signing/document-signing-complete-dialog.tsx @@ -281,7 +281,7 @@ export const DocumentSigningCompleteDialog = ({