refactor: quality-of-life improvements — reduce duplication and improve type safety#762
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
refactor: quality-of-life improvements — reduce duplication and improve type safety#762devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
- Extract fetchClientWithEntries helper in reports.js to eliminate triplication of client verification + work entry fetching - Add getApiErrorMessage utility to centralize error extraction, replacing 8 repeated unsafe type casts across 3 frontend pages - Extract downloadBlob helper and generic handleExport in ReportsPage to remove duplicated CSV/PDF export logic - Migrate DashboardPage Grid from deprecated v1 item props to v2 size API, eliminating 3 @ts-expect-error suppressions
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Four targeted quality-of-life improvements that reduce code duplication and improve type safety without changing any functionality. Net result: -59 lines (243 added, 302 removed) across 7 files.
1. Backend: Extract
fetchClientWithEntrieshelper inreports.jsAll three report routes (
/client/:clientId,/export/csv/:clientId,/export/pdf/:clientId) duplicated the same pattern — parse clientId, validate, verify client ownership, fetch work entries, handle errors. Extracted into a single reusable helper that accepts the SELECT columns and a callback. Eliminates ~60 lines of triplication.2. Frontend: Add
getApiErrorMessageutility (types/api.ts)The pattern
err as { response?: { data?: { error?: string } } }was repeated 8 times acrossLoginPage,ClientsPage, andWorkEntriesPage. Replaced with a singlegetApiErrorMessage(err, fallback)function that centralizes the extraction logic and theApiErrorBodyinterface.3. Frontend: Extract
downloadBlob+handleExportinReportsPageThe CSV and PDF export handlers had near-identical code for creating object URLs, triggering downloads, and cleaning up. Extracted
downloadBlob(reusable blob-to-download helper) and a generichandleExportthat takes the API function, extension, and error message.4. Frontend: Migrate
DashboardPageGrid to MUI v2 APIReplaced deprecated
<Grid item xs={} sm={} md={}>props with<Grid size={{ xs:, sm:, md: }}>, matching the pattern already used inReportsPage. Eliminates 3@ts-expect-errorsuppression comments.Review & Testing Checklist for Human
fetchClientWithEntriesrefactor touches all three routesgetApiErrorMessagechange touches all mutation error handlersNotes
eslint src/) passes with no errorstsc -b && vite build) succeedsLink to Devin session: https://partner-workshops.devinenterprise.com/sessions/bc89425a2d8e4128af32ea28ce6f98e1