feat: configurable bed types via BedTypesContext

- Add BedTypesContext with default types + add/remove/update operations
- Replace hardcoded BED_ITEM_TYPES array in RoomModal with useBedTypes()
- Add "Справочник спальных мест" section to RoomCategoriesPage
  (expandable, same UX as amenities: add icon+label, rename, delete)
- BedItem.type changed from union to string for dynamic support

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 14:20:09 +03:00
parent 6bf1391890
commit 8c6cdfb1c7
5 changed files with 206 additions and 15 deletions

View File

@@ -0,0 +1,53 @@
import { createContext, useContext, useState } from 'react'
import type { ReactNode } from 'react'
export interface BedTypeItem {
value: string // unique key stored in DB (e.g. 'double', 'sofa')
label: string // display name
icon: string // emoji
}
const DEFAULT_BED_TYPES: BedTypeItem[] = [
{ value: 'single', label: 'Кровать 1-сп.', icon: '🛏' },
{ value: 'double', label: 'Кровать 2-сп.', icon: '🛏' },
{ value: 'queen', label: 'Queen-кровать', icon: '🛏' },
{ value: 'king', label: 'King-кровать', icon: '🛏' },
{ value: 'twin', label: 'Две кровати', icon: '🛏' },
{ value: 'sofa', label: 'Диван', icon: '🛋' },
{ value: 'bunk', label: 'Двухъярусная', icon: '🛏' },
{ value: 'cot', label: 'Раскладушка', icon: '🪑' },
]
interface BedTypesContextValue {
bedTypes: BedTypeItem[]
addBedType: (item: BedTypeItem) => void
removeBedType: (value: string) => void
updateBedType: (value: string, patch: Partial<Omit<BedTypeItem, 'value'>>) => void
}
const BedTypesContext = createContext<BedTypesContextValue | null>(null)
export function BedTypesProvider({ children }: { children: ReactNode }) {
const [bedTypes, setBedTypes] = useState<BedTypeItem[]>(DEFAULT_BED_TYPES)
const addBedType = (item: BedTypeItem) =>
setBedTypes(prev => prev.find(b => b.value === item.value) ? prev : [...prev, item])
const removeBedType = (value: string) =>
setBedTypes(prev => prev.filter(b => b.value !== value))
const updateBedType = (value: string, patch: Partial<Omit<BedTypeItem, 'value'>>) =>
setBedTypes(prev => prev.map(b => b.value === value ? { ...b, ...patch } : b))
return (
<BedTypesContext.Provider value={{ bedTypes, addBedType, removeBedType, updateBedType }}>
{children}
</BedTypesContext.Provider>
)
}
export function useBedTypes() {
const ctx = useContext(BedTypesContext)
if (!ctx) throw new Error('useBedTypes must be used within BedTypesProvider')
return ctx
}