Skip to content

Conversation

@divyanshu-patil
Copy link

@divyanshu-patil divyanshu-patil commented Nov 6, 2025

Proposed changes

reset all fields of Form after changing workspace

Issue(s)

closes #6762

How to test or reproduce

Screenshots

Workspaces Comparison

Workspace Preview
mobile.rocket.chat
open.rocket.chat

Video:

Before / After

Before After
https://github.com/user-attachments/assets/34d60efc-d5ef-4fd2-b4d8-038bc7bebd77 https://github.com/user-attachments/assets/3f88222a-e965-45f1-8b25-43e8a8876fa3

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices app

ly)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Profile form now rehydrates with the latest account data when the view regains focus, populating name, username, email, bio, and nickname so displayed values stay synchronized with the current user.
    • The form will also refresh when underlying account data changes, ensuring edits start from up-to-date values.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Walkthrough

ProfileView's form reset behavior was changed: the component now calls reset(...) with the current user's name, username, email, bio, and nickname inside a useEffect that depends on user and reset, instead of using a no-argument reset() in useFocusEffect.

Changes

Cohort / File(s) Summary
Profile form reset update
app/views/ProfileView/index.tsx
Replaced useFocusEffect no-arg reset() with a useEffect that calls reset({ name, username, email: emails?.[0]?.address, currentPassword, bio, nickname, saving }); added user and reset to effect deps; adjusted imports and expanded useForm return usage.

Sequence Diagram(s)

sequenceDiagram
    participant View as ProfileView
    participant Store as Redux selector
    participant Form as react-hook-form

    rect rgb(248,249,255)
    View->>Store: select `user` (and related settings)
    end

    Note over View,Form: On mount and when `user` or `reset` changes
    rect rgb(235,250,235)
    View->>Form: useEffect -> reset({ name, username, email, currentPassword, bio, nickname, saving })
    Form-->>View: form state rehydrated with current user values
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify emails?.[0]?.address mapping and null-safety.
  • Confirm effect dependency list (user, reset) is correct and doesn't trigger excessive resets.
  • Check there are no leftover useFocusEffect usages or unused imports.

Possibly related PRs

Suggested reviewers

  • OtavioStasiak
  • diegolmello

Poem

🐰
I hopped through props and gentle state,
Pulled user fields to populate.
Name and nick in rows aligned,
Email tucked, the bio defined.
A nibble, a hop — the form feels light.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing profile details not updating when switching workspaces, which directly addresses the linked issue.
Linked Issues check ✅ Passed The code changes reset profile form fields with current user data on focus, directly addressing the bug where username and other profile details didn't update when switching workspaces.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the profile form rehydration issue in ProfileView, with no unrelated modifications introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2d51ccf and feea90d.

⛔ Files ignored due to path filters (2)
  • Gemfile.lock is excluded by !**/*.lock
  • ios/Podfile.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • app/views/ProfileView/index.tsx (3 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
app/views/ProfileView/index.tsx (1)

283-291: Incomplete form reset when workspace changes.

The change from useFocusEffect to useEffect([user, reset]) correctly fixes the workspace-change bug by only resetting when the user object changes, not on every screen focus. However, the reset omits currentPassword and saving fields that are defined in defaultValues (lines 100, 103) and included in the post-submit reset (lines 219, 222).

Impact:

  • currentPassword could retain a value from the previous workspace, creating a privacy risk or causing failed submissions with wrong credentials.
  • saving could show a stale loading state after workspace switch.

Apply this diff to include all form fields in the reset:

 	useEffect(() => {
 		reset({
 			name: user?.name || '',
 			username: user?.username || '',
 			email: user?.emails?.[0]?.address || '',
 			bio: user?.bio || '',
-			nickname: user?.nickname || ''
+			nickname: user?.nickname || '',
+			currentPassword: null,
+			saving: false
 		});
 	}, [user, reset]);
🧹 Nitpick comments (1)
app/views/ProfileView/index.tsx (1)

96-104: Align defaultValues with reset patterns for consistency.

The defaultValues use mixed patterns (as string, ternary with null, optional chaining allowing undefined), while reset calls consistently use || '' to default to empty strings. This inconsistency could cause subtle form behavior differences between initial load and post-reset states.

Apply this diff to align defaultValues with the reset pattern:

 	defaultValues: {
-		name: user?.name as string,
+		name: user?.name || '',
 		username: user?.username,
-		email: user?.emails ? user?.emails[0].address : null,
+		email: user?.emails?.[0]?.address || '',
 		currentPassword: null,
-		bio: user?.bio,
-		nickname: user?.nickname,
+		bio: user?.bio || '',
+		nickname: user?.nickname || '',
 		saving: false
 	},
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 625cd3d and 44a4b6f.

⛔ Files ignored due to path filters (2)
  • Gemfile.lock is excluded by !**/*.lock
  • ios/Podfile.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • app/views/ProfileView/index.tsx (3 hunks)
🔇 Additional comments (2)
app/views/ProfileView/index.tsx (2)

3-3: LGTM: Import changes align with the fix.

The removal of useFocusEffect and useCallback imports is correct, as the fix properly replaces focus-based reset with effect-based reset.


60-82: LGTM: Well-structured selector consolidation.

The consolidated useAppSelector properly extracts all necessary state and settings in a single call with appropriate type assertions.

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.

bug: Username not updating while switching the workspace

2 participants