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:
38
src/contexts/AmenitiesContext.tsx
Normal file
38
src/contexts/AmenitiesContext.tsx
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user