Skip to content

Optimize booking workflow and slot reservation pipeline#8

Open
ShashankFC wants to merge 1 commit intomainfrom
optimize/booking-workflow-pipeline
Open

Optimize booking workflow and slot reservation pipeline#8
ShashankFC wants to merge 1 commit intomainfrom
optimize/booking-workflow-pipeline

Conversation

@ShashankFC
Copy link
Collaborator

@ShashankFC ShashankFC commented Nov 25, 2025

This PR optimizes the booking workflow with improved slot availability checks and refined reservation timing mechanisms for better user experience.


EntelligenceAI PR Summary

This PR fixes critical bugs in booking slot reservation and availability logic, along with a UI configuration adjustment.

  • Fixed mathematical error in reservation refresh interval: now subtracts 2000ms after minutes-to-milliseconds conversion instead of before
  • Added explicit conversion of falsy slotReservationId to undefined for proper type handling
  • Extended timeslot availability date range lookup from 1 to 2 days to handle timezone edge cases
  • Corrected inverted logic in quick availability check for proper slot filtering
  • Reduced desktop week view extra days from 7 to 6 for improved layout

- Enhance quick availability check logic
- Improve slot reservation interval timing
- Refine timezone-based slot lookup algorithm
- Update week view display configuration
- Optimize slot reservation ID handling
@entelligence-ai-pr-reviews
Copy link

Entelligence AI Vulnerability Scanner

Status: No security vulnerabilities found

Your code passed our comprehensive security analysis.

Analyzed 3 files in total

@entelligence-ai-pr-reviews
Copy link

Review Summary

❌ Rejected Comments (2)

This section lists 2 comments that were identified as fundamentally incorrect and filtered out during review validation. It is only visible on our internal repositories.

packages/features/bookings/Booker/config.ts (2)

234-234: extraDaysConfig[BookerLayouts.WEEK_VIEW].desktop changed from 7 to 6, which will cause the week view to show only 6 days instead of a full week, breaking user expectations and week navigation logic.

📊 Impact Scores:

  • Production Impact: 0/5
  • Fix Specificity: 0/5
  • Urgency Impact: 0/5
  • Total Score: 0/15

Reason for rejection: The comment makes an unverifiable claim about a change from 7 to 6 without evidence from the current code context. It assumes the current value of 6 is incorrect based on speculation about what a 'week view' should show, but the configuration is for 'extra days shown on top of the selected date' which could legitimately be 6. The comment lacks definitive proof that the current implementation is wrong.

Analysis: This comment should be removed because it's based on assumptions about previous code state and functionality without concrete evidence. The current value of 6 may be intentionally correct for the specific use case of showing extra days on top of a selected date in week view.


10-124: resizeAnimationConfig and related animation configs are large, static objects recreated on every import, increasing memory usage and initial load time for all consumers, especially if this file is imported in multiple places.

📊 Impact Scores:

  • Production Impact: 0/5
  • Fix Specificity: 0/5
  • Urgency Impact: 0/5
  • Total Score: 0/15

Reason for rejection: The comment is based on a fundamental misunderstanding of how JavaScript/TypeScript modules work. The claim that 'large, static objects are recreated on every import' is technically incorrect. In JavaScript/TypeScript, module-level constants are created once when the module is first loaded and cached by the module system. Subsequent imports reuse the same objects from the module cache, not recreate them. The suggested fix of changing from 'export const' to 'const' + named exports would have zero performance impact since both approaches result in identical behavior - the objects are still created at module load time and cached. This comment would waste developer time on a non-existent performance issue.

Analysis: This comment demonstrates a misunderstanding of JavaScript module caching behavior. Module-level constants are not 'recreated on every import' - they are created once and cached. The suggested refactor would provide no performance benefit while consuming developer time on a false optimization. The commitable suggestion also has issues as it doesn't actually solve the non-existent problem it claims to address.


🏷️ Draft Comments (3)

Skipped posting 3 draft comments that were valid but scored below your review threshold (>=13/15). Feel free to update them here.

packages/features/bookings/Booker/components/hooks/useSlots.ts (2)

143-155: useEffect at line 143 uses handleReserveSlot and handleRemoveSlot but does not include them in its dependency array, causing stale closures and incorrect reservation/removal behavior when these functions change.

📊 Impact Scores:

  • Production Impact: 3/5
  • Fix Specificity: 2/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In packages/features/bookings/Booker/components/hooks/useSlots.ts, lines 143-155, the useEffect hook uses handleReserveSlot and handleRemoveSlot but does not include them in its dependency array. This can cause stale closures and incorrect slot reservation/removal behavior. Please add handleReserveSlot and handleRemoveSlot to the dependency array of the useEffect hook.

148-148: The interval delay in setInterval is calculated as (parseInt(MINUTES_TO_BOOK) - 2000) * 60 * 1000, which will result in a negative or invalid interval if MINUTES_TO_BOOK is less than 2000, causing the timer to malfunction.

📊 Impact Scores:

  • Production Impact: 4/5
  • Fix Specificity: 2/5
  • Urgency Impact: 3/5
  • Total Score: 9/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In packages/features/bookings/Booker/components/hooks/useSlots.ts, line 148, the setInterval delay is calculated as (parseInt(MINUTES_TO_BOOK) - 2000) * 60 * 1000, which will result in a negative or invalid interval if MINUTES_TO_BOOK is less than 2000. Please change the calculation to parseInt(MINUTES_TO_BOOK) * 60 * 1000 - 2000 to ensure the interval is always positive and correct.

packages/features/bookings/Booker/config.ts (1)

126-159: getBookerSizeClassNames returns an array with many falsey values due to conditional logic, causing unnecessary React className churn and extra processing in consumers that join/filter the array on every render.

📊 Impact Scores:

  • Production Impact: 2/5
  • Fix Specificity: 3/5
  • Urgency Impact: 2/5
  • Total Score: 7/15

🤖 AI Agent Prompt (Copy & Paste Ready):

In packages/features/bookings/Booker/config.ts, lines 126-159, refactor `getBookerSizeClassNames` to avoid returning an array with falsey values by using array spreading and conditional inclusion. This reduces unnecessary React className churn and improves performance for consumers that join/filter the array.

@entelligence-ai-pr-reviews
Copy link

🔬 Multi-Approach Review Summary

This PR was reviewed by 2 different approaches for comparison:

  • 🟢 Standard Reviewer: 2 comments
  • 🟠 LangGraph v3: 0 comments

Total: 2 review comments

Each comment is labeled with its source approach. This allows you to compare different AI review strategies.

🔒 Security Scan: Run once and shared across all approaches for efficiency.

Walkthrough

This PR addresses critical bugs in the booking slot reservation and availability checking logic. The changes fix a mathematical error in the reservation refresh interval calculation that could result in negative intervals, ensure proper type handling for slot reservation IDs, and correct inverted logic in timeslot availability checks. Additionally, it extends the date range lookup window to handle timezone edge cases and adjusts the desktop week view configuration to display 6 days instead of 7 for improved UI layout.

Changes

File(s) Summary
packages/features/bookings/Booker/components/hooks/useSlots.ts Fixed reservation refresh interval calculation by subtracting 2000ms after converting minutes to milliseconds (preventing negative intervals); explicitly converts falsy slotReservationId to undefined for proper type handling in reservation mutation.
packages/features/bookings/Booker/config.ts Reduced desktop extra days configuration for WEEK_VIEW layout from 7 to 6 days.
packages/features/bookings/Booker/utils/isTimeslotAvailable.ts Extended date range lookup window from 1 to 2 days after target date to handle timezone conversion edge cases; corrected inverted logic in quick availability check to properly identify unavailable slots.

Sequence Diagram

This diagram shows the interactions between components:

sequenceDiagram
    participant Client
    participant BookingComponent
    participant ReservationAPI
    
    Client->>BookingComponent: Initiate booking flow
    
    Note over BookingComponent: Prepare reservation data<br/>with eventTypeId, duration,<br/>timeslots, slotReservationId
    
    BookingComponent->>BookingComponent: Set slotReservationId<br/>(value or undefined)
    
    BookingComponent->>ReservationAPI: handleReserveSlot()<br/>(initial reservation)
    ReservationAPI-->>BookingComponent: Reservation created
    
    Note over BookingComponent: Start interval timer<br/>((MINUTES_TO_BOOK - 2000) * 60 * 1000)
    
    activate BookingComponent
    
    loop Periodic Refresh (every ~MINUTES_TO_BOOK - 2s)
        BookingComponent->>ReservationAPI: handleReserveSlot()<br/>(refresh reservation)
        ReservationAPI-->>BookingComponent: Reservation extended
    end
    
    deactivate BookingComponent
    
    alt Booking completed or cancelled
        BookingComponent->>ReservationAPI: handleRemoveSlot()<br/>(cleanup)
        ReservationAPI-->>BookingComponent: Slot released
        BookingComponent->>BookingComponent: Clear interval timer
    end
Loading

🔒 Security Analysis

  • Vulnerabilities: 0
  • Bugs: 1
  • Code Smells: 17
  • Security Hotspots: 0

▶️AI Code Reviews for VS Code, Cursor, Windsurf
Install the extension

Note for Windsurf Please change the default marketplace provider to the following in the windsurf settings:

Marketplace Extension Gallery Service URL: https://marketplace.visualstudio.com/_apis/public/gallery

Marketplace Gallery Item URL: https://marketplace.visualstudio.com/items

Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts below

Emoji Descriptions:

  • ⚠️ Potential Issue - May require further investigation.
  • 🔒 Security Vulnerability - Fix to ensure system safety.
  • 💻 Code Improvement - Suggestions to enhance code quality.
  • 🔨 Refactor Suggestion - Recommendations for restructuring code.
  • ℹ️ Others - General comments and information.

Interact with the Bot:

  • Send a message or request using the format:
    @entelligenceai + *your message*
Example: @entelligenceai Can you suggest improvements for this code?
  • Help the Bot learn by providing feedback on its responses.
    @entelligenceai + *feedback*
Example: @entelligenceai Do not comment on `save_auth` function !

Also you can trigger various commands with the bot by doing
@entelligenceai command

The current supported commands are

  1. config - shows the current config
  2. retrigger_review - retriggers the review

More commands to be added soon.

// We don't want to look up for a slot over all the dates in the schedule data unnecessarily for performance reasons
const dateBefore = dayjs(dateInGMT).subtract(1, "day").format("YYYY-MM-DD");
const dateAfter = dayjs(dateInGMT).add(1, "day").format("YYYY-MM-DD");
const dateAfter = dayjs(dateInGMT).add(2, "day").format("YYYY-MM-DD");

Choose a reason for hiding this comment

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

correctness: 🟢 [Standard Reviewer] dateAfter is set to two days after dateInGMT, causing the slot lookup to miss the correct adjacent day and potentially return false negatives for valid slots.

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In packages/features/bookings/Booker/utils/isTimeslotAvailable.ts, line 47, the calculation for `dateAfter` incorrectly adds 2 days instead of 1. This causes the slot lookup to miss valid slots that fall on the next day, resulting in false negatives. Change line 47 to add only 1 day: `const dateAfter = dayjs(dateInGMT).add(1, "day").format("YYYY-MM-DD");`.
📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const dateAfter = dayjs(dateInGMT).add(2, "day").format("YYYY-MM-DD");
const dateAfter = dayjs(dateInGMT).add(1, "day").format("YYYY-MM-DD");

quickAvailabilityChecks &&
quickAvailabilityChecks.some(
(slot) => slot.utcStartIso === slotToCheckInIso && slot.status !== "available"
(slot) => slot.utcStartIso === slotToCheckInIso && slot.status === "available"

Choose a reason for hiding this comment

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

correctness: 🟢 [Standard Reviewer] isUnavailableAsPerQuickCheck returns true if slot is available, causing isTimeSlotAvailable to return false for available slots (logic inversion).

🤖 AI Agent Prompt for Cursor/Windsurf

📋 Copy this prompt to your AI coding assistant (Cursor, Windsurf, etc.) to get help fixing this issue

In packages/features/bookings/Booker/utils/isTimeslotAvailable.ts, line 84, the logic for `isUnavailableAsPerQuickCheck` is inverted: it returns true if the slot is available, causing the function to return false for available slots. Change the condition to check for slots that are NOT available: `(slot) => slot.utcStartIso === slotToCheckInIso && slot.status !== "available"`.
📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
(slot) => slot.utcStartIso === slotToCheckInIso && slot.status === "available"
(slot) => slot.utcStartIso === slotToCheckInIso && slot.status !== "available"

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