- 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>
111 lines
5.8 KiB
React
111 lines
5.8 KiB
React
// 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, Hand, Info, Minus, Plus } from 'lucide-react'
|
||
import { dedupeModifiers, formatQty, hasUnit } from '../logic/board'
|
||
import { KDS } from '../theme'
|
||
|
||
const MOD_ICON_SZ = 13
|
||
const HOLD_MS = 500
|
||
|
||
export function ModRow({ Icon, color, text, done, fs }) {
|
||
const col = done ? KDS.cardMuted : color
|
||
const fontSize = Math.round(12 * fs)
|
||
const lineH = Math.round(fontSize * 1.4)
|
||
const iconSz = Math.round(MOD_ICON_SZ * fs)
|
||
return (
|
||
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 4, color: col, fontSize, fontWeight: 600, textDecoration: done ? 'line-through' : 'none' }}>
|
||
{/* one line tall, so the icon sits on the first line when the text wraps */}
|
||
<span style={{ flexShrink: 0, width: iconSz, height: lineH, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}>
|
||
<Icon style={{ width: iconSz, height: iconSz, color: col }} />
|
||
</span>
|
||
<span style={{ lineHeight: `${lineH}px` }}>{text}</span>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
export default function ItemBlock({ item, focused, onBump, onDecline, fontScale = 1, fontWeight = 600, combineModifiers }) {
|
||
const status = item.kds_status
|
||
const done = status === 'done' || status === 'served'
|
||
const preparing = status === 'preparing'
|
||
const fs = fontScale
|
||
const removed = dedupeModifiers(item.removed ?? [])
|
||
const extras = dedupeModifiers(item.extras ?? [])
|
||
const prefs = dedupeModifiers(item.prefs ?? [])
|
||
const hasMods = removed.length || extras.length || prefs.length || item.notes
|
||
const nameFontSize = Math.round(15 * fs)
|
||
const nameLineH = Math.round(nameFontSize * 1.4)
|
||
const badgeH = nameLineH
|
||
|
||
const hold = useRef(null)
|
||
const cancelHold = () => { if (hold.current) { clearTimeout(hold.current); hold.current = null } }
|
||
const onPointerDown = focused && onDecline ? e => {
|
||
e.stopPropagation()
|
||
hold.current = setTimeout(() => { hold.current = null; onDecline(item) }, HOLD_MS)
|
||
} : undefined
|
||
|
||
return (
|
||
<div
|
||
data-item={item.id} data-status={status}
|
||
onClick={focused ? e => { e.stopPropagation(); cancelHold(); onBump?.(item) } : undefined}
|
||
onPointerDown={onPointerDown} onPointerUp={cancelHold} onPointerLeave={cancelHold} onPointerCancel={cancelHold}
|
||
style={{ borderRadius: 7, margin: '0 -5px', padding: '2px 5px', cursor: focused ? 'pointer' : 'default',
|
||
transition: 'background .1s', opacity: done ? 0.55 : 1, touchAction: 'none' }}
|
||
>
|
||
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 7 }}>
|
||
<span style={{
|
||
flexShrink: 0, minWidth: badgeH, height: badgeH,
|
||
paddingLeft: hasUnit(item.unit_type) ? Math.round(4 * fs) : 0, paddingRight: hasUnit(item.unit_type) ? Math.round(4 * fs) : 0,
|
||
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||
background: KDS.cardSoft, color: done ? KDS.cardMuted : KDS.cardInk,
|
||
borderRadius: Math.round(5 * fs), fontFamily: KDS.fontMono, fontWeight: 700, fontSize: Math.round(12 * fs), lineHeight: 1,
|
||
}}>
|
||
{formatQty(item.quantity, item.unit_type)}
|
||
</span>
|
||
<span style={{
|
||
color: done ? KDS.cardMuted : KDS.cardInk, fontSize: nameFontSize, fontWeight, lineHeight: `${nameLineH}px`,
|
||
textDecoration: done ? 'line-through' : 'none', textDecorationThickness: 2, flex: '1 1 auto', minWidth: 0,
|
||
}}>
|
||
{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),
|
||
background: done ? KDS.fresh : preparing ? KDS.progress : KDS.cardSoft,
|
||
border: `1px solid ${done ? KDS.freshDeep : preparing ? KDS.progress : KDS.cardMuted}`,
|
||
}} />
|
||
)}
|
||
</div>
|
||
{hasMods ? (
|
||
<div style={{ marginTop: 3, paddingLeft: badgeH + 7, display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||
{combineModifiers ? (
|
||
<>
|
||
{removed.length > 0 && <ModRow Icon={Minus} color={KDS.lateDeep} text={removed.join(' · ')} done={done} fs={fs} />}
|
||
{extras.length > 0 && <ModRow Icon={Plus} color={KDS.freshDeep} text={extras.join(' · ')} done={done} fs={fs} />}
|
||
{prefs.length > 0 && <ModRow Icon={ArrowRight} color={KDS.warningDeep} text={prefs.join(' · ')} done={done} fs={fs} />}
|
||
</>
|
||
) : (
|
||
<>
|
||
{removed.map((r, i) => <ModRow key={`r${i}`} Icon={Minus} color={KDS.lateDeep} text={r} done={done} fs={fs} />)}
|
||
{extras.map((x, i) => <ModRow key={`e${i}`} Icon={Plus} color={KDS.freshDeep} text={x} done={done} fs={fs} />)}
|
||
{prefs.map((p, i) => <ModRow key={`p${i}`} Icon={ArrowRight} color={KDS.warningDeep} text={p} done={done} fs={fs} />)}
|
||
</>
|
||
)}
|
||
{item.notes && <ModRow Icon={Info} color={KDS.progress} text={item.notes} done={done} fs={fs} />}
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
)
|
||
}
|