Fix #666: Refactor NewCauseClient into smaller testable units - #878
Fix #666: Refactor NewCauseClient into smaller testable units#878fredericklamar342-prog wants to merge 11 commits into
Conversation
… testable units - Extract validation logic into src/lib/campaignValidation.ts - Extract draft management into src/hooks/useCampaignFormDraft.ts hook - Extract review modal into src/components/CampaignReviewModal.tsx - Reduce NewCauseClient.tsx from 1,187 to 895 lines - Fix draft overwrite bug on initial mount with hasRestored guard - Add explicit CampaignFormSetters type - Fix pre-existing type errors in markdownSanitizeSchema.ts
|
@fredericklamar342-prog Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Auto-review failed (API error). Leaving PR for human review. |
|
Auto-review failed (API error). Leaving PR for human review. |
| const parts = fullKey.split("."); | ||
| const key = parts[parts.length - 1]; | ||
| const namespace = parts.length > 1 ? parts[0] : ''; | ||
| const namespace = parts.length > 1 ? parts[0] : ""; |
|
Auto-review failed (API error). Leaving PR for human review. |
|
Auto-review failed (API error). Leaving PR for human review. |
|
Auto-review failed (API error). Leaving PR for human review. |
|
Auto-review failed (API error). Leaving PR for human review. |
|
Auto-review failed (API error). Leaving PR for human review. |
|
Auto-review failed (API error). Leaving PR for human review. |
1 similar comment
|
Auto-review failed (API error). Leaving PR for human review. |
|
Auto-review failed (API error). Leaving PR for human review. |
|
Auto-review failed (API error). Leaving PR for human review. |
Summary
Refactors the 1,187-line
NewCauseClient.tsxinto smaller, focused modules by extracting validation logic, draft management, and the review modal into separate files.Changes
New files
src/lib/campaignValidation.ts— extractedvalidateForm,FormErrorKeys, andReviewDatatypes (pure validation logic, now independently testable)src/hooks/useCampaignFormDraft.ts— extracted localStorage draft management hook with restore/save/discard/clear operationssrc/components/CampaignReviewModal.tsx— extracted review modal component with its own props interfaceModified files
src/app/[locale]/causes/new/NewCauseClient.tsx— reduced from 1,187 to 895 lines by importing the extracted modules; behavior is unchangedBug fixes
hasRestoredguard inuseCampaignFormDraftto prevent saving empty default values over a restored draft on initial mountmarkdownSanitizeSchema.ts(implicit any + missing hast-util-sanitize dep)Testing
pnpm typecheck— passedIssue Reference
Fixes #666