// The counter POS screen (plan steps 3.3a–c). Two modes, switched at the top left: // - Sale: categories on the left, the product grid with a search, the quick-sale cart on the // right (SaleCart: Charge → payment, 3.3b). // - Tables: the zones on the left and the table list (TablesView); a table opens with the // product grid again and the table's order on the right (TablePanel). // A tap adds a product (or opens its choices when it has preferences to pick); the (i) button // checks its price without adding it. Every price is the backend's. import { useMemo, useState } from 'react' import { Info, LayoutGrid, Search, ShoppingBag, X } from 'lucide-react' import { useFormat, useLanguage, useTranslation } from '@xenia/i18n' import { useCan } from '@xenia/access' import { EmptyState, IconButton, Input, Spinner } from '@xenia/ui' import { addLine, categoriesWithProducts, defaultSelection, needsChoices, productsIn, searchProducts, toLine, unitOf } from './logic/cart' import { zoneCounts } from './logic/tables' import ProductDialog from './ProductDialog' import SaleCart from './SaleCart' import TablePanel from './TablePanel' import TablesView from './TablesView' import { useMenu, useTables } from './usePos' export default function PosScreen() { const { t } = useTranslation('terminal') const { menu } = useMenu() if (!menu) return
return } function Counter({ menu, t }) { const { language } = useLanguage() const [mode, setMode] = useState('sale') // sale | tables const [tableId, setTableId] = useState(null) // the open table (tables mode) const [zone, setZone] = useState(null) const [category, setCategory] = useState(() => menu.settings.start_category_id ?? null) const [query, setQuery] = useState('') const [orderType, setOrderType] = useState(menu.settings.default_order_type) const [saleCart, setSaleCart] = useState([]) const [tableCart, setTableCart] = useState([]) const [dialog, setDialog] = useState(null) // product const tables = useTables() const canDiscount = useCan('ordering.prices.modify') // a table that left the cashier's list (zone changed) shows the list again const table = tableId != null ? tables.data?.tables.find(x => x.id === tableId) ?? null : null const atTable = mode === 'tables' && table != null const picking = mode === 'tables' && !atTable const setCart = atTable ? setTableCart : setSaleCart const leaveTable = () => { setTableId(null); setTableCart([]) } const byId = useMemo(() => new Map(menu.products.map(p => [p.id, p])), [menu.products]) const categories = useMemo(() => categoriesWithProducts(menu.categories, menu.products), [menu]) const shown = useMemo(() => (query.trim() ? searchProducts(menu.products, query) : productsIn(menu.products, category)), [menu.products, query, category]) const counts = useMemo(() => zoneCounts(tables.data?.tables ?? []), [tables.data]) const tap = product => { if (needsChoices(product)) { setDialog(product); return } const unit = unitOf(product) setCart(c => addLine(c, toLine(product, defaultSelection(product), unit ? unit.start : 1))) } return (
{picking ? (
{ setTableId(id); setTableCart([]) }} />
) : ( <>
setQuery(e.target.value)} placeholder={t('pos.search')} className="pl-10" data-testid="pos-search" aria-label={t('pos.search')} />
{query && setQuery('')}>}
{shown.length === 0 ? ( ) : (
{shown.map(p => tap(p)} onInfo={() => setDialog(p)} />)}
)}
{atTable ? : } )} {dialog && ( setDialog(null)} onAdd={line => setCart(c => addLine(c, line))} /> )}
) } function ModeButton({ active, onClick, icon: Icon, badge, children, testId }) { return ( ) } function NavButton({ active, colour, onClick, children, testId, count }) { return ( ) } function ProductCard({ product, onTap, onInfo }) { const { t } = useTranslation('terminal') const { formatMoney } = useFormat() const unit = unitOf(product) return (
) }