minor cleanup

This commit is contained in:
mikicvi
2025-09-26 22:42:29 +01:00
parent 220f999f19
commit b95a2ab2e4
4 changed files with 0 additions and 594 deletions
-119
View File
@@ -1,119 +0,0 @@
# Day-Specific Booking Times & User Display Features
## Overview
This update introduces two major features to the table tennis booking system:
### 1. Day-Specific Booking Times
The system now supports different booking hours for different days of the week. Administrators can configure custom time slots for each day (Sunday through Saturday).
#### Example Configuration:
- **Sunday**: 12:00 - 17:00 (Weekend afternoon sessions)
- **Monday**: 19:00 - 23:00 (Evening sessions only)
- **Tuesday**: 19:00 - 23:00 (Evening sessions only)
- **Wednesday**: 18:00 - 22:00 (Shorter evening sessions)
- **Thursday**: 19:00 - 23:00 (Evening sessions only)
- **Friday**: 18:00 - 22:00 (Shorter evening sessions)
- **Saturday**: 10:00 - 18:00 (Full day weekend sessions)
### 2. User Name Display
The booking calendar now shows who has booked each court slot, displaying the full name of the person who made the booking.
## Implementation Details
### Database Schema
The system uses the existing `timeSlots` table in the database schema:
```sql
CREATE TABLE time_slots (
id TEXT PRIMARY KEY,
dayOfWeek INTEGER NOT NULL, -- 0 = Sunday, 1 = Monday, etc.
startTime TEXT NOT NULL, -- Format: "HH:MM"
endTime TEXT NOT NULL, -- Format: "HH:MM"
isActive BOOLEAN DEFAULT TRUE,
createdAt INTEGER NOT NULL,
updatedAt INTEGER NOT NULL
);
```
### API Endpoints
#### Public Endpoints (for authenticated users):
- `GET /api/time-slots` - Retrieve active time slots for all days
- `GET /api/bookings/all?date=YYYY-MM-DD` - Get all bookings with user and court information
#### Admin Endpoints:
- `GET /api/admin/time-slots` - Retrieve all time slots (including inactive)
- `POST /api/admin/time-slots` - Create new time slot
- `PUT /api/admin/time-slots/[id]` - Update existing time slot
- `DELETE /api/admin/time-slots/[id]` - Delete time slot
### Admin Management
Administrators can manage time slots through the admin dashboard under the "Settings" tab. The interface allows:
- **Create Time Slots**: Set day of week, start time, end time, and active status
- **Edit Time Slots**: Modify existing time slot configurations
- **Delete Time Slots**: Remove time slot configurations
- **Activate/Deactivate**: Toggle time slots on/off without deletion
### User Experience
#### Enhanced Booking Calendar:
- Automatically adapts to show only available time slots for the selected day
- Displays who has booked each unavailable slot
- Maintains mobile-responsive design
- Provides fallback to global settings if no day-specific slots are configured
#### Booking Display:
- Available slots: Green background with "Book" button
- Booked slots: Red background showing "Booked by [Full Name]"
- Clear visual distinction between available and booked slots
## Usage Instructions
### For Administrators:
1. **Navigate to Admin Dashboard** → Settings tab
2. **Time Slot Management section** allows you to:
- Add new time slots for specific days
- Edit existing time slot configurations
- View all time slots organized by day of the week
- Activate/deactivate time slots as needed
### For Users:
1. **Select a date** in the enhanced booking calendar
2. **View available time slots** automatically filtered for that day
3. **See who has booked unavailable slots** to know who might be playing
4. **Book available slots** with partner information as before
## Technical Benefits
- **Flexible Scheduling**: Different operational hours for different days
- **User Transparency**: Know who's playing when for coordination
- **Administrative Control**: Easy management of time slots
- **Backward Compatibility**: Maintains fallback to global settings
- **Mobile Optimized**: Responsive design across all devices
## Migration
The system includes database seeding scripts that populate initial time slots based on the example configuration above. Existing bookings and functionality remain unchanged.
## Future Enhancements
Potential future improvements could include:
- Seasonal time slot variations
- Holiday-specific scheduling
- Automatic time slot generation tools
- Bulk time slot operations
- Time slot templates for quick setup
-108
View File
@@ -1,108 +0,0 @@
# 🇮🇪 Irish Localization Implementation Complete
## Overview
Successfully implemented Irish localization for the table tennis booking app, with Monday as the first day of the week and Irish (en-IE) date formatting throughout.
## Key Changes Made
### 1. Utility Functions (`lib/utils.ts`)
- **Updated `getWeekDays()`**: Now returns Monday-Sunday order with proper JS day values
- **Added Irish conversion functions**:
- `getIrishDayOfWeek()`: Converts JS getDay() (0=Sunday) to Irish standard (0=Monday)
- `getJavaScriptDayOfWeek()`: Converts Irish day index back to JS getDay() format
- `getIrishDayName()`: Gets day name using Irish week start
- **Updated `formatDate()`**: Changed from 'en-US' to 'en-IE' locale
### 2. Admin Time Slot Management (`components/admin/AdminTimeSlotManagement.tsx`)
- **Irish week order**: Days now display Monday through Sunday
- **Updated constants**: `IRISH_DAY_ORDER = [1, 2, 3, 4, 5, 6, 0]` for correct mapping
- **Form defaults**: New time slots default to Monday (dayOfWeek: 1)
- **Display logic**: Correctly maps JS day values to Irish display order
- **Dropdown options**: Time slot creation shows days in Irish order
### 3. Calendar UI Component (`components/ui/calendar.tsx`)
- **Added `weekStartsOn={1}`**: Calendar widget now starts with Monday
- **Updated locale**: Changed month formatting to 'en-IE'
- **Data attributes**: Updated to use Irish locale for consistency
### 4. Enhanced Booking Calendar (`components/booking/enhanced-booking-calendar.tsx`)
- **Date formatting**: All `toLocaleDateString()` calls updated to 'en-IE'
- **Consistent display**: Weekday abbreviations and full date formats use Irish locale
- **Time slot logic**: Maintains compatibility with JS day values in database
### 5. All Other Components
Updated locale formatting in:
- `components/dashboard/BookingCalendar.tsx`
- `components/user/user-profile.tsx`
- `components/notifications/announcements.tsx`
- `components/admin/AdminUserManagement.tsx`
- `components/admin/AdminAnnouncementManagement.tsx`
- `components/admin/AdminCourtManagement.tsx`
### 6. API Compatibility Fix
- **Fixed Next.js 15 async params**: Updated time-slots/[id]/route.ts to properly handle async params
## Database Compatibility
- **No database changes needed**: Database still stores JavaScript's getDay() values (0=Sunday, 6=Saturday)
- **Mapping handled in UI**: All conversion between JS day values and Irish display order handled in frontend
- **Backward compatibility**: Existing time slots and bookings work seamlessly
## Technical Implementation
### Day Mapping Logic
```javascript
// JavaScript getDay() values remain in database:
// 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday
// Irish display order (Monday first):
const IRISH_DAY_ORDER = [1, 2, 3, 4, 5, 6, 0]; // Maps to Monday-Sunday
// Admin panel shows: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
// But stores as: 1, 2, 3, 4, 5, 6, 0
```
### Locale Settings
- **Calendar**: Starts with Monday (`weekStartsOn={1}`)
- **Date Format**: Irish format (DD/MM/YYYY pattern via en-IE)
- **Time Format**: Maintained 24-hour format as requested
- **Day Names**: All components use Irish week order for display
## User Impact
1. **Admin Interface**: Time slot management shows Monday first, making it intuitive for Irish users
2. **Booking Calendar**: Date selection and display follow Irish conventions
3. **Date Display**: All dates throughout the app use Irish formatting (en-IE)
4. **Week View**: Calendar widgets start with Monday as expected in Ireland
## Testing Verification
- ✅ Created test script (`scripts/test-irish-localization.js`) to verify settings
- ✅ Confirmed day mapping logic works correctly
- ✅ Verified Irish date formatting across all components
- ✅ Time slot management displays in correct order
- ✅ Calendar widgets start with Monday
## Benefits
- **Cultural Alignment**: Follows Irish/European convention of Monday as week start
- **User Experience**: More intuitive for Irish users
- **Consistency**: All date formatting uses Irish locale
- **Maintainable**: Clean separation between database storage and display logic
- **No Breaking Changes**: Existing bookings and time slots continue to work
## Future Considerations
- Could extend to full internationalization (i18n) if needed for other locales
- Day conversion utilities are ready for reuse across the application
- Database schema remains flexible for any future locale changes
-157
View File
@@ -1,157 +0,0 @@
# ✅ ROBUST BOOKING VALIDATION IMPLEMENTATION COMPLETE
## 🎯 **PROBLEM SOLVED**
**Original Issue**: "On days where there is no booking slots(e.g. none set up, no play that day), system just gives all of the options to the clients. Robust checking has to be in place to not allow clients ever try to book something that is not available, not via UI, not via API"
## 🛡️ **COMPREHENSIVE VALIDATION LAYERS**
### **1. Database Layer ✅**
- **Time Slots Configuration**: Proper day-specific time slots in database
- **Current Configuration**:
- Sunday: 12:00-17:00
- Monday: 19:00-23:00
- Tuesday: 19:00-23:00
- **Wednesday: CLOSED** (no time slots)
- **Thursday: CLOSED** (no time slots)
- Friday: 18:00-22:00
- Saturday: 10:00-18:00
### **2. API Layer Validation ✅**
**File**: `/app/api/bookings/route.ts`
-**Day Validation**: Rejects bookings on days with no time slots
-**Time Validation**: Rejects bookings outside allowed time ranges
-**Detailed Error Messages**: Specific feedback for different validation failures
**Example API Responses**:
```json
// Booking on Wednesday (closed day)
{
"error": "No bookings are allowed on Wednesdays. The facility is closed on this day."
}
// Booking at wrong time on Monday
{
"error": "Time slot 10:00 is not available on Mondays. Available times: 19:00-23:00"
}
```
### **3. UI Layer Validation ✅**
**File**: `/components/booking/enhanced-booking-calendar.tsx`
#### **Date Selection Prevention**:
-`isDateSelectable()` function prevents selecting unavailable days
- ✅ Calendar disables days with no time slots
- ✅ Users cannot click on closed days
#### **Time Slot Generation**:
-`generateTimeSlots()` only shows available times for selected day
-**NO FALLBACK** to global settings - returns empty array if no day-specific slots
-`isDayBookable()` function checks if day has any active time slots
#### **Visual Feedback**:
- ✅ Clear messages: "No courts available on Wednesdays"
- ✅ Explains facility is closed on that day
- ✅ Shows who booked each unavailable slot
#### **Multiple Validation Points**:
-`handleSlotClick()` - Prevents booking dialog on invalid slots
-`handleBookingConfirm()` - Final validation before API call
- ✅ Toast notifications for validation failures
### **4. User Experience Features ✅**
#### **Day-Specific Booking Times**:
- ✅ Different hours for different days of the week
- ✅ Admin can configure via Time Slot Management interface
- ✅ Automatic calendar adaptation based on selected date
#### **Enhanced Booking Display**:
- ✅ Shows "Booked by [Full Name]" instead of just "Booked"
-`/api/bookings/all` endpoint includes user information
- ✅ Clear visual distinction between available/unavailable slots
## 🧪 **VALIDATION TEST SCENARIOS**
The system now prevents ALL of these invalid booking attempts:
1. **❌ Booking on Closed Days**
- UI: Date not selectable, clear "facility closed" message
- API: "No bookings are allowed on Wednesdays"
2. **❌ Booking at Wrong Times**
- UI: Time slot not generated, not displayed
- API: "Time slot 10:00 is not available on Mondays"
3. **❌ Direct API Attacks**
- Comprehensive server-side validation
- Detailed error messages for debugging
- No way to bypass UI restrictions
4. **✅ Valid Bookings Only**
- Only shows available times for bookable days
- Only allows clicks on valid time slots
- Only processes API calls for valid day/time combinations
## 🎯 **SECURITY GUARANTEES**
### **Zero Bypass Paths**:
- ✅ Users cannot select unavailable dates in calendar
- ✅ Users cannot see unavailable time slots
- ✅ Users cannot click on invalid slots
- ✅ Users cannot submit booking forms for invalid times
- ✅ API rejects all invalid booking attempts with specific errors
### **Admin Control**:
- ✅ Complete control over which days have courts available
- ✅ Flexible time ranges per day
- ✅ Easy enable/disable of specific time slots
- ✅ Activity logging of all time slot changes
## 📋 **IMPLEMENTATION FILES**
### **Modified/Created Files**:
1.`/app/api/bookings/route.ts` - Server-side validation
2.`/components/booking/enhanced-booking-calendar.tsx` - UI validation
3.`/app/api/time-slots/route.ts` - Public time slots API
4.`/app/api/admin/time-slots/route.ts` - Admin time slots API
5.`/components/admin/AdminTimeSlotManagement.tsx` - Admin interface
6.`/scripts/seed-time-slots.ts` - Database seeding
7. ✅ Database schema with proper time_slots table
### **Validation Functions**:
-`isDayBookable()` - Checks if day has any time slots
-`isDateSelectable()` - Prevents selecting unavailable dates
-`generateTimeSlots()` - Only returns valid times for day
- ✅ Server-side day/time validation in booking API
## 🚀 **RESULT**
**PROBLEM COMPLETELY SOLVED**:
- ❌ Users can NO LONGER book on days without time slots
- ❌ Users can NO LONGER book at unavailable times
- ❌ No fallback to global settings - strict day-specific enforcement
- ✅ Clear communication about facility availability
- ✅ Robust validation at every layer (UI, API, Database)
- ✅ Enhanced UX with user names and day-specific times
The system is now **bulletproof** against invalid booking attempts through any channel.