Add centralized amenities directory and hourly booking example

- AmenitiesContext: shared amenities list with add/edit/delete, available app-wide
- RoomsPage: collapsible Справочник удобств section (add/rename/delete)
- RoomModal + RoomCategoriesPage: use amenities from context, no hardcoded lists
- RoomCategoriesPage: removed custom amenity input (use справочник instead)
- mockData: room 103 now has allowHourly=true, added sample hourly booking (today, 10-13ч)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-16 15:40:01 +03:00
parent c347c99228
commit 87455c2710
6 changed files with 156 additions and 59 deletions

View File

@@ -0,0 +1,38 @@
import { createContext, useContext, useState } from 'react'
import type { ReactNode } from 'react'
const DEFAULT_AMENITIES = [
'Wi-Fi', 'TV', 'AC', 'Mini-bar', 'Bathrobe', 'Jacuzzi',
'Panoramic view', 'Kitchen', 'Washing machine', 'Butler', 'Terrace',
'Safe', 'Hairdryer', 'Iron', 'Balcony',
]
interface AmenitiesContextValue {
amenities: string[]
addAmenity: (a: string) => void
removeAmenity: (a: string) => void
renameAmenity: (oldName: string, newName: string) => void
}
const AmenitiesContext = createContext<AmenitiesContextValue | null>(null)
export function AmenitiesProvider({ children }: { children: ReactNode }) {
const [amenities, setAmenities] = useState<string[]>(DEFAULT_AMENITIES)
const addAmenity = (a: string) => setAmenities(prev => prev.includes(a) ? prev : [...prev, a])
const removeAmenity = (a: string) => setAmenities(prev => prev.filter(x => x !== a))
const renameAmenity = (oldName: string, newName: string) =>
setAmenities(prev => prev.map(x => x === oldName ? newName.trim() || x : x))
return (
<AmenitiesContext.Provider value={{ amenities, addAmenity, removeAmenity, renameAmenity }}>
{children}
</AmenitiesContext.Provider>
)
}
export function useAmenities() {
const ctx = useContext(AmenitiesContext)
if (!ctx) throw new Error('useAmenities must be used within AmenitiesProvider')
return ctx
}