Skip to content

Conversation

@juah255
Copy link

@juah255 juah255 commented Jan 24, 2026

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

Closes

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • Improvements

    • Consistent, localized time formatting for store open/close fields and pickers using a moment-compatible format.
    • Visible time inputs now mirror values into hidden fields for reliable form submission.
    • Improved show/hide behavior, validation, error highlighting, and auto-focus on the first invalid time entry.
  • New Features

    • Added helper to generate a moment.js-compatible i18n time format.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

📝 Walkthrough

Walkthrough

Server-side time parsing calls to dokan_convert_date_format were simplified by removing explicit input/output format arguments; client templates decouple visible time inputs from submitted values (hidden fields); client JS adds a Moment.js-compatible i18n time format helper and uses it for parsing, formatting, and validation before submit.

Changes

Cohort / File(s) Change Summary
Server-side time parsing
includes/Dashboard/Templates/Settings.php
Removed explicit input/output format parameters when converting opening_time and closing_time; calls now pass only the time string (relying on the function's defaults).
Client templates — form & time inputs
templates/settings/store-form.php, templates/settings/store-time.php
Visible time inputs no longer carry name attributes; hidden inputs with submission names were added to mirror visible values. Template markup/labels adjusted; minor comment/whitespace edits.
Client JS helper & validation
assets/src/js/helper.js, templates/settings/store-form.php (JS)
Added dokan_get_i18n_time_format_for_moment_js() to produce Moment-compatible formats; JS now uses a localized moment-based time format for timepicker parsing/formatting, populates hidden fields (hh:mm a), and validates open/close times before submit.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser as Client JS
    participant Server as PHP
    participant DB

    User->>Browser: Enter opening/closing times (visible inputs)
    Browser->>Browser: Parse/format with dokan_get_i18n_time_format_for_moment_js (moment)\nPopulate hidden inputs with standardized values
    User->>Browser: Submit form
    Browser->>Server: POST with hidden time fields
    Server->>Server: Convert/validate times (dokan_convert_date_format)
    Server->>DB: Save store timings
    DB-->>Server: Persisted
    Server-->>Browser: Response (saved)
    Browser-->>User: Show confirmation
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • mrabbani
  • shohag121

Poem

🐰 I hop and parse the hours with care,

Visible clocks for show, hidden ones to bear,
Moment sings the format true,
Server nods and saves it too,
A rabbit cheers — timing's fair.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks critical content sections including specific changes proposed, testing steps, changelog entry, before/after descriptions, and acceptance criteria details. Complete the PR description by filling in: 1) 'Changes proposed' section explaining the time format fix, 2) 'How to test' with specific reproduction steps, 3) 'Changelog entry' with summary, and 4) 'Before/After Changes' with descriptions of the issue and fix.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix—addressing custom time format issues for store opening/closing times in vendor settings, which aligns with the code changes across multiple template and helper files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

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

🤖 Fix all issues with AI agents
In `@templates/settings/store-form.php`:
- Around line 340-344: The client-side time formatting currently uses
moment(...).format('hh:mm a') for openValueSelected and closeValueSelected which
produces leading zeros; update both calls to use format('h:mm a') to match the
server-side PHP expectation (ensure the two lines setting openValueSelected and
closeValueSelected are changed), so the values written via
$openInputHidden.val(...) and $closeInputHidden.val(...) will have no leading
zero.

In `@templates/settings/store-time.php`:
- Around line 26-32: The value attributes for the opening time inputs are
outputting the raw $opening_time variable and must be escaped to prevent XSS;
update both the visible input (id "opening-time[<?php echo esc_attr( $day_key );
?>]" / class "opening-time") and the hidden input (name "opening_time[<?php echo
esc_attr( $day_key ); ?>]" / class "opening-time-hidden") to wrap $opening_time
with esc_attr() so the attribute values are safely escaped before rendering.
🧹 Nitpick comments (1)
templates/settings/store-form.php (1)

378-385: Same format inconsistency and missing invalid date handling.

  1. Same 'hh:mm a' vs 'h:mm a' issue as the change handler.
  2. If moment() parsing fails (e.g., empty or malformed input after manual edit), format() returns "Invalid date" which would be submitted to the server.
Proposed fix
                 const formattedOpenValue  = moment( openValue, timeFormatMoment ).format( 'HH:mm' ),
                     formattedCloseValue = moment( closeValue, timeFormatMoment ).format( 'HH:mm' );

-                let openValueSelected  = moment(openValue, timeFormatMoment ).format('hh:mm a');
-                let closeValueSelected = moment(closeValue, timeFormatMoment ).format('hh:mm a');
+                const parsedOpen  = moment( openValue, timeFormatMoment );
+                const parsedClose = moment( closeValue, timeFormatMoment );
+
+                if ( ! parsedOpen.isValid() || ! parsedClose.isValid() ) {
+                    self.find( 'input.dokan-form-control' ).css({ 'border-color': '#F87171', 'color': '#F87171' });
+                    self.find( '.opening-time' ).focus();
+                    e.preventDefault();
+                    return false;
+                }
+
+                let openValueSelected  = parsedOpen.format( 'h:mm a' );
+                let closeValueSelected = parsedClose.format( 'h:mm a' );

                 $openInputHidden.val(openValueSelected);
                 $closeInputHidden.val(closeValueSelected);

Comment on lines 340 to 344
let openValueSelected = moment( openValue, timeFormatMoment ).format('hh:mm a' );
let closeValueSelected = moment( closeValue, timeFormatMoment ).format('hh:mm a' );

$openInputHidden.val( openValueSelected );
$closeInputHidden.val( closeValueSelected );
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Use 'h:mm a' format to match server-side expectations.

The 'hh:mm a' format outputs times with leading zeros (e.g., "09:30 am"), but the PHP backend uses 'g:i a' which expects no leading zeros (e.g., "9:30 am"). Use moment's single 'h' to avoid potential parsing issues.

Proposed fix
-                let openValueSelected  = moment( openValue, timeFormatMoment ).format('hh:mm a' );
-                let closeValueSelected = moment( closeValue, timeFormatMoment ).format('hh:mm a' );
+                let openValueSelected  = moment( openValue, timeFormatMoment ).format('h:mm a' );
+                let closeValueSelected = moment( closeValue, timeFormatMoment ).format('h:mm a' );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let openValueSelected = moment( openValue, timeFormatMoment ).format('hh:mm a' );
let closeValueSelected = moment( closeValue, timeFormatMoment ).format('hh:mm a' );
$openInputHidden.val( openValueSelected );
$closeInputHidden.val( closeValueSelected );
let openValueSelected = moment( openValue, timeFormatMoment ).format('h:mm a' );
let closeValueSelected = moment( closeValue, timeFormatMoment ).format('h:mm a' );
$openInputHidden.val( openValueSelected );
$closeInputHidden.val( closeValueSelected );
🤖 Prompt for AI Agents
In `@templates/settings/store-form.php` around lines 340 - 344, The client-side
time formatting currently uses moment(...).format('hh:mm a') for
openValueSelected and closeValueSelected which produces leading zeros; update
both calls to use format('h:mm a') to match the server-side PHP expectation
(ensure the two lines setting openValueSelected and closeValueSelected are
changed), so the values written via $openInputHidden.val(...) and
$closeInputHidden.val(...) will have no leading zero.

@juah255 juah255 requested a review from mrabbani January 24, 2026 11:05
@juah255 juah255 added the Needs: Dev Review It requires a developer review and approval label Jan 24, 2026
@MdAsifHossainNadim MdAsifHossainNadim added the Needs: Testing This requires further testing label Jan 26, 2026
@juah255 juah255 self-assigned this Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants