-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: signing volume #1358
feat: signing volume #1358
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 Walkthrough📝 WalkthroughWalkthroughThis pull request includes extensive updates to localization files for both German and English translations, enhancing user interface strings across the application. It introduces new translation entries, modifies existing ones, and adds new functionality for fetching and displaying leaderboard data. New components and actions related to the leaderboard feature have been created, including asynchronous functions for data retrieval and React components for rendering the leaderboard interface. Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Outside diff range and nitpick comments (1)
apps/web/src/app/(dashboard)/admin/leaderboard/fetch-leaderboard.actions.ts (1)
18-20
: Consider providing more specific error messages.Instead of throwing a generic 'Unauthorized' error, consider providing more context about why the error occurred. For example:
throw new Error('Only admin users can access the leaderboard data.');This can help with debugging and provides a clearer message to the client.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (7)
- apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx (1 hunks)
- apps/web/src/app/(dashboard)/admin/leaderboard/fetch-leaderboard.actions.ts (1 hunks)
- apps/web/src/app/(dashboard)/admin/leaderboard/page.tsx (1 hunks)
- apps/web/src/app/(dashboard)/admin/nav.tsx (2 hunks)
- packages/lib/server-only/admin/get-signing-volume.ts (1 hunks)
- packages/lib/translations/de/web.po (7 hunks)
- packages/lib/translations/en/web.po (7 hunks)
Additional comments not posted (19)
apps/web/src/app/(dashboard)/admin/leaderboard/fetch-leaderboard.actions.ts (1)
15-25
: LGTM! The function provides a secure and flexible way to retrieve leaderboard data.The implementation looks good overall:
- It correctly uses server-side rendering.
- It properly checks for admin privileges before executing the main logic.
- It uses clear parameter types for the search options.
- It delegates data fetching to a separate function, which is a good separation of concerns.
apps/web/src/app/(dashboard)/admin/leaderboard/page.tsx (5)
1-18
: Imports and type definitions look good!The component imports all the necessary dependencies and defines a clear type structure for its props. The
AdminLeaderboardProps
type provides flexibility by making all search parameters optional.
20-23
: Component function signature and setup are well-structured!The
Leaderboard
component is properly defined as an async default export function, accepting optional search parameters as props. Setting up internationalization and retrieving the user session are appropriate steps for an admin-facing component.
25-27
: Admin access control is properly implemented!The component correctly enforces admin access control by checking the user's admin status using the
isAdmin
function. Throwing an "Unauthorized" error for non-admin users is an appropriate way to handle unauthorized access attempts.
29-41
: Search parameter handling and data fetching are well-implemented!The component effectively extracts and processes the search parameters, assigning default values for pagination and sorting. This ensures a consistent and predictable behavior for the component. Using a separate
search
function for data fetching promotes separation of concerns and maintainability.
43-60
: Component's return statement and rendering are well-structured!The component returns a well-structured JSX with a heading and the
LeaderboardTable
component. Using theTrans
component for the heading ensures proper internationalization. Passing the fetched data and other relevant props to theLeaderboardTable
component allows for a clean separation of concerns and maintainable code structure.apps/web/src/app/(dashboard)/admin/nav.tsx (1)
83-95
: LGTM!The new button for the leaderboard section follows the existing patterns and conventions of the
AdminNav
component. It is correctly linked to the "/admin/leaderboard" route, uses an appropriate icon and label, and is properly styled to highlight when active.The use of the
Trans
component for the label allows for easy internationalization, which is a good practice.Overall, this is a clean and consistent addition to the navigation.
apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx (5)
1-30
: LGTM!The imports and type definitions are appropriate and cover the necessary dependencies. The
SigningVolume
andLeaderboardTableProps
types provide a clear structure for the data and props used in the component.
32-45
: LGTM!The component definition and state management are implemented correctly. The usage of hooks like
useState
,useTransition
, anduseDebouncedValue
is appropriate for managing state and optimizing search performance. TheuseUpdateSearchParams
custom hook is a good choice for updating the URL search params.
47-98
: LGTM!The
columns
definition and memoization are implemented correctly. UsinguseMemo
is a good practice to memoize thecolumns
array and avoid unnecessary re-renders. The column definitions are clear and include the necessary properties. The sortable columns have appropriate click handlers to trigger the sorting functionality. The usage of thesatisfies
keyword ensures type safety of thecolumns
array.
100-133
: LGTM!The
useEffect
hook and pagination handling are implemented correctly. TheuseEffect
hook properly updates the search params whenever the debounced search string changes. TheonPaginationChange
function correctly updates the page andperPage
values in the search params. ThehandleChange
function updates the search string state when the input value changes. ThehandleColumnSort
function appropriately toggles the sort order and updates the search params when a sortable column header is clicked.
135-162
: LGTM!The rendering logic and loading state handling are implemented correctly. The search input is rendered with appropriate props and change handler. The
DataTable
component is rendered with the necessary props, including columns, data, pagination, and callbacks. TheDataTablePagination
component is correctly rendered as a child ofDataTable
to handle pagination. The loading indicator is conditionally rendered based on theisPending
state, providing visual feedback during loading states.packages/lib/translations/de/web.po (3)
1800-1802
: LGTM!The new translation entry for "Leaderboard" looks good. It's correctly referenced in the admin navigation component.
2819-2822
: Looks good!The new translation entry for "Signing Volume" is correctly added with references to the leaderboard components.
2832-2833
: Reference update looks good!The line number reference for the "Site Settings" translation entry has been correctly updated in
apps/web/src/app/(dashboard)/admin/nav.tsx
, indicating the navigation item has moved.packages/lib/translations/en/web.po (2)
1818-1820
: New translation looks good!The new "Leaderboard" translation entry is clear, accurate and consistent.
2841-2844
: New translation looks good!The new "Signing Volume" translation entry is clear, accurate and consistent.
packages/lib/server-only/admin/get-signing-volume.ts (2)
45-46
: Verify the existence and correctness of getOrderByClause functionEnsure that the
getOrderByClause
function is correctly defined and available in the scope before it's used.Run the following script to check for any issues:
Verification successful
getOrderByClause function is correctly defined and used
The
getOrderByClause
function is properly defined and available in the scope before it's used. It's defined as a const arrow function in the same file (packages/lib/server-only/admin/get-signing-volume.ts
) where it's being used. The function is called with the correct parameters (sortBy
andsortOrder
), and there are no naming conflicts or multiple definitions.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for the definition and export of getOrderByClause. # Test: Search for the function definition. # Expect: The function should be defined only once and exported if used externally. rg --type typescript 'function getOrderByClause' # Test: Ensure there are no naming conflicts. # Expect: No other functions with the same name. rg --type typescript 'getOrderByClause' | grep -v 'function getOrderByClause'Length of output: 198
Script:
#!/bin/bash # Search for getOrderByClause function definition echo "Searching for getOrderByClause function definition:" fd -e ts -e js | xargs rg 'function getOrderByClause' # Search for getOrderByClause usage echo "Searching for getOrderByClause usage:" fd -e ts -e js | xargs rg 'getOrderByClause' # Check the specific file for function usage echo "Checking get-signing-volume.ts for getOrderByClause usage:" rg 'getOrderByClause' packages/lib/server-only/admin/get-signing-volume.ts # Search for imports of getOrderByClause echo "Searching for imports of getOrderByClause:" fd -e ts -e js | xargs rg 'import.*getOrderByClause'Length of output: 1032
119-142
: Verify the correctness of ordering by signing volumeWhen sorting by
signingVolume
, the currentorderBy
implementation may not work as intended because Prisma does not support ordering by the combined counts of relations directly in this manner.Consider the following steps to verify and correct the ordering:
Adjust the
orderBy
clause: Modify theorderBy
to use_count
with relation paths.default: return [ - { - User: { - Document: { - _count: sortOrder, - }, - }, - }, - { - team: { - document: { - _count: sortOrder, - }, - }, - }, - ]; + { + _count: { + User: { + Document: sortOrder, + }, + }, + }, + { + _count: { + team: { + document: sortOrder, + }, + }, + }, ];Verify if Prisma supports this ordering: Since Prisma may not support ordering by combined counts across different relations, you might need to fetch the signing volumes first and then sort them in your application code.
To verify, run the following script:
Ensure you have a script
verify-orderby.ts
that attempts to run the query with the existingorderBy
clause.Alternative solution: Fetch the counts separately and sort the
leaderboardWithVolume
array in your application.// After calculating signingVolume leaderboardWithVolume.sort((a, b) => { if (sortOrder === 'asc') { return a.signingVolume - b.signingVolume; } else { return b.signingVolume - a.signingVolume; } });Adjust your
getOrderByClause
to handle this case appropriately.Verification successful
Ordering by signing volume is implemented correctly
The
getOrderByClause
function inpackages/lib/server-only/admin/get-signing-volume.ts
correctly implements the ordering for signing volume. It uses a nested structure to count documents for both User and team, which effectively represents the signing volume. This approach is valid in Prisma for ordering by related model counts.
- For 'name' sorting, it orders by User name and team name.
- For 'createdAt' sorting, it uses the createdAt field directly.
- For 'signingVolume' (default case), it orders by the count of documents for both User and team.
This implementation should correctly order the results based on the total number of documents (signing volume) associated with each user or team.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check if ordering by combined counts works as intended. # Test: Attempt to query with the current orderBy clause. # Expect: Verify whether Prisma allows this operation or throws an error. npx prisma generate npx ts-node verify-orderby.tsLength of output: 195
Script:
#!/bin/bash # Find the implementation of getOrderByClause ast-grep --lang typescript --pattern 'function getOrderByClause($_) { $$$ }' # Search for mentions of leaderboard or signing volume rg -i "leaderboard|signing volume" -A 5 -B 5 # Look for Prisma schema definitions rg "model User|model Team|model Document" -A 10 schema.prismaLength of output: 142023
Script:
#!/bin/bash # Search for getOrderByClause function implementation rg "function getOrderByClause" -A 10 # Examine leaderboard-related files cat packages/lib/server-only/admin/get-signing-volume.ts # Try to locate Prisma schema file fd schema.prismaLength of output: 3389
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, a few points:
- No need for the ID in leaderboard
- The Subscriptions (Username) should link to stripe subscription e.g. https://dashboard.stripe.com/subscriptions/sub_xxxxxx for easier management
This commit enhances the leaderboard by adding a clickable link to each customer's name, which directs to their Stripe subscription page. It also removes the ID column and includes the planId in the signing volume data for improved user experience and easier access to subscription details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
packages/lib/translations/en/web.po (2)
Line range hint
15-16
: Consider using a more specific placeholder name.The placeholder "{0}" is used here. While this works, it might be more maintainable to use a named placeholder that describes what will be inserted, e.g., "{date}" or "{formatted_date}".
Line range hint
30-31
: Consider adding context for pluralization.These translations use plural forms correctly. Consider adding a comment to explain the plural rules for translators of other languages where plural forms might be more complex.
Also applies to: 33-34
packages/lib/translations/de/web.po (1)
Line range hint
1-3524
: Several translations are missing or incomplete.There are numerous instances where translations are either missing entirely (empty msgstr) or still in English. This needs to be addressed to ensure a complete German localization. Here are a few examples:
- Line 1823-1825: "Leaderboard" is not translated.
- Line 2015-2020: "Signing Volume" is not translated.
- Line 2846-2850: "Signing Volume" is not translated again.
Please review the entire file and provide translations for all missing or incomplete entries.
Inconsistencies in formatting and translation style detected.
There are some inconsistencies in how certain terms or phrases are translated throughout the file. For example:
- "Sign in" is translated as both "Einloggen" and "Anmelden" in different places.
- "Dashboard" is sometimes left in English and sometimes translated to "Übersicht".
Standardize these translations for consistency across the application.
Some translations could be improved for clarity or naturalness.
While many translations are accurate, some could be improved to sound more natural in German or to better convey the original meaning. For example:
- Line 964: "Created" is translated as "Erstellt", which is correct but could be more specific depending on the context, such as "Erstellungsdatum" for a date field.
- Line 1009-1013: "Customer Type" is not translated and commented out. Consider translating this to "Kundentyp" if it's still needed.
Review these instances and consider refining the translations for better clarity and naturalness in German.
Potential functional issues in translations.
Some translations might affect functionality if not handled correctly:
- Lines 2859-2860: "Site Settings" is translated as "Website Einstellungen", but the space might cause issues if this is used as a key in the code. Consider using "Website-Einstellungen" instead.
- Throughout the file, there are instances where placeholders like {0}, {1} are used. Ensure that these are kept in the correct order in the German translations, as word order often differs between English and German.
Review these instances carefully to prevent any potential functional issues arising from the translations.
Suggestion for handling gender-neutral language.
German often requires gendered forms of words. Consider implementing a system for handling gender-neutral language or providing both masculine and feminine forms where appropriate. For example:
- Line 2015: "User" could be translated as "Benutzer*in" or "Benutzer/in" to be more inclusive.
This approach would make the application more inclusive and aligned with modern German language practices.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- packages/lib/translations/de/web.po (7 hunks)
- packages/lib/translations/en/web.po (7 hunks)
🧰 Additional context used
🔇 Additional comments (5)
packages/lib/translations/en/web.po (5)
Line range hint
1-13
: LGTM: File header and metadata look correct.The file header contains the necessary metadata for a PO file, including the MIME type, content type, and language specification. This is correctly set up for English translations.
Line range hint
18-19
: Ensure consistent use of quotation marks.The translation uses double quotes around "{documentTitle}", which is correct. Ensure this style is consistently used throughout the file for similar placeholders.
Line range hint
21-22
: LGTM: Consistent use of placeholders and parentheses.These translations correctly use the {0} placeholder and maintain consistent formatting with parentheses.
Also applies to: 24-25, 27-28
Line range hint
36-37
: LGTM: Correct use of HTML-like tags and pluralization.These translations correctly use HTML-like tags for formatting and handle pluralization. The structure is consistent across similar messages.
Also applies to: 39-40, 42-43, 45-46, 48-49
Line range hint
51-52
: Ensure placeholder consistency across similar messages.These two messages use {0} as a placeholder for what seems to be the same type of information. Ensure that this is intentional and that the placeholder represents the same data in both cases.
Also applies to: 54-55
@ephraimduncan Looks good so far. Can you fix the merge conflicts, so I can it to to staging to test with the stripe dev account? |
working on it now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (2)
packages/lib/translations/fr/web.po (2)
Line range hint
751-757
: Missing translations for new featuresThe following strings are missing French translations:
- "Leaderboard" should be translated as "Classement" or "Tableau des scores"
- "Signing Volume" should be translated as "Volume de signatures"
Apply this diff to add the missing translations:
msgid "Leaderboard" -msgstr "" +msgstr "Classement" msgid "Signing Volume" -msgstr "" +msgstr "Volume de signatures"Also applies to: 2155-2158, 3322-3326
Line range hint
4470-4803
: Inconsistent translation of error messagesI notice some inconsistency in how error messages are translated. For example, some use "Nous ne pouvons pas..." while others use "Impossible de...". We should standardize on one format.
Consider standardizing error message translations to use "Impossible de..." format consistently throughout the file for better user experience.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (13)
apps/web/src/app/(dashboard)/admin/leaderboard/page.tsx
(1 hunks)packages/lib/translations/de/common.po
(0 hunks)packages/lib/translations/de/marketing.po
(0 hunks)packages/lib/translations/de/web.js
(1 hunks)packages/lib/translations/de/web.po
(15 hunks)packages/lib/translations/en/web.js
(1 hunks)packages/lib/translations/en/web.po
(15 hunks)packages/lib/translations/es/common.po
(0 hunks)packages/lib/translations/es/marketing.po
(0 hunks)packages/lib/translations/es/web.po
(14 hunks)packages/lib/translations/fr/common.po
(0 hunks)packages/lib/translations/fr/marketing.po
(0 hunks)packages/lib/translations/fr/web.po
(14 hunks)
💤 Files with no reviewable changes (6)
- packages/lib/translations/de/common.po
- packages/lib/translations/de/marketing.po
- packages/lib/translations/es/common.po
- packages/lib/translations/es/marketing.po
- packages/lib/translations/fr/common.po
- packages/lib/translations/fr/marketing.po
🚧 Files skipped from review as they are similar to previous changes (4)
- apps/web/src/app/(dashboard)/admin/leaderboard/page.tsx
- packages/lib/translations/de/web.js
- packages/lib/translations/de/web.po
- packages/lib/translations/en/web.js
🔇 Additional comments (7)
packages/lib/translations/en/web.po (2)
2155-2157
: LGTM! New translation added for Leaderboard.
The translation entry for "Leaderboard" has been added correctly.
3322-3325
: LGTM! New translation added for Signing Volume.
The translation entry for "Signing Volume" has been added correctly.
packages/lib/translations/es/web.po (4)
4803-4804
: Verify translation consistency
The translation for "Free Plan" should be consistent with other plan-related translations in the file. The current translation looks good but ensure it aligns with your terminology guidelines.
4855-4857
: Verify customer support related translation
The translation for the customer support message is accurate and maintains a professional tone while clearly conveying the message about contacting support.
5001-5003
: Verify payment-related translation
The translation for the payment overdue message is accurate and maintains the urgency while being polite and professional.
751-754
:
Missing translation for "Billing"
The English string "Billing" has been left untranslated. Consider translating it to "Facturación" to maintain consistency with other billing-related translations in the file.
-msgstr "Billing"
+msgstr "Facturación"
Likely invalid or redundant comment.
packages/lib/translations/fr/web.po (1)
Line range hint 1-5001
: Overall translation quality is good
The majority of translations are accurate and maintain proper French grammar and idioms. The file shows good attention to:
- Proper use of French punctuation (spaces before/after punctuation marks)
- Consistent use of formal "vous" form
- Accurate translation of technical terms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
packages/lib/translations/en/web.po (1)
Line range hint
1181-1224
: New leaderboard translations addedThe new translations for leaderboard functionality have been added correctly. However, there are some duplicate entries that should be cleaned up:
- #: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:94 - #: apps/web/src/app/(dashboard)/admin/leaderboard/leaderboard-table.tsx:94 - #~ msgid "Customer Type" - #~ msgstr "Customer Type"Remove the duplicate entries to maintain a cleaner translation file.
packages/lib/translations/de/web.po (1)
Line range hint
1-4000
: Consider standardizing formality in translationsThe translations alternate between formal "Sie" and informal "du" forms. For consistency, consider standardizing to one form throughout the file.
Examples:
- "Warte auf" (informal) vs "Warten Sie" (formal)
- "dein Dokument" (informal) vs "Ihr Dokument" (formal)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (10)
packages/lib/translations/de/common.po
(0 hunks)packages/lib/translations/de/marketing.po
(0 hunks)packages/lib/translations/de/web.po
(7 hunks)packages/lib/translations/en/web.po
(7 hunks)packages/lib/translations/es/common.po
(0 hunks)packages/lib/translations/es/marketing.po
(0 hunks)packages/lib/translations/es/web.po
(6 hunks)packages/lib/translations/fr/common.po
(0 hunks)packages/lib/translations/fr/marketing.po
(0 hunks)packages/lib/translations/fr/web.po
(6 hunks)
💤 Files with no reviewable changes (6)
- packages/lib/translations/de/common.po
- packages/lib/translations/de/marketing.po
- packages/lib/translations/es/common.po
- packages/lib/translations/es/marketing.po
- packages/lib/translations/fr/common.po
- packages/lib/translations/fr/marketing.po
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/lib/translations/es/web.po
- packages/lib/translations/fr/web.po
🔇 Additional comments (3)
packages/lib/translations/en/web.po (3)
3337-3341
: New signing volume translations look good
The translations for "Signing Volume" have been properly added and are consistent with the rest of the file.
2169-2172
: LGTM: Leaderboard navigation translation
The translation for the leaderboard navigation item has been properly added.
Line range hint 1-24
: File metadata looks good
The PO file header contains all required metadata fields and is properly formatted.
Summary by CodeRabbit
Release Notes
New Features
LeaderboardTable
component for displaying signing volumes with search and pagination functionalities.Bug Fixes
Documentation