mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
82 lines
2.8 KiB
Markdown
82 lines
2.8 KiB
Markdown
# Seat Selection Fix - COMPLETED
|
|
|
|
## Issue
|
|
Users were unable to select another seat after clicking on one of the available seats. The seat selection wasn't responding to subsequent clicks.
|
|
|
|
## Root Cause
|
|
The `toggleSeat` function was using stale state from closures. When `setSelectedSeats` was called, it was based on the current value of `selectedSeats` at function definition time, not at click time. This caused state updates to be lost when clicking multiple seats rapidly.
|
|
|
|
## Solution
|
|
|
|
### 1. Fixed toggleSeat Function (Lines 103-112)
|
|
**Before:**
|
|
```typescript
|
|
const toggleSeat = (seatId: string) => {
|
|
if (selectedSeats.includes(seatId)) {
|
|
setSelectedSeats(selectedSeats.filter(id => id !== seatId));
|
|
} else if (selectedSeats.length < passengers.length) {
|
|
setSelectedSeats([...selectedSeats, seatId]);
|
|
}
|
|
};
|
|
```
|
|
|
|
**After:**
|
|
```typescript
|
|
const toggleSeat = (seatId: string) => {
|
|
setSelectedSeats(prev => {
|
|
if (prev.includes(seatId)) {
|
|
return prev.filter(id => id !== seatId);
|
|
} else if (prev.length < passengers.length) {
|
|
return [...prev, seatId];
|
|
}
|
|
return prev;
|
|
});
|
|
};
|
|
```
|
|
|
|
**Change:** Use functional state update pattern (`prev =>`) to ensure we always work with the latest state value.
|
|
|
|
### 2. Improved Seat Button Click Handler (Lines 211-215)
|
|
**Before:**
|
|
```typescript
|
|
onClick={() => seat.status === 'AVAILABLE' && toggleSeat(seat.id)}
|
|
```
|
|
|
|
**After:**
|
|
```typescript
|
|
onClick={() => {
|
|
if (seat.status === 'AVAILABLE') {
|
|
toggleSeat(seat.id);
|
|
}
|
|
}}
|
|
```
|
|
|
|
**Change:** Explicit conditional check in the handler for better clarity and reliability.
|
|
|
|
### 3. Added Cursor Pointer Style (Line 223)
|
|
Added `cursor-pointer` class to available seats to give better visual feedback that they're clickable.
|
|
|
|
## Benefits
|
|
|
|
✅ **Functional State Updates**: Uses React's functional setState pattern to always access latest state
|
|
✅ **No Stale Closures**: Eliminates closure issues that prevented multiple seat selections
|
|
✅ **Multiple Selections Work**: Users can now click multiple seats in sequence without issues
|
|
✅ **Better UX**: Explicit conditional makes code more maintainable and easier to debug
|
|
✅ **Visual Feedback**: Added cursor pointer to indicate clickable seats
|
|
|
|
## Testing Steps
|
|
|
|
1. Navigate to seat selection page
|
|
2. Click on first available seat - should highlight in primary color
|
|
3. Click on another available seat - should also highlight
|
|
4. Continue clicking multiple seats - all should remain selected
|
|
5. Click on a selected seat - should deselect it
|
|
6. Verify seat count updates in "Selection Summary" panel
|
|
|
|
## Technical Details
|
|
|
|
- React's `setSelectedSeats(prev => {...})` functional update ensures state consistency
|
|
- Each click now works with the current state, not a stale copy
|
|
- No race conditions with rapid clicks
|
|
- Maximum seats can still be selected based on passenger count
|