From the owner's page-by-page review (2026-11-20): - every page root is <Page> (scrolls, fills 1080p, 16:9 centred on ultrawides); not yet: products, management/tables, stock (next pass) - /dashboard: more padding in cards (p-card), quieter secondary text, 11px uppercase labels everywhere (text-overline) - day stats: xl dialog, "● Day running · Opened …" as text, the six figures in equal boxes, "On tabs" in the payments bar, shared Tabs - /tables: Segmented List / Map / QR codes (?view=; /online/qr redirects), filter chips + zones multi-select at one height, the card itself opens the table (button removed), cards ~20% wider - /online-orders: shared Tabs with Settings (= the old /online/fees page, which redirects to ?tab=settings); orders fill the width - contacts, customers, expenses: PageHeader + Toolbar + SearchInput + multi-select Dropdowns (kinds; statuses, categories); table cells vertically centred; the Spent tip opens on hover - filterCards / filterContacts / filterExpenses take several values (unit tests added) - docs/DESIGN.md: the design language (CS-20 in the pack README) - tests/e2e/manager_layout.mjs: the page rule at 1920x1080 and 3440x1440; manager.mjs and manager_look.mjs follow the moved pages Verified: manager build + lint (0 errors), unit tests (manager 99, ui 24, i18n 31, api 25, access 8), i18n guard, manager_layout.mjs all passed, manager.mjs 228 checks all passed. Not checked: the waiter app and the terminal by eye (they only get the muted ink-2 token). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
5.7 KiB
React
100 lines
5.7 KiB
React
// 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 <div className="flex justify-center p-8"><Spinner /></div>
|
|
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 (
|
|
<div className="p-4 md:p-6 grid gap-4" data-testid="floor-plans">
|
|
<nav className="grid gap-2" aria-label={t('floor.title')}>
|
|
<p className="text-label text-ink-2 max-w-4xl">{t('floor.intro')}</p>
|
|
<div className="flex flex-wrap items-end gap-x-4 gap-y-2">
|
|
{byZone.map(z => (
|
|
<div key={z.id ?? 'none'} className="grid gap-1">
|
|
<span className="text-overline font-semibold text-ink-3 uppercase tracking-wide">{z.name}</span>
|
|
<div className="flex flex-wrap gap-1.5">
|
|
{z.plans.map(p => (
|
|
<button key={p.id} type="button" onClick={() => setChosen(p.id)} aria-current={plan?.id === p.id ? 'true' : undefined} data-testid="floor-plan-item" data-name={p.name}
|
|
className={cx('px-3 py-1.5 rounded-control border text-label font-medium transition-colors duration-fast text-left',
|
|
plan?.id === p.id ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface hover:bg-surface-2 text-ink')}>
|
|
{p.name}
|
|
<span className="ml-2 text-caption text-ink-3 font-normal">{t('floor.tableCount', { count: data.tables.filter(x => x.plan_id === p.id).length })}</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
</div>
|
|
))}
|
|
<Button size="sm" variant="secondary" icon={<Plus size={16} />} onClick={() => setCreating(true)} data-testid="floor-new">{t('floor.new')}</Button>
|
|
</div>
|
|
</nav>
|
|
<main className="min-w-0">
|
|
{plan ? (
|
|
<FloorEditor key={`${plan.id}:${version}`} plan={plan} data={data} groups={groups}
|
|
onSaved={async () => { await refetch(); setVersion(v => v + 1) }}
|
|
onDeleted={async () => { setChosen(null); await refetch(); setVersion(v => v + 1) }} />
|
|
) : <EmptyState title={t('floor.none')} description={t('floor.noneHint')} action={<Button icon={<Plus size={16} />} onClick={() => setCreating(true)}>{t('floor.new')}</Button>} />}
|
|
</main>
|
|
{creating && <NewPlan groups={groups} onClose={() => 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)) }
|
|
}} />}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
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 (
|
|
<Dialog open size="sm" title={t('floor.new')} onClose={onClose}
|
|
footer={<>
|
|
<Button variant="secondary" onClick={onClose}>{t('floor.cancel')}</Button>
|
|
<Button disabled={!name.trim()} data-testid="floor-create"
|
|
onClick={() => onCreate({ name: name.trim(), group_id: zone, width: SIZES[size][0], height: SIZES[size][1], grid_on: true, grid_size: 40 })}>{t('floor.create')}</Button>
|
|
</>}>
|
|
<div className="grid gap-3">
|
|
<Field label={t('floor.name')}><Input value={name} autoFocus maxLength={60} onChange={e => setName(e.target.value)} placeholder={t('floor.namePlaceholder')} data-testid="floor-new-name" /></Field>
|
|
<Field label={t('floor.zone')} hint={t('floor.zoneHint')}>
|
|
<Select value={zone ?? ''} onChange={e => setZone(e.target.value === '' ? null : Number(e.target.value))} data-testid="floor-new-zone"
|
|
options={[...groups.map(g => ({ value: g.id, label: g.name })), { value: '', label: t('floor.noZone') }]} />
|
|
</Field>
|
|
<Field label={t('floor.size')} hint={t('floor.sizeHint')}>
|
|
<Select value={size} onChange={e => 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] }) }))} />
|
|
</Field>
|
|
</div>
|
|
</Dialog>
|
|
)
|
|
}
|