Spaces:
Running
Running
axeronis commited on
Commit ·
a99b470
1
Parent(s): 027f30e
feat: Replace time inputs with select dropdown showing only company hours
Browse files
frontend/components/ResourcesManager.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
-
import { useState } from 'react'
|
| 4 |
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
| 5 |
import { useToast } from '@/contexts/ToastContext'
|
| 6 |
import { bookingsApi } from '@/lib/api'
|
|
@@ -140,6 +140,21 @@ export default function ResourcesManager({ bookingSettings }: ResourcesManagerPr
|
|
| 140 |
const companyDays = bookingSettings?.working_days || ['mon', 'tue', 'wed', 'thu', 'fri']
|
| 141 |
const companyHours = bookingSettings?.working_hours || { start: '09:00', end: '18:00' }
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
// Check if a day is a working day for the company
|
| 144 |
const isDayAllowed = (dayCode: string) => companyDays.includes(dayCode)
|
| 145 |
|
|
@@ -393,23 +408,25 @@ export default function ResourcesManager({ bookingSettings }: ResourcesManagerPr
|
|
| 393 |
</button>
|
| 394 |
{hours && (
|
| 395 |
<>
|
| 396 |
-
<
|
| 397 |
-
type="time"
|
| 398 |
value={hours.start}
|
| 399 |
-
min={companyHours.start}
|
| 400 |
-
max={companyHours.end}
|
| 401 |
onChange={(e) => updateDayHours(day.key, 'start', e.target.value)}
|
| 402 |
className="px-2 py-1 bg-surface border border-white/10 rounded text-white text-sm"
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
<span className="text-slate-500">—</span>
|
| 405 |
-
<
|
| 406 |
-
type="time"
|
| 407 |
value={hours.end}
|
| 408 |
-
min={companyHours.start}
|
| 409 |
-
max={companyHours.end}
|
| 410 |
onChange={(e) => updateDayHours(day.key, 'end', e.target.value)}
|
| 411 |
className="px-2 py-1 bg-surface border border-white/10 rounded text-white text-sm"
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
</>
|
| 414 |
)}
|
| 415 |
{!allowed && (
|
|
|
|
| 1 |
'use client'
|
| 2 |
|
| 3 |
+
import { useState, useMemo } from 'react'
|
| 4 |
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
| 5 |
import { useToast } from '@/contexts/ToastContext'
|
| 6 |
import { bookingsApi } from '@/lib/api'
|
|
|
|
| 140 |
const companyDays = bookingSettings?.working_days || ['mon', 'tue', 'wed', 'thu', 'fri']
|
| 141 |
const companyHours = bookingSettings?.working_hours || { start: '09:00', end: '18:00' }
|
| 142 |
|
| 143 |
+
// Generate time slots within company hours (30min intervals)
|
| 144 |
+
const availableTimeSlots = useMemo(() => {
|
| 145 |
+
const slots: string[] = []
|
| 146 |
+
const startHour = parseInt(companyHours.start.split(':')[0]) || 9
|
| 147 |
+
const endHour = parseInt(companyHours.end.split(':')[0]) || 18
|
| 148 |
+
|
| 149 |
+
for (let h = startHour; h <= endHour; h++) {
|
| 150 |
+
slots.push(`${h.toString().padStart(2, '0')}:00`)
|
| 151 |
+
if (h < endHour) {
|
| 152 |
+
slots.push(`${h.toString().padStart(2, '0')}:30`)
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
return slots
|
| 156 |
+
}, [companyHours])
|
| 157 |
+
|
| 158 |
// Check if a day is a working day for the company
|
| 159 |
const isDayAllowed = (dayCode: string) => companyDays.includes(dayCode)
|
| 160 |
|
|
|
|
| 408 |
</button>
|
| 409 |
{hours && (
|
| 410 |
<>
|
| 411 |
+
<select
|
|
|
|
| 412 |
value={hours.start}
|
|
|
|
|
|
|
| 413 |
onChange={(e) => updateDayHours(day.key, 'start', e.target.value)}
|
| 414 |
className="px-2 py-1 bg-surface border border-white/10 rounded text-white text-sm"
|
| 415 |
+
>
|
| 416 |
+
{availableTimeSlots.map(slot => (
|
| 417 |
+
<option key={slot} value={slot}>{slot}</option>
|
| 418 |
+
))}
|
| 419 |
+
</select>
|
| 420 |
<span className="text-slate-500">—</span>
|
| 421 |
+
<select
|
|
|
|
| 422 |
value={hours.end}
|
|
|
|
|
|
|
| 423 |
onChange={(e) => updateDayHours(day.key, 'end', e.target.value)}
|
| 424 |
className="px-2 py-1 bg-surface border border-white/10 rounded text-white text-sm"
|
| 425 |
+
>
|
| 426 |
+
{availableTimeSlots.map(slot => (
|
| 427 |
+
<option key={slot} value={slot}>{slot}</option>
|
| 428 |
+
))}
|
| 429 |
+
</select>
|
| 430 |
</>
|
| 431 |
)}
|
| 432 |
{!allowed && (
|