Repository navigation
feat: add certificate translations - #1440
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
5 Skipped Deployments
|
WalkthroughThe changes in this pull request primarily enhance internationalization (i18n) across various components in the application. Key modifications include the simplification of audit log action descriptions, the integration of localization support using the Lingui library, and the removal of unnecessary functions. The updates affect components such as Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
🚨 @dguyen has 4 pull requests awaiting review. Please consider reviewing them when possible. 🚨 |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (12)
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx (3)
28-30: Enhance the documentation commentWhile the comment is helpful, it would be more maintainable if it explained why
transshould be avoided in this context.Consider expanding the comment:
/** - * DO NOT USE TRANS. YOU MUST USE _ FOR THIS FILE AND ALL CHILDREN COMPONENTS. + * IMPORTANT: Use the `_` function instead of `trans` for this file and all children components. + * This ensures consistent translation handling for PDF generation where dynamic translations + * need to be evaluated at render time. */
31-32: Consider adding type safety for translationsWhile the Lingui setup is correct, consider adding type safety to prevent translation key errors.
Consider creating a type-safe messages catalog:
// messages.ts export const messages = { time: msg`Time`, user: msg`User`, action: msg`Action`, ipAddress: msg`IP Address`, browser: msg`Browser`, } as const;This would help catch missing translations at compile time.
44-48: Consider extracting table headers configurationWhile the translations are implemented correctly, the table headers could be more maintainable if extracted into a configuration object.
Consider refactoring to:
const TABLE_HEADERS = [ { key: 'time', label: msg`Time` }, { key: 'user', label: msg`User` }, { key: 'action', label: msg`Action` }, { key: 'ipAddress', label: msg`IP Address` }, { key: 'browser', label: msg`Browser` }, ] as const; // Then in JSX: {TABLE_HEADERS.map((header) => ( <TableHead key={header.key}>{_(header.label)}</TableHead> ))}apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-data-table.tsx (1)
102-102: Consider internationalizing remaining static text.While most of the component is properly internationalized, there are a few remaining strings that should be translated:
- The "IP Address" and "Browser" column headers
- The "N/A" fallback text
Here's how to improve it:
- header: 'IP Address', + header: _(msg`IP Address`), - header: 'Browser', + header: _(msg`Browser`), - return 'N/A'; + return _(msg`N/A`); - return result.browser.name ?? 'N/A'; + return result.browser.name ?? _(msg`N/A`);Also applies to: 108-108, 114-114, 127-127
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recent-activity.tsx (1)
148-150: Optimize duplicate function calls.The
formatDocumentAuditLogActionfunction is called twice with identical parameters. Consider extracting the description to avoid redundant computation:<p className="text-muted-foreground dark:text-muted-foreground/70 flex-auto truncate py-0.5 text-xs leading-5" - title={formatDocumentAuditLogAction(_, auditLog, userId).description} + title={description} > - {formatDocumentAuditLogAction(_, auditLog, userId).description} + {description} </p>Add this before the return statement:
const description = formatDocumentAuditLogAction(_, auditLog, userId).description;apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx (3)
28-33: Clarify the comment regarding internationalization usage.The comment specifies not to use
transand to use_instead. For better clarity, consider elaborating on whytransshould not be used and provide guidance for contributors.Apply this diff to enhance the comment:
/** - * DO NOT USE TRANS. YOU MUST USE _ FOR THIS FILE AND ALL CHILDREN COMPONENTS. + * Do not use `trans`. You must use `_` for this file and all child components. * * Cannot use dynamicActivate by itself to translate this specific page and all * children components because `not-found.tsx` page runs and overrides the i18n. */
61-62: Address the TODO: Implement dynamic language activation.There's a TODO comment indicating the need to activate the appropriate language once metadata is available. Implementing this will ensure users see the audit log in their preferred language.
Would you like assistance in implementing dynamic language activation based on the document's metadata? I can help draft code that activates the language dynamically when the metadata becomes available.
Line range hint
109-119: Date formatting uses default locale—consider dynamic locale support.Currently, dates are formatted using
APP_I18N_OPTIONS.defaultLocale. To enhance user experience, consider formatting dates based on the user's locale or the document's metadata.You might adjust the code to use a dynamic locale:
{DateTime.fromJSDate(document.createdAt) - .setLocale(APP_I18N_OPTIONS.defaultLocale) + .setLocale(currentLocale) // Assume `currentLocale` is determined dynamically .toFormat('yyyy-MM-dd hh:mm:ss a (ZZZZ)')}Ensure that
currentLocaleis defined based on available metadata or user preferences.apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx (4)
46-51: Consider refining the explanatory comment for clarityThe comment provides important information about using
_for localization due to issues withnot-found.tsxoverriding the i18n settings. Consider refining the wording for clarity or documenting this behavior in a central location if it affects multiple files.
79-81: Address the TODO regarding language metadataThere's a TODO comment about adding metadata to determine which language to use and dynamically activating it. Implementing this will enhance the localization functionality of the certificate.
Would you like assistance in implementing dynamic language activation or opening a GitHub issue to track this task?
246-274: Consider using the recipient's locale for date formattingCurrently, dates are formatted using
APP_I18N_OPTIONS.defaultLocale. If the recipient's preferred language or locale is known, consider using it to format dates for a more personalized experience.
281-285: Avoid redundant localization wrappingThe
FRIENDLY_SIGNING_REASONSvalues are already localized usingmsg. Wrapping them again with_might be unnecessary. Consider removing the extra_to prevent redundant processing.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (9)
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recent-activity.tsx(1 hunks)apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-data-table.tsx(1 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx(4 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx(6 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx(9 hunks)apps/web/src/components/document/document-history-sheet.tsx(3 hunks)packages/lib/constants/document.ts(1 hunks)packages/lib/constants/recipient-roles.ts(0 hunks)packages/lib/utils/document-audit-logs.ts(2 hunks)
💤 Files with no reviewable changes (1)
- packages/lib/constants/recipient-roles.ts
🔇 Additional comments (23)
packages/lib/constants/document.ts (2)
1-4: LGTM! Imports are well-structured.
The imports are properly organized, with external dependencies first followed by internal ones. The types and utilities are appropriately imported for i18n support.
6-18: LGTM! Well-structured constant with type safety.
The implementation provides a type-safe mapping for document status translations. The structure is clean and allows for future extensibility.
Consider these architectural points for future iterations:
- If more properties are added later, consider renaming
descriptionto something more specific likedisplayNameorlabel - Consider adding a
colororvariantproperty for UI consistency if these statuses need visual representation
Let's verify that all DocumentStatus enum values are covered:
✅ Verification successful
Let me try another script to find the enum definition since the previous pattern didn't match:
✅ All DocumentStatus enum values are properly mapped
The enum values in packages/prisma/schema.prisma (DRAFT, PENDING, COMPLETED) perfectly match the mappings in DOCUMENT_STATUS. The implementation is complete and type-safe.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all DocumentStatus enum values are mapped in DOCUMENT_STATUS
# Search for the DocumentStatus enum definition
echo "DocumentStatus enum definition:"
ast-grep --pattern 'enum DocumentStatus {
$$$
}'
# Compare with the constant mapping
echo -e "\nDOCUMENT_STATUS mapping:"
rg '\[DocumentStatus\.' "packages/lib/constants/document.ts"
Length of output: 341
Script:
#!/bin/bash
# Search for DocumentStatus enum with different pattern and show surrounding context
rg -A 10 "enum\s+DocumentStatus"
Length of output: 488
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx (2)
1-2: LGTM: Proper i18n imports added
The addition of Lingui imports follows best practices for internationalization.
82-82: 🛠️ Refactor suggestion
Multiple improvements needed for text transformation
- There's a typo in the utility function name (
uppercaseFistLetter→uppercaseFirstLetter) - Consider using CSS for text transformation instead of JavaScript
Replace the current implementation with:
- {uppercaseFistLetter(formatDocumentAuditLogAction(_, log).description)}
+ <span className="first-letter:uppercase">
+ {formatDocumentAuditLogAction(_, log).description}
+ </span>Add to your CSS:
.first-letter:uppercase:first-letter {
text-transform: uppercase;
}Let's verify if this text transformation is consistently applied across the application:
✅ Verification successful
Fix typo in utility function and consider CSS-based text transformation
The verification confirms that:
- The typo
uppercaseFistLetteris only used within this specific file - No existing CSS-based uppercase transformations were found in the codebase
Given this is an isolated case with a clear typo and no established pattern for text transformations in the codebase, the original review suggestions remain valid:
- Fix the typo in the function name
- Consider using CSS for better maintainability and performance
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for other instances of uppercase transformations
rg -l "uppercase.*letter|text-transform.*uppercase" --type css
rg "uppercaseFist|uppercaseFirst"
Length of output: 374
apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-data-table.tsx (1)
102-102: LGTM! Proper i18n implementation for audit log actions.
The change correctly implements internationalization for audit log actions by using formatDocumentAuditLogAction with the translation context. The removal of manual text casing is appropriate as this should be handled by the translations themselves.
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recent-activity.tsx (1)
Line range hint 1-159: Well-implemented internationalization.
The component demonstrates thorough and consistent internationalization:
- All user-facing strings are properly wrapped with translation components
- Dynamic strings correctly use the
_(msg)pattern - Loading states and error messages are properly internationalized
apps/web/src/components/document/document-history-sheet.tsx (2)
15-15: LGTM: Clean i18n integration
The integration of internationalization support through the useLingui hook and the updated formatDocumentAuditLogAction import follows best practices for React i18n implementations.
Also applies to: 40-40
Line range hint 155-163: Verify locale-based formatting consistency
The implementation correctly uses both translated audit log descriptions and localized date formatting. However, we should verify that the date format remains consistent across different locales.
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx (8)
5-6: Imports for internationalization are correctly added.
The addition of msg from @lingui/macro and useLingui from @lingui/react is appropriate for enabling translations.
9-12: Internationalization constants are properly imported.
Importing setupI18nSSR, DOCUMENT_STATUS, and RECIPIENT_ROLES_DESCRIPTION ensures that the necessary internationalization utilities and constants are available.
35-37: Server-side internationalization is appropriately initialized.
Calling setupI18nSSR() and destructuring _ from useLingui correctly sets up internationalization for server-side rendering.
73-73: Translation of the page title is correctly implemented.
Wrapping the title "Version History" with _(msg\...`)` ensures it's translatable.
Line range hint 79-129: Translation of labels is consistently applied.
All labels such as "Document ID", "Enclosed Document", "Status", "Owner", "Created At", "Last Updated", and "Time Zone" are correctly wrapped with _(msg\...`)` for translation.
101-101: Owner information displayed correctly.
Displaying the owner's name and email is appropriate and follows the existing pattern.
129-129: Time zone handling is appropriate.
Displaying the document's time zone or 'N/A' if unavailable is suitable.
137-137: Translation of "Recipients" label is correctly implemented.
Wrapping "Recipients" with _(msg\...`)` ensures it is translatable.
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx (7)
5-6: Imports for internationalization added correctly
The imports for msg from @lingui/macro and useLingui from @lingui/react are necessary for implementing internationalization and are correctly added.
42-43: Updating friendly signing reasons with localization
The FRIENDLY_SIGNING_REASONS object now includes a localized message for '__OWNER__' and spreads RECIPIENT_ROLE_SIGNING_REASONS, which is appropriate for supporting multiple languages.
117-120: Localization of authentication levels is correctly implemented
The authentication levels are properly localized using the _(msg\...`)pattern within thematch` function.
192-192: Verify the necessity of wrapping localized strings with _
In {_(RECIPIENT_ROLES_DESCRIPTION[recipient.role].roleName)}, if roleName is already a localized string, wrapping it with _ might be redundant. Please verify whether the additional wrapping is necessary.
218-218: Localization of signature details is appropriate
The signature ID label is correctly localized using _(msg\Signature ID`)`.
225-227: Ensure consistent handling of unknown IP addresses
The IP address displays {logs.DOCUMENT_RECIPIENT_COMPLETED[0]?.ipAddress ?? _(msg\Unknown`)}. Confirm that this handles cases where the IP address might be nullorundefined` appropriately.
301-301: Footer message localization is correctly implemented
The footer message {_(msg\Signing certificate provided by`)}:` is appropriately localized, enhancing the internationalization support.
| // Todo: Translations. | ||
| export const formatDocumentAuditLogAction = (auditLog: TDocumentAuditLog, userId?: number) => { | ||
| let prefix = userId === auditLog.userId ? 'You' : auditLog.name || auditLog.email || ''; | ||
| const prefix = userId === auditLog.userId ? _(msg`You`) : auditLog.name || auditLog.email || ''; |
There was a problem hiding this comment.
Avoid exposing user email addresses in audit logs
Including auditLog.email in the prefix may inadvertently expose users' email addresses in audit logs, leading to potential PII leakage and privacy concerns.
Consider modifying the prefix to exclude the email address. Here's a suggested fix:
- const prefix = userId === auditLog.userId ? _(msg`You`) : auditLog.name || auditLog.email || '';
+ const prefix = userId === auditLog.userId ? _(msg`You`) : auditLog.name || _(msg`A user`);📝 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.
| const prefix = userId === auditLog.userId ? _(msg`You`) : auditLog.name || auditLog.email || ''; | |
| const prefix = userId === auditLog.userId ? _(msg`You`) : auditLog.name || _(msg`A user`); |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (12)
packages/lib/constants/document.ts (1)
6-18: Add JSDoc documentation for better maintainability.While the implementation is solid, adding documentation would improve maintainability and help other developers understand the purpose and usage of this constant.
Consider adding documentation like this:
+/** + * Maps document statuses to their localized descriptions. + * Used for displaying document status in the UI with proper internationalization. + */ export const DOCUMENT_STATUS: {apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx (1)
28-30: Consider enhancing the i18n usage documentationWhile the comment correctly warns about using
_instead ofTRANS, it would be more helpful to explain why this constraint exists. Consider adding:
- The reason for preferring
_overTRANS- A link to relevant i18n documentation or guidelines
- Examples of correct usage
apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-data-table.tsx (1)
102-102: LGTM! Consider adding type safety enhancement.The simplified action description rendering with proper i18n integration looks good. However, we could enhance type safety by explicitly typing the row data.
Consider this enhancement:
-cell: ({ row }) => <span>{formatDocumentAuditLogAction(_, row.original).description}</span>, +cell: ({ row: { original: log } }) => <span>{formatDocumentAuditLogAction(_, log).description}</span>,apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recent-activity.tsx (1)
Line range hint
153-155: Consider accessibility improvements for the timestamp.The relative time display could be enhanced with a more detailed timestamp in the title attribute for better accessibility.
- <time className="text-muted-foreground dark:text-muted-foreground/70 flex-none py-0.5 text-xs leading-5"> + <time + className="text-muted-foreground dark:text-muted-foreground/70 flex-none py-0.5 text-xs leading-5" + title={DateTime.fromJSDate(auditLog.createdAt).toLocaleString(DateTime.DATETIME_FULL)} + > {DateTime.fromJSDate(auditLog.createdAt).toRelative({ style: 'short' })} </time>packages/lib/utils/document-audit-logs.ts (2)
258-267: Consider adding translator comments for better contextThe
msgtemplate literals would benefit from translator comments to provide context about where and how these messages are used. This helps translators make better decisions about word choice and grammar.Example improvement:
- anonymous: msg`A field was added`, + /* Translators: Shown in audit log when a form field is added to a document */ + anonymous: msg`A field was added`,
338-349: Consider extracting recipient role message mappingThe recipient role message mapping logic could be extracted into a separate function for better maintainability and reusability.
Example refactor:
const getRecipientRoleMessage = (userName: string, role: RecipientRole, _: I18n['_']) => { return match(role) .with(RecipientRole.SIGNER, () => msg`${userName} signed the document`) .with(RecipientRole.VIEWER, () => msg`${userName} viewed the document`) .with(RecipientRole.APPROVER, () => msg`${userName} approved the document`) .with(RecipientRole.CC, () => msg`${userName} CC'd the document`) .otherwise(() => msg`${userName} completed their task`); };Then use it in the main function:
const result = getRecipientRoleMessage(userName, data.recipientRole, _);apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx (1)
249-252: Consider dynamic locale for DateTime formattingCurrently, DateTime formatting uses
APP_I18N_OPTIONS.defaultLocale. Once language selection is implemented, this should be updated to use the user's selected locale for consistent internationalization.Example implementation:
- .setLocale(APP_I18N_OPTIONS.defaultLocale) + .setLocale(selectedLocale || APP_I18N_OPTIONS.defaultLocale)Also applies to: 260-263, 271-274
apps/web/src/components/document/document-history-sheet.tsx (1)
Line range hint
109-117: Consider translating remaining hardcoded strings.There are still some hardcoded English strings that could benefit from translation support:
- Button text: "Hide additional information" / "Show additional information"
- Error message: "Unable to load document history"
- Retry text: "Click here to retry"
- "Show more" button text
Consider wrapping these strings with the
Transcomponent for consistency:- <Trans>Hide additional information</Trans> + <Trans>Hide additional information</Trans> - <Trans>Show additional information</Trans> + <Trans>Show additional information</Trans> - <Trans>Unable to load document history</Trans> + <Trans>Unable to load document history</Trans> - <Trans>Click here to retry</Trans> + <Trans>Click here to retry</Trans> - Show more + <Trans>Show more</Trans>Also applies to: 132-134, 301-307
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx (4)
28-33: Consider revising comment style for clarity and consistencyThe comment block between lines 28-33 could be improved for clarity and adherence to standard commenting practices. Consider rephrasing the comments to better explain why
useLinguiis used instead oftrans, and hownot-found.tsxaffects the i18n setup.
61-63: Address TODO: Implement dynamic language activationThere's a TODO comment indicating that dynamic language activation is pending implementation. Implementing this is crucial for proper internationalization and ensuring users see content in their preferred language.
Do you need assistance in implementing dynamic language activation? I can help set up the correct language based on metadata or other criteria. Would you like me to open a new GitHub issue to track this task?
Line range hint
109-118: Use dynamic locale for date formattingCurrently, the dates are formatted using
APP_I18N_OPTIONS.defaultLocale. To support proper internationalization, consider using the dynamic locale set ini18nso that dates are displayed according to the user's preferences.You can modify the date formatting to use the current locale:
{DateTime.fromJSDate(document.createdAt) - .setLocale(APP_I18N_OPTIONS.defaultLocale) + .setLocale(i18n.locale) .toFormat('yyyy-mm-dd hh:mm:ss a (ZZZZ)')}
Line range hint
119-128: Use dynamic locale for date formattingSimilarly, for the "Last Updated" date, use the dynamic locale to ensure consistency with the user's language settings.
Apply the same change as above:
{DateTime.fromJSDate(document.updatedAt) - .setLocale(APP_I18N_OPTIONS.defaultLocale) + .setLocale(i18n.locale) .toFormat('yyyy-mm-dd hh:mm:ss a (ZZZZ)')}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (9)
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recent-activity.tsx(1 hunks)apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-data-table.tsx(1 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx(4 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx(6 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx(9 hunks)apps/web/src/components/document/document-history-sheet.tsx(3 hunks)packages/lib/constants/document.ts(1 hunks)packages/lib/constants/recipient-roles.ts(0 hunks)packages/lib/utils/document-audit-logs.ts(2 hunks)
💤 Files with no reviewable changes (1)
- packages/lib/constants/recipient-roles.ts
🔇 Additional comments (17)
packages/lib/constants/document.ts (2)
1-4: LGTM! Well-organized imports.
The imports are properly structured and include all necessary dependencies for internationalization and type safety.
6-18: Verify DocumentStatus enum coverage.
Let's ensure all possible enum values are covered to prevent potential runtime issues.
✅ Verification successful
Let me generate another script to find the enum definition since it wasn't found in the first attempt.
Let me try one more search to find the DocumentStatus enum definition.
Based on the schema.prisma file, I can now provide the final response since I found the DocumentStatus enum definition and have verified its usage across the codebase.
All DocumentStatus enum values are properly covered in the constant.
The DocumentStatus enum in schema.prisma defines exactly three values: DRAFT, PENDING, and COMPLETED. The DOCUMENT_STATUS constant in the code covers all these values with their respective descriptions:
- DocumentStatus.COMPLETED
- DocumentStatus.DRAFT
- DocumentStatus.PENDING
No additional enum values exist that need to be added to the constant.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all DocumentStatus enum values are covered in the constant
# Search for the DocumentStatus enum definition
echo "DocumentStatus enum definition:"
ast-grep --pattern 'enum DocumentStatus {
$$$
}'
# Search for any other status references in the codebase
echo -e "\nOther status references:"
rg "DocumentStatus\." --type ts
Length of output: 20106
Script:
#!/bin/bash
# Search for DocumentStatus enum definition with a different pattern
echo "Searching for DocumentStatus enum definition:"
rg "enum\s+DocumentStatus" -A 5 --type ts
# Also search for ExtendedDocumentStatus since it was referenced
echo -e "\nSearching for ExtendedDocumentStatus definition:"
rg "ExtendedDocumentStatus" -B 2 -A 5 --type ts
Length of output: 37438
Script:
#!/bin/bash
# Search for DocumentStatus enum in prisma schema
echo "Searching for DocumentStatus in prisma schema:"
fd "schema.prisma" --exec cat {}
Length of output: 20095
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx (3)
1-2: LGTM: Proper i18n setup with Lingui
The addition of Lingui imports establishes the foundation for internationalization support.
32-32: LGTM: Proper implementation of i18n for table headers
The translation setup and table header translations are correctly implemented using the Lingui _ function and msg template.
Also applies to: 44-48
82-82: Verify translation coverage for audit log actions
Let's ensure all audit log actions have corresponding translations defined.
apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-data-table.tsx (1)
Line range hint 4-11: Well-implemented internationalization!
The component demonstrates excellent i18n practices:
- Proper use of Lingui's
msgtemplate for static text - Correct handling of date localization
- Consistent translation of column headers
- Integration with audit log action translations
Also applies to: 37-37, 63-65, 101-103
packages/lib/utils/document-audit-logs.ts (2)
1-6: LGTM: Clean import organization
The imports are well-organized, with clear separation between i18n-related imports and domain-specific types.
253-257: LGTM: Well-structured i18n implementation
The function signature properly includes the i18n translator, enabling localization support while maintaining type safety.
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx (4)
5-6: LGTM: i18n setup and constants look good!
The imports and constants have been properly updated to support internationalization using the Lingui library. The msg template literals are correctly used for translation strings.
Also applies to: 11-11, 14-15, 42-43
46-51: Implementation needed: Language selection mechanism
The TODO comment indicates that language selection functionality is missing. According to the PR description, this needs to be tied to either:
- Email translation settings (future integration), or
- Document metadata
Please clarify which approach will be implemented and ensure this is tracked.
Would you like me to help create a GitHub issue to track the implementation of the language selection mechanism?
Also applies to: 79-80
117-120: LGTM: Authentication level translations are well implemented!
The authentication level strings are properly translated using the _ function, and the pattern matching ensures all cases are handled exhaustively.
Also applies to: 126-127
166-166: LGTM: Comprehensive translation coverage!
All user-facing strings have been properly wrapped with translation functions, providing complete internationalization support for the certificate page.
Also applies to: 174-176, 192-192, 196-196, 218-218, 225-225, 227-227, 232-232, 246-246, 252-252, 257-257, 263-263, 268-268, 274-274, 279-279, 281-285, 301-301
apps/web/src/components/document/document-history-sheet.tsx (4)
15-15: LGTM: Import change aligns with i18n support.
The rename from formatDocumentAuditLogActionString to formatDocumentAuditLogAction reflects the enhanced functionality to support translations.
40-40: LGTM: Proper integration of translation support.
Good use of the useLingui hook to obtain both the translation function (_) and the i18n object, which is correctly used for date localization.
155-155: LGTM: Audit log action translation implementation.
The audit log action description is now properly internationalized using the translation function.
Line range hint 157-161: Verify date format localization across all supported languages.
The date formatting uses i18n.locales[0] with a fallback to i18n.locale. While this is generally correct, it's important to ensure the date format is appropriate for all supported languages.
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx (1)
143-145:
Verify recipient role descriptions are localized
Ensure that RECIPIENT_ROLES_DESCRIPTION[recipient.role].roleName provides a localized string. If roleName is not already translated, consider localizing it to support internationalization.
Run the following script to verify if roleName in RECIPIENT_ROLES_DESCRIPTION is localized:
This script searches for occurrences where roleName is assigned a localized string using msg. If any roleName assignments are not wrapped with msg, they may not be properly localized.
✅ Verification successful
Based on the search results, I can now provide a final response as we have found clear evidence about the localization of role names.
Role names are properly localized
The RECIPIENT_ROLES_DESCRIPTION constant in packages/lib/constants/recipient-roles.ts shows that role names are properly wrapped with the msg template literal for localization:
export const RECIPIENT_ROLES_DESCRIPTION = {
[RecipientRole.APPROVER]: {
...
roleName: msg`Approver`,
...
}
}Additionally, in the file where the role name is used (audit-log/page.tsx), the value is properly wrapped with the translation function:
[{_(RECIPIENT_ROLES_DESCRIPTION[recipient.role].roleName)}]🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify if role names in RECIPIENT_ROLES_DESCRIPTION are localized.
# Test: Search for `roleName` definitions wrapped with `msg`. Expect: All `roleName` values are localized.
ast-grep --pattern 'roleName: msg`$$_`' --type tsx
Length of output: 232
Script:
#!/bin/bash
# Let's first find the file that defines RECIPIENT_ROLES_DESCRIPTION
rg "RECIPIENT_ROLES_DESCRIPTION.*=.*{" -l
# Then let's examine its content
rg "RECIPIENT_ROLES_DESCRIPTION.*=.*{" -A 10
Length of output: 350
Script:
#!/bin/bash
# Let's try to find the constant definition with proper regex escaping
rg "RECIPIENT_ROLES_DESCRIPTION.*=.*\{" -l
# Let's also try to find any file that mentions this constant
rg "RECIPIENT_ROLES_DESCRIPTION" -l
# And get the content around its usage
rg "RECIPIENT_ROLES_DESCRIPTION" -B 2 -A 5
Length of output: 26680
76ff83f to
3f51029
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (7)
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx (2)
28-30: Enhance the translation usage commentWhile the directive is clear, it would be helpful to explain why TRANS should not be used and the benefits of using the
_function./** - * DO NOT USE TRANS. YOU MUST USE _ FOR THIS FILE AND ALL CHILDREN COMPONENTS. + * DO NOT USE TRANS. Instead, use the `_` function from useLingui for this file and all children components. + * This ensures consistent runtime translation updates and proper integration with the Lingui system. */
44-48: Consider extracting table headers to constantsWhile the translations are correctly implemented, consider extracting these table headers to constants to improve maintainability and reusability.
+const TABLE_HEADERS = { + TIME: msg`Time`, + USER: msg`User`, + ACTION: msg`Action`, + IP_ADDRESS: msg`IP Address`, + BROWSER: msg`Browser`, +} as const; <TableHeader> <TableRow> - <TableHead>{_(msg`Time`)}</TableHead> - <TableHead>{_(msg`User`)}</TableHead> - <TableHead>{_(msg`Action`)}</TableHead> - <TableHead>{_(msg`IP Address`)}</TableHead> - <TableHead>{_(msg`Browser`)}</TableHead> + <TableHead>{_(TABLE_HEADERS.TIME)}</TableHead> + <TableHead>{_(TABLE_HEADERS.USER)}</TableHead> + <TableHead>{_(TABLE_HEADERS.ACTION)}</TableHead> + <TableHead>{_(TABLE_HEADERS.IP_ADDRESS)}</TableHead> + <TableHead>{_(TABLE_HEADERS.BROWSER)}</TableHead> </TableRow> </TableHeader>apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx (3)
5-6: LGTM! Consider enhancing the warning comment.The i18n-related imports are well-organized and follow proper separation of server/client concerns. The warning comment is crucial but could be more detailed.
Consider expanding the warning comment to explain why Trans can't be used and what issues it could cause:
/** * DO NOT USE TRANS. YOU MUST USE _ FOR THIS FILE AND ALL CHILDREN COMPONENTS. * * Cannot use dynamicActivate by itself to translate this specific page and all * children components because `not-found.tsx` page runs and overrides the i18n. + * + * Using Trans components here would cause hydration mismatches since the server + * and client would render different content due to the i18n override behavior. */Also applies to: 9-12, 16-16, 29-34
36-38: LGTM! Consider adding error handling for language activation.The i18n setup is well-structured with proper validation. However, the
dynamicActivatecall could benefit from error handling.Consider adding error handling:
- await dynamicActivate(i18n, documentLanguage); + try { + await dynamicActivate(i18n, documentLanguage); + } catch (error) { + console.error('Failed to activate language:', error); + // Fallback to default language + await dynamicActivate(i18n, APP_I18N_OPTIONS.defaultLocale); + }Also applies to: 62-64
95-99: Consider using the document's language for date formatting.Currently, the DateTime formatting uses the default locale (
APP_I18N_OPTIONS.defaultLocale) instead of the document's language.Consider using the document's language for consistent localization:
{DateTime.fromJSDate(document.createdAt) - .setLocale(APP_I18N_OPTIONS.defaultLocale) + .setLocale(documentLanguage) .toFormat('yyyy-mm-dd hh:mm:ss a (ZZZZ)')}Also applies to: 111-117, 121-127
packages/lib/utils/document-audit-logs.ts (1)
340-345: Enhance recipient role translationsThe current translations could be more descriptive to provide better context about the action.
Consider this improvement:
- .with(RecipientRole.SIGNER, () => msg`${userName} signed the document`) - .with(RecipientRole.VIEWER, () => msg`${userName} viewed the document`) - .with(RecipientRole.APPROVER, () => msg`${userName} approved the document`) - .with(RecipientRole.CC, () => msg`${userName} CC'd the document`) + .with(RecipientRole.SIGNER, () => msg`${userName} completed signing the document`) + .with(RecipientRole.VIEWER, () => msg`${userName} completed viewing the document`) + .with(RecipientRole.APPROVER, () => msg`${userName} completed approving the document`) + .with(RecipientRole.CC, () => msg`${userName} was copied on the document`)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx (1)
168-168: Consider using document language for date formatting.While the translations are correctly implemented, the date formatting currently uses
APP_I18N_OPTIONS.defaultLocale. Consider using the document's language (documentLanguage) for date formatting to maintain consistency with the certificate's language.Example change for date formatting:
- .setLocale(APP_I18N_OPTIONS.defaultLocale) + .setLocale(documentLanguage)Also applies to: 176-178, 194-194, 198-198, 220-220, 227-227, 229-229, 234-234, 248-248, 254-254, 259-259, 265-265, 270-270, 276-276, 281-281, 283-287, 303-303
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (9)
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recent-activity.tsx(1 hunks)apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-data-table.tsx(1 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx(4 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx(6 hunks)apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx(9 hunks)apps/web/src/components/document/document-history-sheet.tsx(3 hunks)packages/lib/constants/document.ts(1 hunks)packages/lib/constants/recipient-roles.ts(0 hunks)packages/lib/utils/document-audit-logs.ts(2 hunks)
💤 Files with no reviewable changes (1)
- packages/lib/constants/recipient-roles.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recent-activity.tsx
- apps/web/src/app/(dashboard)/documents/[id]/logs/document-logs-data-table.tsx
- apps/web/src/components/document/document-history-sheet.tsx
- packages/lib/constants/document.ts
🔇 Additional comments (11)
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/data-table.tsx (3)
1-2: LGTM: Clean i18n setup
The Lingui imports are correctly added and properly organized with other external imports.
32-32: LGTM: Clean i18n hook integration
The useLingui hook is properly implemented at the component level with clean destructuring.
82-82: Fix typo in helper function name and verify translations
- The helper function has a typo:
uppercaseFistLettershould beuppercaseFirstLetter - Ensure that
formatDocumentAuditLogActionproperly handles the translation function in all cases.
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/audit-log/page.tsx (1)
Line range hint 73-152: LGTM! Well-structured UI with consistent translations.
The UI implementation demonstrates:
- Consistent use of translations
- Well-organized grid layout
- Proper print styling
packages/lib/utils/document-audit-logs.ts (3)
1-6: LGTM! Clean import changes for i18n support
The removal of English-specific role descriptions in favor of direct enum usage aligns well with the internationalization objectives.
366-366: LGTM! Proper handling of anonymous vs identified descriptions
The conditional translation selection based on prefix presence is well implemented.
253-254: Verify all callers handle the new i18n parameter
The addition of the I18n['_'] parameter is a breaking change that requires updates to all callers of this function.
✅ Verification successful
All callers have been updated with the new i18n parameter
The verification shows that all callers of formatDocumentAuditLogAction are already passing the _ parameter correctly:
document-history-sheet.tsx:formatDocumentAuditLogAction(_, auditLog, userId)data-table.tsx:formatDocumentAuditLogAction(_, log)document-page-view-recent-activity.tsx:formatDocumentAuditLogAction(_, auditLog, userId)document-logs-data-table.tsx:formatDocumentAuditLogAction(_, row.original)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all usages of formatDocumentAuditLogAction to verify they've been updated
# with the new i18n parameter
# Search for function calls
rg "formatDocumentAuditLogAction" --type ts --type tsx -B 2 -A 2
Length of output: 92
Script:
#!/bin/bash
# Let's try with just ripgrep without file type filters
rg "formatDocumentAuditLogAction" -B 2 -A 2
# Also search for exports to understand the full context
rg "export.*formatDocumentAuditLogAction" -B 2 -A 2
Length of output: 6209
apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx (4)
5-12: LGTM! Important i18n setup and documentation.
The i18n setup is correctly implemented with proper imports. The comment about using _ instead of Trans is crucial for preventing conflicts with the not-found.tsx page.
Also applies to: 47-52
43-44: LGTM! Proper translation of signing reasons.
The signing reasons are correctly set up for translation using the msg template literal while preserving existing values.
119-122: LGTM! Authentication levels properly translated.
The authentication level translations are correctly implemented using pattern matching with exhaustive cases.
Also applies to: 128-129
Line range hint 54-82: LGTM! Verify language fallback behavior.
The i18n setup sequence is well implemented with proper language validation and activation. However, it would be good to verify the fallback behavior when an unsupported language is encountered.
✅ Verification successful
The search results show that ZSupportedLanguageCodeSchema is defined in packages/lib/constants/i18n.ts with a .catch('en') fallback, which means it automatically defaults to 'en' for unsupported languages. Let me verify the complete implementation by checking the related i18n setup.
Language fallback is properly implemented and secure
The implementation is correct and safe. The ZSupportedLanguageCodeSchema is well-defined with:
- Explicit supported languages (de, en, fr, es)
- Default fallback to 'en' via
.catch('en') - Type-safe validation through zod enum
The code in the PDF certificate page correctly uses this schema for validation, ensuring consistent language handling with proper fallback behavior.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for language validation and fallback handling
# Look for other instances where ZSupportedLanguageCodeSchema is used to ensure consistent validation
rg -A 3 "ZSupportedLanguageCodeSchema"
Length of output: 2190
Script:
#!/bin/bash
# Check the complete i18n setup and supported languages
cat packages/lib/constants/i18n.ts
Length of output: 1200
| anonymous: data.isResending ? msg`Email resent` : msg`Email sent`, | ||
| identified: data.isResending | ||
| ? msg`${prefix} resent an email to ${data.recipientEmail}` | ||
| : msg`${prefix} sent an email to ${data.recipientEmail}`, | ||
| })) |
There was a problem hiding this comment.
Avoid exposing recipient email in audit log messages
The email messages contain recipient email addresses which could lead to PII exposure.
Consider this fix:
- anonymous: data.isResending ? msg`Email resent` : msg`Email sent`,
- identified: data.isResending
- ? msg`${prefix} resent an email to ${data.recipientEmail}`
- : msg`${prefix} sent an email to ${data.recipientEmail}`,
+ anonymous: data.isResending ? msg`Email resent` : msg`Email sent`,
+ identified: data.isResending
+ ? msg`${prefix} resent an email to recipient`
+ : msg`${prefix} sent an email to recipient`,📝 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.
| anonymous: data.isResending ? msg`Email resent` : msg`Email sent`, | |
| identified: data.isResending | |
| ? msg`${prefix} resent an email to ${data.recipientEmail}` | |
| : msg`${prefix} sent an email to ${data.recipientEmail}`, | |
| })) | |
| anonymous: data.isResending ? msg`Email resent` : msg`Email sent`, | |
| identified: data.isResending | |
| ? msg`${prefix} resent an email to recipient` | |
| : msg`${prefix} sent an email to recipient`, | |
| })) |
Description
Add translations for audit logs and certificates.
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation
Chores