Spaces:
Running
Running
axeronis commited on
Commit ·
47ebad1
1
Parent(s): 07fe5c0
feat: Restrict resource working hours to company booking settings
Browse filesFiles changed (2)
190 unmodified lines191192193194195196197190 unmodified lines<div className="border-t border-white/10" />{/* Resources Manager */}<ResourcesManager />{/* Save Button */}<div className="pt-4 border-t border-white/10 flex justify-end">190 unmodified lines191192193194195196197190 unmodified lines<div className="border-t border-white/10" />{/* Resources Manager */}<ResourcesManager bookingSettings={localSettings} />{/* Save Button */}<div className="pt-4 border-t border-white/10 flex justify-end">
4 unmodified lines5678910117 unmodified lines192021222324252627282930313233343586 unmodified lines122123124125126127128129130131132133134135136137138139140141142143144145146147148149175 unmodified lines3253263273283293303313323333343353363373383393403412 unmodified lines3443453463473483491 unmodified line3513523533543553563573583593603614 unmodified linesimport { useToast } from '@/contexts/ToastContext'import { bookingsApi } from '@/lib/api'import { motion, AnimatePresence } from 'framer-motion'import { Loader2, Plus, Trash2, Edit2, X, Clock, CheckCircle, XCircle, Save, Send } from 'lucide-react'import { cn } from '@/lib/utils'interface Resource {7 unmodified linesservices: { id: string, name: string }[]}const DAYS = [{ key: '0', name: 'Пн' },{ key: '1', name: 'Вт' },{ key: '2', name: 'Ср' },{ key: '3', name: 'Чт' },{ key: '4', name: 'Пт' },{ key: '5', name: 'Сб' },{ key: '6', name: 'Вс' }]export default function ResourcesManager() {const toast = useToast()const queryClient = useQueryClient()86 unmodified lines}}const toggleDayHours = (day: string) => {if (formData.working_hours[day]) {const newHours = { ...formData.working_hours }delete newHours[day]setFormData({ ...formData, working_hours: newHours })} else {setFormData({...formData,working_hours: {...formData.working_hours,[day]: { start: '09:00', end: '18:00' }}})}}const updateDayHours = (day: string, field: 'start' | 'end', value: string) => {setFormData({...formData,working_hours: {...formData.working_hours,[day]: { ...formData.working_hours[day], [field]: value }}})}175 unmodified lines{/* Working Hours */}<div><label className="block text-sm text-slate-300 mb-2">Рабочие часы</label><div className="space-y-2">{DAYS.map(day => {const hours = formData.working_hours[day.key]return (<div key={day.key} className="flex items-center gap-2"><buttononClick={() => toggleDayHours(day.key)}className={cn("w-10 h-8 rounded font-medium text-sm transition-colors",hours ? "bg-indigo-600 text-white" : "bg-slate-700 text-slate-400")}>{day.name}</button>2 unmodified lines<inputtype="time"value={hours.start}onChange={(e) => updateDayHours(day.key, 'start', e.target.value)}className="px-2 py-1 bg-surface border border-white/10 rounded text-white text-sm"/>1 unmodified line<inputtype="time"value={hours.end}onChange={(e) => updateDayHours(day.key, 'end', e.target.value)}className="px-2 py-1 bg-surface border border-white/10 rounded text-white text-sm"/></>)}</div>)})}4 unmodified lines5678910117 unmodified lines1920212223242526272829303132333435363738394041424344454647484986 unmodified lines136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190175 unmodified lines3663673683693703713723733743753763773783793803813823833843853863873883893903913923932 unmodified lines3963973983994004014024031 unmodified line4054064074084094104114124134144154164174184194204 unmodified linesimport { useToast } from '@/contexts/ToastContext'import { bookingsApi } from '@/lib/api'import { motion, AnimatePresence } from 'framer-motion'import { Loader2, Plus, Trash2, Edit2, X, Clock, CheckCircle, XCircle, Save, Send, AlertCircle } from 'lucide-react'import { cn } from '@/lib/utils'interface Resource {7 unmodified linesservices: { id: string, name: string }[]}interface BookingSettings {working_days?: string[] // ['mon', 'tue', 'wed', 'thu', 'fri']working_hours?: { start: string; end: string } // { start: '09:00', end: '18:00' }}interface ResourcesManagerProps {bookingSettings?: BookingSettings}// Map: day key to day code used in booking_settingsconst DAY_KEY_TO_CODE: Record<string, string> = {'0': 'mon', '1': 'tue', '2': 'wed', '3': 'thu', '4': 'fri', '5': 'sat', '6': 'sun'}const DAYS = [{ key: '0', name: 'Пн', code: 'mon' },{ key: '1', name: 'Вт', code: 'tue' },{ key: '2', name: 'Ср', code: 'wed' },{ key: '3', name: 'Чт', code: 'thu' },{ key: '4', name: 'Пт', code: 'fri' },{ key: '5', name: 'Сб', code: 'sat' },{ key: '6', name: 'Вс', code: 'sun' }]export default function ResourcesManager({ bookingSettings }: ResourcesManagerProps) {const toast = useToast()const queryClient = useQueryClient()86 unmodified lines}}// Default company settingsconst companyDays = bookingSettings?.working_days || ['mon', 'tue', 'wed', 'thu', 'fri']const companyHours = bookingSettings?.working_hours || { start: '09:00', end: '18:00' }// Check if a day is a working day for the companyconst isDayAllowed = (dayCode: string) => companyDays.includes(dayCode)const toggleDayHours = (day: string) => {const dayCode = DAY_KEY_TO_CODE[day]// Don't allow toggling non-working daysif (!isDayAllowed(dayCode)) {toast.warning('Этот день — выходной', 'Измените в настройках записи')return}if (formData.working_hours[day]) {const newHours = { ...formData.working_hours }delete newHours[day]setFormData({ ...formData, working_hours: newHours })} else {// Use company hours as default for new daysetFormData({...formData,working_hours: {...formData.working_hours,[day]: { start: companyHours.start, end: companyHours.end }}})}}const updateDayHours = (day: string, field: 'start' | 'end', value: string) => {// Clamp value to company hourslet clampedValue = valueif (field === 'start' && value < companyHours.start) {clampedValue = companyHours.starttoast.warning('Минимальное время', `Компания работает с ${companyHours.start}`)}if (field === 'end' && value > companyHours.end) {clampedValue = companyHours.endtoast.warning('Максимальное время', `Компания работает до ${companyHours.end}`)}setFormData({...formData,working_hours: {...formData.working_hours,[day]: { ...formData.working_hours[day], [field]: clampedValue }}})}175 unmodified lines{/* Working Hours */}<div><label className="block text-sm text-slate-300 mb-2">Рабочие часы</label><p className="text-xs text-slate-500 mb-3 flex items-center gap-1"><AlertCircle className="w-3 h-3" />Доступно: {companyDays.map(d => d.substring(0, 2).toUpperCase()).join(', ')} с {companyHours.start} до {companyHours.end}</p><div className="space-y-2">{DAYS.map(day => {const hours = formData.working_hours[day.key]const allowed = isDayAllowed(day.code)return (<div key={day.key} className="flex items-center gap-2"><buttononClick={() => toggleDayHours(day.key)}disabled={!allowed}className={cn("w-10 h-8 rounded font-medium text-sm transition-colors",!allowed? "bg-slate-800 text-slate-600 cursor-not-allowed opacity-50": hours? "bg-indigo-600 text-white": "bg-slate-700 text-slate-400 hover:bg-slate-600")}title={!allowed ? 'Выходной день компании' : ''}>{day.name}</button>2 unmodified lines<inputtype="time"value={hours.start}min={companyHours.start}max={companyHours.end}onChange={(e) => updateDayHours(day.key, 'start', e.target.value)}className="px-2 py-1 bg-surface border border-white/10 rounded text-white text-sm"/>1 unmodified line<inputtype="time"value={hours.end}min={companyHours.start}max={companyHours.end}onChange={(e) => updateDayHours(day.key, 'end', e.target.value)}className="px-2 py-1 bg-surface border border-white/10 rounded text-white text-sm"/></>)}{!allowed && (<span className="text-xs text-slate-600">выходной</span>)}</div>)})}
frontend/components/BookingSettings.tsx+1-1
frontend/components/ResourcesManager.tsx+71-12