-
Notifications
You must be signed in to change notification settings - Fork 13.1k
refactor: reduce cyclomatic complexity in RegisterForm #38369
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
refactor: reduce cyclomatic complexity in RegisterForm #38369
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
WalkthroughThe changes refactor the registration form by introducing a reusable FormField wrapper component and centralizing validation and error handling logic into two new custom hooks (useRegistrationValidation and useRegistrationErrors), replacing previous inline field wiring and error management patterns. Changes
Sequence DiagramsequenceDiagram
participant User
participant RegisterForm
participant useRegistrationValidation as Validation Hook
participant useRegistrationErrors as Error Hook
participant FormField
participant Server
User->>RegisterForm: Input form data
RegisterForm->>useRegistrationValidation: Get validation rules for fields
useRegistrationValidation-->>RegisterForm: Return field validators & passwordIsValid
RegisterForm->>FormField: Render with validation rules
FormField->>User: Display form field
User->>RegisterForm: Submit form
RegisterForm->>RegisterForm: Validate with rules from hook
alt Validation passes
RegisterForm->>Server: Send registration request
Server-->>RegisterForm: Success or error response
alt Server error received
RegisterForm->>useRegistrationErrors: handleRegistrationError(error)
useRegistrationErrors->>useRegistrationErrors: Map error to field or flow
alt Field-specific error
useRegistrationErrors-->>RegisterForm: Set field error
RegisterForm->>FormField: Update with error
FormField-->>User: Display field error
else Rate limit or activation flow
useRegistrationErrors-->>RegisterForm: Toast & routing
RegisterForm-->>User: Show toast & navigate
else Custom server error
useRegistrationErrors-->>RegisterForm: Set server error state
RegisterForm-->>User: Display server error
end
end
else Validation fails
RegisterForm->>FormField: Mark fields with errors
FormField-->>User: Display validation errors
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
No issues found across 5 files
|
fixes #38364 What was the problem?
The component (~316 lines) combined several distinct responsibilities:
This accumulation of logic made the file difficult to read, test, and maintain without risking regressions. What does this PR do?This PR performs a pure refactor to decouple logic and reduce complexity, with zero functional or UI changes. Key changes
What this PR does NOT do
This is strictly a refactor to improve code quality. Why this approach?
Files changedModified
Added
|
|
Before opening a PR please check if there are others doing the same, as this is a duplicate of #38365 |
fixes #38364
What was the problem?
RegisterForm.tsxhad excessive cyclomatic complexity, forcing the usage of an ESLint disable directive:/* eslint-disable complexity */The component (~316 lines) combined several distinct responsibilities:
This accumulation of logic made the file difficult to read, test, and maintain without risking regressions.
What does this PR do?
This PR performs a pure refactor to decouple logic and reduce complexity, with zero functional or UI changes.
Key changes
eslint-disable complexityuseRegistrationValidationreact-hook-formuseRegistrationErrorsFormFieldcomponent to handle label, input wrapping, and error displayaria-*) across all inputsRegisterForm.tsxWhat this PR does NOT do
This is strictly a refactor to improve code quality.
Why this approach?
Files changed
Modified
packages/web-ui-registration/src/RegisterForm.tsxAdded
packages/web-ui-registration/src/hooks/useRegistrationValidation.tspackages/web-ui-registration/src/hooks/useRegistrationErrors.tspackages/web-ui-registration/src/components/FormField.tsx