feat: add long word validation for name input in onboarding and settings#1286
Conversation
WalkthroughThis PR addresses navbar layout breaking from excessively long user names by truncating the navbar display to the first word and enforcing a 30-character-per-word limit on name input across onboarding and settings flows. Validation blocks form submission and displays inline error messages when violated. ChangesName Validation and Display Truncation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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.
Actionable comments posted: 3
🧹 Nitpick comments (1)
frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx (1)
60-67: ⚡ Quick winExtract name-word validation into a shared helper to avoid drift with Settings.
The same 30-char-per-word validation now exists in multiple components; centralizing it will keep onboarding and settings behavior consistent.
Suggested direction
+// src/utils/nameValidation.ts +export const hasWordLongerThan = (value: string, max = 30): boolean => + value.trim().split(/\s+/).some((word) => word.length > max);- const words = value.split(' '); - const hasLongWord = words.some((word) => word.length > 30); + const hasLongWord = hasWordLongerThan(value, 30);As per coding guidelines "Look for code duplication".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx` around lines 60 - 67, Extract the 30-char-per-word check into a shared helper (e.g., validateNameWords or isNameWordTooLong) in a common utils/module used by both onboarding and settings, replace the inline logic in AvatarSelectionStep (the value.split, hasLongWord, setLongWordError, setLocalName block) to call the helper and setLongWordError based on its boolean result, and update the Settings component to use the same helper so the rule is centralized and cannot drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@frontend/src/components/Navigation/Navbar/Navbar.tsx`:
- Around line 84-90: Guard the userName value before calling split to avoid
runtime errors in the Navbar render: locate the span that currently uses
userName.split(' ')[0] and change it to first check that userName is a non-empty
string (e.g., via optional chaining or a conditional) and fall back to an empty
string or placeholder when absent; ensure the JSX uses that safe expression (or
a small helper like getFirstName(userName)) so the navbar does not crash when
profile state is not yet populated.
In `@frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx`:
- Around line 60-67: Add automated unit tests for the per-word validation in
AvatarSelectionStep: create tests that render AvatarSelectionStep, simulate user
input into the name field and assert that setLongWordError state behavior is
reflected (error message visible and "Next" button disabled) for a 31-character
word, that a 30-character word passes, that multi-space inputs are handled
(ignore extra spaces and validate words correctly), and that recovery works
(enter invalid input, then change to valid input and assert error is cleared and
"Next" enabled). Target the validation logic that splits value into words and
uses hasLongWord (the code that calls setLongWordError and setLocalName) and
assert DOM changes rather than internal state. Ensure tests cover boundary
values, multi-space edge cases, and recovery after invalid input.
In `@frontend/src/pages/SettingsPage/components/AccountSettingsCard.tsx`:
- Around line 86-90: The longWordError validation currently only shows a message
but does not prevent submitting—update the save control to be disabled whenever
longWordError is true (and any other validation flags) so users cannot click
Save while the error is active; locate the Save button or submit handler in
AccountSettingsCard (e.g., the Save button element and the onSave/onSubmit
logic) and add a disable condition like disabled={longWordError || isSaving ||
otherValidationFlags} and/or guard the submit handler to return early if
longWordError is set to ensure the previous valid name cannot be submitted while
an avatar is selected.
---
Nitpick comments:
In `@frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx`:
- Around line 60-67: Extract the 30-char-per-word check into a shared helper
(e.g., validateNameWords or isNameWordTooLong) in a common utils/module used by
both onboarding and settings, replace the inline logic in AvatarSelectionStep
(the value.split, hasLongWord, setLongWordError, setLocalName block) to call the
helper and setLongWordError based on its boolean result, and update the Settings
component to use the same helper so the rule is centralized and cannot drift.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6179f1bd-c2ab-4358-8654-5cd41bb9ba0d
📒 Files selected for processing (3)
frontend/src/components/Navigation/Navbar/Navbar.tsxfrontend/src/components/OnboardingSteps/AvatarSelectionStep.tsxfrontend/src/pages/SettingsPage/components/AccountSettingsCard.tsx
…ting in Navbar and AccountSettingsCard
|
Thank you for your contribution @Umang-Khemka ! |
Summary
The following changes have been made to fix the navbar layout breaking due to long user names:
Addressed Issues:
Fixes #1280
Screenshots:
Before:
After:
Additional Notes:
Changes are limited to 3 frontend files only:
frontend/src/components/Navbar.tsxfrontend/src/components/OnboardingSteps/AvatarSelectionStep.tsxfrontend/src/pages/SettingsPage/components/AccountSettingsCard.tsxThis PR does not contain AI-generated code at all.
This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.
Checklist
Summary by CodeRabbit
New Features
Improvements