Skip to content

Fix #666: Refactor NewCauseClient into smaller testable units - #878

Open
fredericklamar342-prog wants to merge 11 commits into
Iris-IV:mainfrom
fredericklamar342-prog:fix/issue-666-refactor-components
Open

Fix #666: Refactor NewCauseClient into smaller testable units#878
fredericklamar342-prog wants to merge 11 commits into
Iris-IV:mainfrom
fredericklamar342-prog:fix/issue-666-refactor-components

Conversation

@fredericklamar342-prog

Copy link
Copy Markdown

Summary

Refactors the 1,187-line NewCauseClient.tsx into smaller, focused modules by extracting validation logic, draft management, and the review modal into separate files.

Changes

New files

  • src/lib/campaignValidation.ts — extracted validateForm, FormErrorKeys, and ReviewData types (pure validation logic, now independently testable)
  • src/hooks/useCampaignFormDraft.ts — extracted localStorage draft management hook with restore/save/discard/clear operations
  • src/components/CampaignReviewModal.tsx — extracted review modal component with its own props interface

Modified files

  • src/app/[locale]/causes/new/NewCauseClient.tsx — reduced from 1,187 to 895 lines by importing the extracted modules; behavior is unchanged

Bug fixes

  • Fixed draft overwrite bug: added hasRestored guard in useCampaignFormDraft to prevent saving empty default values over a restored draft on initial mount
  • Fixed pre-existing TypeScript type errors in markdownSanitizeSchema.ts (implicit any + missing hast-util-sanitize dep)

Testing

  • pnpm typecheck — passed

Issue Reference

Fixes #666

… 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
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

Comment thread src/hooks/useCampaignFormDraft.ts Fixed
@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

Comment thread scripts/check-i18n.mjs
const parts = fullKey.split(".");
const key = parts[parts.length - 1];
const namespace = parts.length > 1 ? parts[0] : '';
const namespace = parts.length > 1 ? parts[0] : "";
@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

1 similar comment
@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

@sshdopey

sshdopey commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore] Refactor complex components into smaller, testable units

3 participants