Skip to content

fix: submit button not enabled when toggling switches in room edit#6669

Merged
OtavioStasiak merged 1 commit intodevelopfrom
room-edit-switch-fix
Sep 22, 2025
Merged

fix: submit button not enabled when toggling switches in room edit#6669
OtavioStasiak merged 1 commit intodevelopfrom
room-edit-switch-fix

Conversation

@Rohit3523
Copy link
Contributor

@Rohit3523 Rohit3523 commented Sep 20, 2025

Proposed changes

In the Room Edit screen, the Save Changes button wasn’t enabling when toggling switches, Based on react-hook-form/react-hook-form#72 (comment) comment , I am passing { shouldDirty } as the third parameter in setValue to ensure that it updates the value as soon as we click the switch and enables the submit button.

Issue(s)

N/A

How to test or reproduce

  1. Go to any room edit screen
  2. Click on Public or Private
  3. Observe 'Save Changes' and 'Cancel' button

Screenshots

OS Before After
Android https://github.com/user-attachments/assets/f4cde33e-e7cc-4fc2-b332-7dbd89a9ece1 https://github.com/user-attachments/assets/69a55ad1-bea1-4c60-873e-52c2e5cc20f5
iOS https://github.com/user-attachments/assets/bcb20607-e1b3-4135-9389-4290e5b47249 https://github.com/user-attachments/assets/3328efd8-f0b5-449b-ba29-d163c8ecf59a

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 apply)

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
    • Room settings toggles now correctly register changes, enabling the Save/Update action and showing unsaved-changes prompts as expected.
    • Affected toggles include: Room Type, Encryption, Read-only, React when read-only, and System messages.
    • Improves reliability when editing room info, reducing the risk of losing changes before saving.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 20, 2025

Walkthrough

Adds react-hook-form SetValueConfig and a shared dirtyOptions with shouldDirty: true, updating toggle handlers in RoomInfoEditView to pass this option to setValue so related fields register as dirty when toggled.

Changes

Cohort / File(s) Summary of changes
Form dirty-state handling
app/views/RoomInfoEditView/index.tsx
Import SetValueConfig; define dirtyOptions with shouldDirty: true; pass dirtyOptions as third argument to setValue in toggle handlers for t (room type), encrypted, readOnly, reactWhenReadOnly, enableSysMes/systemMessages to ensure dirty state tracking.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant V as RoomInfoEditView
  participant F as react-hook-form
  participant S as setValue(..., value, { shouldDirty: true })

  U->>V: Toggle a switch (e.g., Read Only)
  V->>F: setValue(field, value, dirtyOptions)
  activate F
  F->>S: Apply value with shouldDirty: true
  S-->>F: Field updated and marked dirty
  deactivate F
  F-->>V: Form state updated (dirty = true)
  V-->>U: UI reflects change and dirty state
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • diegolmello

Poem

A twitch of a toggle, a hop of a byte,
I nudge the form gently to mark it just right.
ShouldDirty, I whisper, with paws oh-so-witty—
Now fields wear smudges of meaningful gritty.
Flip, flop, save—carrots for code so pretty! 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title concisely describes the primary fix—enabling the submit ("Save Changes") button when toggling switches in the Room Edit screen. It directly matches the changeset that calls setValue with { shouldDirty: true } so toggle changes mark the form dirty. The phrasing is specific, uses the conventional "fix:" prefix, and is clear for teammates scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch room-edit-switch-fix

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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/views/RoomInfoEditView/index.tsx (1)

274-281: Save button still won’t enable when only “System Messages” selection changes.

MultiSelect updates systemMessages via setValue without shouldDirty, so toggling only the selection won’t enable “Save Changes.” Mirror the toggle fix here.

- onChange={({ value }) => setValue('systemMessages', value)}
+ onChange={({ value }) => setValue('systemMessages', value, dirtyOptions)}

Also applies to: 307-309

🧹 Nitpick comments (3)
app/views/RoomInfoEditView/index.tsx (3)

6-6: Use type‑only import (combine with existing import).

Simplify and avoid potential value import by combining into a single type‑only import.

-import { useForm } from 'react-hook-form';
-import { type SetValueConfig } from 'react-hook-form';
+import { useForm, type SetValueConfig } from 'react-hook-form';

291-293: Double‑check encryption behavior when switching room type.

With disabled={!t} on the Encrypted switch, encryption is only toggleable when t is true (public). Combined with setValue('encrypted', value && encrypted, ...), switching to private (value=false) forces encrypted to false. If the product rule is “encryption allowed only on private rooms,” this is inverted.

If that rule applies, adjust to disable when public and keep previous value when switching to private:

- setValue('t', value, dirtyOptions);
- setValue('encrypted', value && encrypted, dirtyOptions);
+ setValue('t', value, dirtyOptions);
+ // If encryption is only for private rooms, zero it when going public, preserve otherwise
+ setValue('encrypted', !value && encrypted, dirtyOptions);

And in the Encrypted switch:

- disabled={!t}
+ disabled={t}

480-486: Optional: add a quick e2e to prevent regressions.

Add a Detox test that toggles each switch (t, readOnly, reactWhenReadOnly, enableSysMes, encrypted) and asserts room-info-edit-view-submit becomes enabled.

📜 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 2dc07bd and e9d4d84.

📒 Files selected for processing (1)
  • app/views/RoomInfoEditView/index.tsx (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/views/RoomInfoEditView/index.tsx (1)
app/lib/methods/helpers/log/index.ts (1)
  • logEvent (35-42)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: ESLint and Test / run-eslint-and-test
🔇 Additional comments (4)
app/views/RoomInfoEditView/index.tsx (4)

43-45: Good: centralized dirty options.

Defining a shared dirtyOptions with shouldDirty: true is the right fix for enabling the submit button on toggle.


297-297: Good: readOnly now marks form dirty.


302-302: Good: reactWhenReadOnly now marks form dirty.


313-313: Good: encrypted toggle now marks form dirty.

Copy link
Contributor

@OtavioStasiak OtavioStasiak left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@OtavioStasiak OtavioStasiak merged commit 8a19a9f into develop Sep 22, 2025
6 of 16 checks passed
@OtavioStasiak OtavioStasiak deleted the room-edit-switch-fix branch September 22, 2025 22:06
@Rohit3523
Copy link
Contributor Author

Thanks :)

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.

2 participants