feat(backend): KDS item claims across screens; zone screens only touch their own items (platform-v2 3.2c)
- order_items.claimed_by / claimed_at (Alembic 0015). POST/DELETE
/api/kds/orders/{id}/items/{item}/claim (kds.bump): someone else's claim is refused
(kds.item_claimed), letting go works for anyone with kds.bump; live kds_item_claimed.
In progress claims for whoever did it; done/served/pending/declined clear the claim.
- Fix: order-level status and decline from a zone screen changed every zone's items;
now only the screen's zone, and a zone screen sees the order status of its own items.
- Terminal: "I'm on it" / "Let go" on the selected card, the cook's name on claimed items.
- Tests: backend +6, terminal unit +1, terminal.mjs +6 with a second screen and cook.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
// connection (useKdsData). Sound needs one tap after the screen starts (browser rule).
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { CookingPot } from 'lucide-react'
|
||||
import { useAccess, useCan } from '@xenia/access'
|
||||
import { useLanguage, useTranslation } from '@xenia/i18n'
|
||||
import { useToast } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
@@ -27,7 +28,7 @@ import { SideRail, TopBar } from './components/Rails'
|
||||
import SettingsPanel from './components/SettingsPanel'
|
||||
import SummaryPanel from './components/SummaryPanel'
|
||||
import {
|
||||
ageLabel, ageOrderFor, ageState, bucketCounts, nextItemStatus, readyNotice, tabCounts, visibleOrders,
|
||||
ageLabel, ageOrderFor, ageState, bucketCounts, claimState, claimTargets, nextItemStatus, readyNotice, tabCounts, visibleOrders,
|
||||
withItemStatus, withOrderStatus,
|
||||
} from './logic/board'
|
||||
import { layoutBoard } from './logic/layout'
|
||||
@@ -42,6 +43,8 @@ export default function KdsApp() {
|
||||
const { t } = useTranslation('terminal')
|
||||
const { language } = useLanguage()
|
||||
const { me } = useDevice()
|
||||
const { user } = useAccess()
|
||||
const canClaim = useCan('kds.bump')
|
||||
const config = me?.config
|
||||
const [zoom, setZoom] = useState(null) // percent; null = the saved font_scale
|
||||
const settings = useMemo(() => boardSettings(config, zoom), [config, zoom])
|
||||
@@ -182,6 +185,20 @@ export default function KdsApp() {
|
||||
} catch { toast(t('kds.toast.declineFailed'), 'danger') }
|
||||
}, [reload, t, toast])
|
||||
|
||||
// "I'm on it" / let go, for every open item of the card nobody has (or that I hold)
|
||||
const claim = useCallback(async (orderId, action, items) => {
|
||||
const targets = claimTargets(items, user?.id, action)
|
||||
const results = await Promise.allSettled(targets.map(it => (action === 'take'
|
||||
? client.post(`/api/kds/orders/${orderId}/items/${it.id}/claim`)
|
||||
: client.delete(`/api/kds/orders/${orderId}/items/${it.id}/claim`))))
|
||||
const taken = results.find(r => r.status === 'rejected' && r.reason?.xenia?.code === 'kds.item_claimed')
|
||||
if (taken) toast(t('kds.claim.taken', { name: taken.reason.xenia.params?.name ?? '' }), 'warning')
|
||||
else if (results.some(r => r.status === 'rejected')) toast(t('kds.toast.sendFailed'), 'danger')
|
||||
else toast(action === 'take' ? t('kds.claim.taken_by_me') : t('kds.claim.released'))
|
||||
setFocusId(null)
|
||||
reload()
|
||||
}, [user?.id, reload, t, toast])
|
||||
|
||||
const print = useCallback(async orderId => {
|
||||
try {
|
||||
await client.post(`/api/kds/orders/${orderId}/retry-print`)
|
||||
@@ -313,6 +330,8 @@ export default function KdsApp() {
|
||||
settings={settings} multiFilter={filters.size > 1} courses={courses}
|
||||
onFocus={id => setFocusId(id === realId ? order.id : id)}
|
||||
onStatus={setOrderStatus} onBumpItem={bumpItem} onPrint={print} onCallWaiter={callWaiter}
|
||||
claimState={canClaim ? claimState(order.items, user?.id) : 'none'}
|
||||
onClaim={(orderId, action) => claim(orderId, action, order.items)}
|
||||
onDecline={orderId => setDialog({ decline: { orderId, itemId: null } })}
|
||||
onItemDecline={(orderId, itemId, itemName) => setDialog({ decline: { orderId, itemId, itemName } })} />
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// - ActionBar (the selected card): in progress / done (or back), print, and "Call waiter"
|
||||
// over the footer when the order has a waiter.
|
||||
// - QuickActionBar (long press on a card that isn't selected): prep, ready, decline, close.
|
||||
import { Ban, BellRing, Check, Flame, Printer, Undo2, X } from 'lucide-react'
|
||||
import { Ban, BellRing, Check, Flame, Hand, Printer, Undo2, X } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { CARD_FOOT_H_BASE, CARD_HEAD_H_BASE, CARD_SUB_H_BASE } from '../logic/layout'
|
||||
import { KDS, alpha } from '../theme'
|
||||
@@ -34,7 +34,7 @@ function BarButton({ bg, label, title, onClick, fs, children, testId }) {
|
||||
)
|
||||
}
|
||||
|
||||
export function ActionBar({ order, onStatus, onPrint, onCallWaiter, fs = 1, hasWaiter }) {
|
||||
export function ActionBar({ order, onStatus, onPrint, onCallWaiter, onClaim, claimState, fs = 1, hasWaiter }) {
|
||||
const { t } = useTranslation('terminal')
|
||||
const isDone = order.kds_status === 'done'
|
||||
const isPreparing = order.kds_status === 'preparing'
|
||||
@@ -50,6 +50,12 @@ export function ActionBar({ order, onStatus, onPrint, onCallWaiter, fs = 1, hasW
|
||||
bg={isDone ? KDS.done : KDS.freshDeep} onClick={() => onStatus(order.id, isDone ? 'pending' : 'done')}>
|
||||
{isDone ? <Undo2 style={icon} /> : <Check style={icon} />}
|
||||
</BarButton>
|
||||
{claimState !== 'none' && (
|
||||
<BarButton fs={fs} testId="card-claim" title={claimState === 'mine' ? t('kds.claim.release') : t('kds.claim.take')}
|
||||
bg={claimState === 'mine' ? KDS.done : KDS.progress} onClick={() => onClaim(order.id, claimState === 'mine' ? 'release' : 'take')}>
|
||||
{claimState === 'mine' ? <Undo2 style={icon} /> : <Hand style={icon} />}
|
||||
</BarButton>
|
||||
)}
|
||||
<BarButton fs={fs} testId="card-print" title={t('kds.actions.print')} bg={alpha('on-status', 0.12)} onClick={() => onPrint(order.id)}>
|
||||
<Printer style={icon} />
|
||||
</BarButton>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// One item on an order card: quantity badge, name, changes (− removed, + extras, → choices)
|
||||
// and its note. On the selected card a tap moves it on, a long press declines it.
|
||||
import { useRef } from 'react'
|
||||
import { ArrowRight, Info, Minus, Plus } from 'lucide-react'
|
||||
import { ArrowRight, Hand, Info, Minus, Plus } from 'lucide-react'
|
||||
import { dedupeModifiers, formatQty, hasUnit } from '../logic/board'
|
||||
import { KDS } from '../theme'
|
||||
|
||||
@@ -68,6 +68,17 @@ export default function ItemBlock({ item, focused, onBump, onDecline, fontScale
|
||||
}}>
|
||||
{item.product_name}
|
||||
</span>
|
||||
{item.claimed_by_name && !done && (
|
||||
<span data-testid="item-claim" title={item.claimed_by_name} style={{
|
||||
flexShrink: 0, maxWidth: '45%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
||||
height: badgeH, display: 'inline-flex', alignItems: 'center', gap: 3, padding: `0 ${Math.round(6 * fs)}px`,
|
||||
borderRadius: Math.round(5 * fs), background: KDS.progress, color: KDS.onStatus,
|
||||
fontSize: Math.round(11 * fs), fontWeight: 700,
|
||||
}}>
|
||||
<Hand style={{ width: Math.round(11 * fs), height: Math.round(11 * fs), flexShrink: 0 }} />
|
||||
{item.claimed_by_name}
|
||||
</span>
|
||||
)}
|
||||
{focused && (
|
||||
<span style={{
|
||||
flexShrink: 0, width: 8, height: 8, borderRadius: 4, display: 'inline-block', marginTop: Math.round((badgeH - 8) / 2),
|
||||
|
||||
@@ -45,7 +45,7 @@ function glowFor(order, age) {
|
||||
}
|
||||
|
||||
export default function OrderCard({ order, age, ageText, layout, focused, dimmed, settings, multiFilter, courses, now,
|
||||
onFocus, onStatus, onBumpItem, onPrint, onDecline, onItemDecline, onCallWaiter }) {
|
||||
onFocus, onStatus, onBumpItem, onPrint, onDecline, onItemDecline, onCallWaiter, onClaim, claimState }) {
|
||||
const { t } = useTranslation('terminal')
|
||||
const fs = settings.fontScale
|
||||
const [headBg, subBg] = headColours(age.age, settings.colours)
|
||||
@@ -207,7 +207,7 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed
|
||||
<QuickActionBar order={order} onStatus={onStatus} onDecline={onDecline} onDismiss={() => setQuick(false)} fs={fs} />
|
||||
)}
|
||||
{focused && (
|
||||
<ActionBar order={order} onStatus={onStatus} onPrint={onPrint} onCallWaiter={onCallWaiter} fs={fs} hasWaiter={!!waiter} />
|
||||
<ActionBar order={order} onStatus={onStatus} onPrint={onPrint} onCallWaiter={onCallWaiter} onClaim={onClaim} claimState={claimState} fs={fs} hasWaiter={!!waiter} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -222,3 +222,21 @@ export function readyNotice(order, itemId, settings) {
|
||||
if (done === active.length) return settings.notifyOrderComplete ? { kind: 'order' } : null
|
||||
return settings.notifyItemComplete ? { kind: 'items', ready_count: done, total_count: active.length } : null
|
||||
}
|
||||
|
||||
// ── claims (3.2c): who is on which item ─────────────────────────────────────
|
||||
|
||||
const isOpen = it => it.status !== 'cancelled' && !['done', 'served', 'declined'].includes(it.kds_status)
|
||||
|
||||
/** What the card's claim button does for `userId`: 'take' (some open items are nobody's),
|
||||
* 'mine' (I hold some and nothing is left to take: let go), or 'none'. */
|
||||
export function claimState(items, userId) {
|
||||
const open = items.filter(isOpen)
|
||||
if (!open.length || userId == null) return 'none'
|
||||
if (open.some(it => it.claimed_by == null)) return 'take'
|
||||
return open.some(it => it.claimed_by === userId) ? 'mine' : 'none'
|
||||
}
|
||||
|
||||
/** The items a take / release touches: nobody's open items, or my open ones. */
|
||||
export function claimTargets(items, userId, action) {
|
||||
return items.filter(isOpen).filter(it => (action === 'take' ? it.claimed_by == null : it.claimed_by === userId))
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import client from '../../api/client'
|
||||
import { useDevice, useLiveEvent, useLiveEvents } from '../../device/context'
|
||||
|
||||
export const ORDER_EVENTS = ['kds_order_updated', 'kds_item_updated', 'order_updated', 'order_paid', 'order_closed', 'products_changed']
|
||||
export const ORDER_EVENTS = ['kds_order_updated', 'kds_item_updated', 'order_updated', 'order_paid', 'order_closed', 'products_changed', 'kds_item_claimed']
|
||||
const COALESCE_MS = 150
|
||||
const quiet = { xenia: { noOverride: true } }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user