// Management → Tables → Floor plans (plan step 6.8, D-31): the venue's floor plans by zone (a zone // can have several, e.g. "Ground floor" and "Upstairs"; a plan may have no zone), "New floor plan", // and the chosen plan's editor (FloorEditor). The phones, the counter and the Tables page draw // the saved plans live (@xenia/floorplan FloorView). import { useState } from 'react' import toast from 'react-hot-toast' import { Plus } from 'lucide-react' import { errorMessage } from '@xenia/api' import { useTranslation } from '@xenia/i18n' import { Button, Dialog, EmptyState, Field, Input, Select, Spinner, cx } from '@xenia/ui' import { useLiveQuery } from '../../live/useLiveQuery' import FloorEditor from './FloorEditor' import * as api from './floorApi' const SIZES = { small: [800, 600], medium: [1200, 800], large: [1800, 1200] } export default function FloorPlansTab() { const { t } = useTranslation('manager') const { data, refetch } = useLiveQuery({ queryKey: ['floor-plans'], queryFn: api.listPlans, events: api.FLOOR_EVENTS }) const { data: groups = [] } = useLiveQuery({ queryKey: ['table-groups'], queryFn: api.listZones, events: ['table_list_changed'] }) const [chosen, setChosen] = useState(null) const [creating, setCreating] = useState(false) const [version, setVersion] = useState(0) // a new editor after a save (it starts from what was saved) if (!data) return
const plans = data.plans const plan = plans.find(p => p.id === chosen) ?? plans[0] ?? null const byZone = [...groups.map(g => ({ id: g.id, name: g.name, plans: plans.filter(p => p.group_id === g.id) })), { id: null, name: t('floor.noZone'), plans: plans.filter(p => p.group_id == null || !groups.some(g => g.id === p.group_id)) }].filter(z => z.plans.length) return (
{plan ? ( { await refetch(); setVersion(v => v + 1) }} onDeleted={async () => { setChosen(null); await refetch(); setVersion(v => v + 1) }} /> ) : } onClick={() => setCreating(true)}>{t('floor.new')}} />}
{creating && setCreating(false)} onCreate={async body => { try { const p = await api.createPlan(body) setCreating(false) await refetch() setChosen(p.id) setVersion(v => v + 1) } catch (err) { toast.error(errorMessage(err, t)) } }} />}
) } function NewPlan({ groups, onClose, onCreate }) { const { t } = useTranslation('manager') const [name, setName] = useState('') const [zone, setZone] = useState(groups[0]?.id ?? null) const [size, setSize] = useState('medium') return ( }>
setName(e.target.value)} placeholder={t('floor.namePlaceholder')} data-testid="floor-new-name" /> setSize(e.target.value)} options={Object.keys(SIZES).map(k => ({ value: k, label: t(`floor.sizes.${k}`, { w: SIZES[k][0], h: SIZES[k][1] }) }))} />
) }