Skip to content

[Bugfix]: Fix uninformative error message for incorrect value in Event date field #3648

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Tadei-Mykola
Copy link
Contributor

@Tadei-Mykola Tadei-Mykola commented Apr 29, 2025

Summary by CodeRabbit

  • New Features

    • Improved date input validation in the event creation form, now supporting multiple date formats and providing immediate feedback for invalid entries.
  • Bug Fixes

    • Enhanced error messaging for date format issues, offering clearer instructions in both English and Ukrainian.
  • Refactor

    • Updated the date validation logic to ensure stricter checks and more accurate error display.
  • Chores

    • Removed unused date adapter and validator files to streamline the codebase.

@Tadei-Mykola Tadei-Mykola self-assigned this Apr 29, 2025
Copy link

coderabbitai bot commented Apr 29, 2025

Walkthrough

This update introduces stricter and more flexible date validation in the event creation form by supporting multiple date input formats and providing clearer user guidance. The changes include the addition of a new dateFormatValidator for validating date inputs, updates to the error message display logic in the template, and enhancements to the date parsing and display formats. Several files related to the Moment.js date adapter and time validation are removed, streamlining date handling. Localization strings for date format errors are updated in both English and Ukrainian to offer explicit formatting instructions.

Changes

File(s) Change Summary
.../date-time.component.html Modified error message condition to check the day control for date format errors instead of startDate.
.../date-time.component.ts Added ChangeDetectorRef and new dateFormatValidator. Expanded supported date formats and updated display format. Improved validation and UI update logic.
.../event-custom-validators.ts Added new exported dateFormatValidator function for validating date input format.
.../moment-date-adapter/index.ts
.../moment-date-adapter/moment-date-adapter.ts
.../moment-date-adapter/moment-date-formats.ts
.../moment-date-adapter/moment-date-adapter.spec.ts
Deleted all Moment.js date adapter implementation files, including modules, formats, and tests.
.../date-time/validator/timeValidator.ts Deleted custom timeValidator function file.
src/assets/i18n/en.json Updated English date format error message to specify accepted formats.
src/assets/i18n/ua.json Updated Ukrainian date format error message to specify accepted formats.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DateInputComponent
    participant FormControl
    participant dateFormatValidator

    User->>DateInputComponent: Enters date value
    DateInputComponent->>FormControl: Updates 'day' control value
    FormControl->>dateFormatValidator: Validate input format
    dateFormatValidator-->>FormControl: Return error if invalid
    FormControl-->>DateInputComponent: Update error state
    DateInputComponent->>User: Display specific error message if invalid
Loading

Poem

In the garden where dates now bloom,
New formats chase the error gloom.
Old adapters hop away,
Validators come out to play.
With clearer hints in every tongue,
Our forms grow strong, our code stays young!
🐇🌱✨

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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.

Copy link

@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

🧹 Nitpick comments (2)
src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/date-time.component.ts (2)

154-156: Effective validation setup with proper change detection

The changes in ngAfterViewInit properly add the date format validator, update the control's validity, and trigger change detection to reflect validation status immediately in the UI.

One consideration: validators are typically added during form initialization rather than in ngAfterViewInit. Since this works for your use case, it's acceptable, but consider moving validation setup to form initialization in future refactors.


1-313: Consider adopting OnPush change detection strategy

Since you're using manual change detection with ChangeDetectorRef, this component might benefit from using OnPush change detection strategy, which could improve performance by reducing unnecessary change detection cycles.

You could add this to your @component decorator:

@Component({
  selector: 'app-date-time',
  templateUrl: './date-time.component.html',
  styleUrls: ['./date-time.component.scss'],
+ changeDetection: ChangeDetectionStrategy.OnPush,
  providers: [
    { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
    { provide: MAT_DATE_FORMATS, useValue: MY_FORMATS }
  ]
})

Don't forget to add the import:

import { ChangeDetectionStrategy } from '@angular/core';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 04f39a2 and 2433031.

📒 Files selected for processing (10)
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/date-time.component.html (1 hunks)
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/date-time.component.ts (5 hunks)
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/moment-date-adapter/index.ts (0 hunks)
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/moment-date-adapter/moment-date-adapter.spec.ts (0 hunks)
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/moment-date-adapter/moment-date-adapter.ts (0 hunks)
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/moment-date-adapter/moment-date-formats.ts (0 hunks)
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/validator/timeValidator.ts (0 hunks)
  • src/app/greencity/modules/events/components/event-editor/validators/event-custom-validators.ts (1 hunks)
  • src/assets/i18n/en.json (1 hunks)
  • src/assets/i18n/ua.json (1 hunks)
💤 Files with no reviewable changes (5)
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/moment-date-adapter/index.ts
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/validator/timeValidator.ts
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/moment-date-adapter/moment-date-formats.ts
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/moment-date-adapter/moment-date-adapter.spec.ts
  • src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/moment-date-adapter/moment-date-adapter.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/date-time.component.ts (1)
src/app/greencity/modules/events/components/event-editor/validators/event-custom-validators.ts (1)
  • dateFormatValidator (35-45)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (18.x)
🔇 Additional comments (10)
src/app/greencity/modules/events/components/event-editor/validators/event-custom-validators.ts (1)

35-45: Well-implemented date format validator function

The new dateFormatValidator function is cleanly implemented, following Angular's validator pattern. It properly checks if a date value exists and is valid using the optional chaining operator for safe property access.

src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/date-time.component.html (1)

10-10: Error message now correctly references the day control

Good change to update the error message condition to check the day control for the dateIncorrect error instead of the startDate control. This aligns with the new validation approach and ensures users receive appropriate feedback.

src/assets/i18n/en.json (1)

1362-1362: Improved error message with clear date format instructions

The updated error message is much more helpful, providing explicit guidance on the accepted date formats (MM/DD/YYYY or month DD YYYY). This will significantly improve the user experience when entering dates.

src/assets/i18n/ua.json (1)

1401-1401: Localization properly adapted for Ukrainian date format convention

Good job adapting the date format guidance for Ukrainian users (DD.MM.YYYY or DD month YYYY), respecting the common day-first format used in Ukraine. This ensures consistent localization across the application.

src/app/greencity/modules/events/components/event-editor/components/create-event-dates/date-time/date-time.component.ts (6)

1-1: Nice addition of ChangeDetectorRef for proper change detection

The import of ChangeDetectorRef is necessary for the manual change detection triggering used later in the component lifecycle.


10-10: Good import of the custom validator

This import properly brings in the dateFormatValidator that will be used to validate date formats.


14-14: Excellent enhancement of date format support

Supporting multiple date input formats ('DD MMM, YYYY', 'DD.MM.YYYY', 'MMM DD, YYYY', 'MM/DD/YYYY') provides a much better user experience, allowing users to enter dates in the format they're most comfortable with.


17-17: Good switch to localized long date format

Using 'LL' for the display format ensures the date is shown in a user-friendly, localized format appropriate for the current language.


74-75: Proper dependency injection

The inclusion of DateAdapter and ChangeDetectorRef as private dependencies follows Angular best practices.


134-136: Good defensive programming

The early return when newDate is falsy prevents unnecessary processing and potential errors during date conversion or manipulation.

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.

1 participant