Checkmate icon indicating copy to clipboard operation
Checkmate copied to clipboard

# Fix: Save button disabled when timezone changes (#2343)

Open mohicody opened this issue 7 months ago • 1 comments

Describe your changes

Problem

When changing the timezone in the Settings page, the Save button remains disabled, preventing users from saving their timezone preference. After refreshing the page, the Save button works correctly.

Root Cause

  1. The timezone field was missing from both frontend and backend validation schemas
  2. When changing the timezone, the local component state wasn't properly updated
  3. The backend API validation rejected the timezone field since it wasn't in the allowed fields list

Solution

  1. Added timezone field to the frontend validation schema in validation.js
  2. Added timezone field to the backend validation schema in server/validation/joi.js
  3. Fixed state synchronization in the Settings component to properly update when timezone changes

Write your issue number after "Fixes "

Fixes #2343

Please ensure all items are checked off before requesting a review. "Checked off" means you need to add an "x" character between brackets so they turn into checkmarks.

  • [x] (Do not skip this or your PR will be closed) I deployed the application locally.
  • [x] (Do not skip this or your PR will be closed) I have performed a self-review and testing of my code.
  • [x] I have included the issue # in the PR.
  • [x] I have added i18n support to visible strings (instead of <div>Add</div>, use):
const { t } = useTranslation();
<div>{t('add')}</div>
  • [x] I have not included any files that are not related to my pull request, including package-lock and package-json if dependencies have not changed
  • [x] I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • [x] I made sure font sizes, color choices etc are all referenced from the theme. I have no hardcoded dimensions.
  • [x] My PR is granular and targeted to one specific feature.
  • [x] I took a screenshot or a video and attached to this PR if there is a UI change.

https://github.com/user-attachments/assets/626cc41c-f290-4a6a-9a54-d9cf8f375a84

Summary by CodeRabbit

  • New Features

    • Added support for updating and validating the timezone setting in user settings.
  • Bug Fixes

    • Ensured the displayed timezone value in settings stays in sync with user changes.

mohicody avatar May 28 '25 00:05 mohicody

Walkthrough

The changes update both client and server validation schemas to include an optional timezone field and modify the settings page logic to synchronize the local state when the timezone is changed. This ensures that timezone updates are properly reflected in the UI and pass validation checks.

Changes

File(s) Change Summary
client/src/Pages/Settings/index.jsx Updates handleChange to also update local settingsData when the timezone is changed.
client/src/Validation/validation.js Adds optional timezone string field to the settingsValidation Joi schema.
server/validation/joi.js Adds optional timezone string field to the updateAppSettingsBodyValidation Joi schema.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SettingsPage
    participant ReduxStore
    participant ValidationLayer

    User->>SettingsPage: Change timezone
    SettingsPage->>ReduxStore: Dispatch setTimezone action
    SettingsPage->>SettingsPage: Update local settingsData.timezone
    SettingsPage->>ValidationLayer: Validate settingsData (with timezone)
    ValidationLayer-->>SettingsPage: Validation result

Assessment against linked issues

Objective Addressed Explanation
Enable Save button when timezone changes (#2343)

Why did the Canadian developer refuse to use a timezone? Because he didn’t want to lose track of his moose-ments!


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b86d892c5652a64611d7935e1d6914fd820b73c and ed5d5986ff487c64839d0939855333006bc79556.

📒 Files selected for processing (3)
  • client/src/Pages/Settings/index.jsx (1 hunks)
  • client/src/Validation/validation.js (1 hunks)
  • server/validation/joi.js (1 hunks)
🔇 Additional comments (3)
client/src/Validation/validation.js (1)

280-280: LGTM! Timezone validation added correctly.

The timezone field is properly configured as an optional string that allows empty values, which is consistent with the schema pattern used for other optional settings fields.

server/validation/joi.js (1)

430-430: LGTM! Server validation aligns with client-side schema.

The timezone field is correctly added as an optional string allowing empty values, maintaining consistency with the client-side validation schema. This ensures timezone updates will pass validation on both ends - like a good Canadian-American trade agreement, everything's in sync! 🍁🦅

client/src/Pages/Settings/index.jsx (1)

88-89: LGTM! State synchronization fix addresses the Save button issue.

Adding setSettingsData(newSettingsData) ensures the local component state stays synchronized with the Redux state when the timezone changes. This should fix the issue where the Save button remained disabled after timezone updates - no more refreshing required! Unlike Americans waiting for their morning coffee, this fix works immediately. ☕

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar May 28 '25 00:05 coderabbitai[bot]