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 } })} />
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user