Spaces:
Sleeping

axeronis commited on
Commit
e9c092b
·
1 Parent(s): 5152823

fix(frontend): handle mixed string/number types in booking modal days settings

Browse files
frontend/components/bookings/BookingModal.tsx CHANGED
@@ -109,16 +109,29 @@ export function BookingModal({ isOpen, onClose, leadId, leadName }: BookingModal
109
 
110
  const jsDay = getDay(date)
111
  const dayKey = String(jsDay === 0 ? 6 : jsDay - 1)
 
112
 
 
113
  if (selectedResourceData?.working_hours) {
114
  return !!selectedResourceData.working_hours[dayKey]
115
  }
116
 
 
117
  if (bookingSettings) {
118
- const dayIndex = jsDay === 0 ? 6 : jsDay - 1
119
- return bookingSettings.working_days.includes(dayIndex)
 
 
 
 
 
 
 
 
 
120
  }
121
 
 
122
  return jsDay !== 0 && jsDay !== 6
123
  }, [selectedResourceData, bookingSettings])
124
 
@@ -136,7 +149,19 @@ export function BookingModal({ isOpen, onClose, leadId, leadName }: BookingModal
136
  const timeSlots = useMemo(() => {
137
  if (!selectedDate || !isWorkingDay(selectedDate)) return []
138
  const hours = getWorkingHours(selectedDate)
139
- return generateTimeSlots(hours.start, hours.end, bookingSettings?.slot_duration || 30)
 
 
 
 
 
 
 
 
 
 
 
 
140
  }, [selectedDate, getWorkingHours, isWorkingDay, bookingSettings?.slot_duration])
141
 
142
  const calendarDays = useMemo(() => {
 
109
 
110
  const jsDay = getDay(date)
111
  const dayKey = String(jsDay === 0 ? 6 : jsDay - 1)
112
+ const dayIndex = jsDay === 0 ? 6 : jsDay - 1
113
 
114
+ // Resource-specific schedule
115
  if (selectedResourceData?.working_hours) {
116
  return !!selectedResourceData.working_hours[dayKey]
117
  }
118
 
119
+ // Global settings
120
  if (bookingSettings) {
121
+ // Handle both number[] (old) and string[] (new from BookingSettings.tsx)
122
+ const days = bookingSettings.working_days
123
+ if (Array.isArray(days) && days.length > 0) {
124
+ // Check if days are strings like 'mon', 'tue'
125
+ if (typeof days[0] === 'string') {
126
+ const DAY_IDS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
127
+ return days.includes(DAY_IDS[dayIndex] as any)
128
+ }
129
+ // Check if days are numbers 0-6
130
+ return days.includes(dayIndex)
131
+ }
132
  }
133
 
134
+ // Fallback: Mon-Fri
135
  return jsDay !== 0 && jsDay !== 6
136
  }, [selectedResourceData, bookingSettings])
137
 
 
149
  const timeSlots = useMemo(() => {
150
  if (!selectedDate || !isWorkingDay(selectedDate)) return []
151
  const hours = getWorkingHours(selectedDate)
152
+ const slots = generateTimeSlots(hours.start, hours.end, bookingSettings?.slot_duration || 30)
153
+
154
+ // Filter past times if today
155
+ if (isSameDay(selectedDate, new Date())) {
156
+ const now = new Date()
157
+ const currentMinutes = now.getHours() * 60 + now.getMinutes()
158
+ return slots.filter(slot => {
159
+ const [h, m] = slot.split(':').map(Number)
160
+ return (h * 60 + m) > currentMinutes
161
+ })
162
+ }
163
+
164
+ return slots
165
  }, [selectedDate, getWorkingHours, isWorkingDay, bookingSettings?.slot_duration])
166
 
167
  const calendarDays = useMemo(() => {