feat(waiter): what a waiter may do comes from permission keys (platform-v2 step 4.3)
- Payments: ordering.orders.close checked on pay/close and the counter POS
(waiters have it by default, owner decision); pay-offline always recorded.
- The venue switches waiter_cancellations / price_adjust / revert are gone:
ordering.orders.cancel, ordering.prices.modify and the new
ordering.payments.revert (overridable) decide; moves/split/transfer/merge
need ordering.orders.open; discounts pricing.discounts.apply; chat chat.use.
- Venue role defaults: role_permissions (Alembic 0024), role_template(role, db),
GET/PUT /api/waiters/roles/{role}/permissions applying the change to everyone
with the role; manager Settings -> Operation -> "What each role may do".
0024 also grants the new key to existing owners and store managers.
- Bootstrap `approvable`; @xenia/access useAllowed(key) -> yes/approve/no.
The waiter shows each action by key, "with a manager's approval (PIN)" where
allowed; GET /api/orders/cancel-permissions removed.
- Tests: test_waiter_keys.py (11), access allowed(), waiter.mjs +5, manager.mjs +3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useState, useRef } from 'react'
|
||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'
|
||||
import { useAllowed, useCan } from '@xenia/access'
|
||||
import OrderSummary from '../components/OrderSummary'
|
||||
import useConnectionStore from '../store/connectionStore'
|
||||
import client from '../api/client'
|
||||
@@ -242,7 +243,7 @@ function PriceAdjustModal({ item, onConfirm, onClose }) {
|
||||
|
||||
// ─── Item action modal (long-press) ──────────────────────────────────────────
|
||||
|
||||
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, canCancel, priceAdjAllowed, onAdjustPrice, onClose }) {
|
||||
function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCancel, canCancel, cancelNeedsApproval, priceAdjAllowed, priceNeedsApproval, canMove, onAdjustPrice, onClose }) {
|
||||
const { items, singleStacked, multiSelect } = target
|
||||
const label = multiSelect
|
||||
? `${items.length} αντικείμενα επιλεγμένα`
|
||||
@@ -254,7 +255,7 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
|
||||
color: '#f59e0b',
|
||||
iconBg: 'rgba(245,158,11,0.15)',
|
||||
label: 'Ρύθμιση τιμής',
|
||||
sub: 'Αλλαγή τιμής για αυτό το αντικείμενο',
|
||||
sub: priceNeedsApproval ? 'Με έγκριση διαχειριστή (PIN)' : 'Αλλαγή τιμής για αυτό το αντικείμενο',
|
||||
icon: (
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="9" stroke="#f59e0b" strokeWidth="2"/>
|
||||
@@ -279,7 +280,7 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
|
||||
onClick: onOrderAgain,
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
...(canMove ? [{
|
||||
key: 'move',
|
||||
color: '#f97316',
|
||||
iconBg: 'rgba(249,115,22,0.15)',
|
||||
@@ -292,8 +293,8 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
|
||||
),
|
||||
onClick: onMoveToTable,
|
||||
enabled: true,
|
||||
},
|
||||
...(singleStacked && !multiSelect ? [{
|
||||
}] : []),
|
||||
...(canMove && singleStacked && !multiSelect ? [{
|
||||
key: 'split',
|
||||
color: '#60a5fa',
|
||||
iconBg: 'rgba(96,165,250,0.15)',
|
||||
@@ -312,7 +313,7 @@ function ItemActionModal({ target, onOrderAgain, onSplit, onMoveToTable, onCance
|
||||
color: canCancel ? '#ef4444' : '#6b7280',
|
||||
iconBg: canCancel ? 'rgba(239,68,68,0.15)' : 'rgba(107,114,128,0.1)',
|
||||
label: 'Ακύρωση παραγγελίας',
|
||||
sub: canCancel ? 'Ακύρωση επιλεγμένων αντικειμένων' : 'Δεν επιτρέπεται η ακύρωση',
|
||||
sub: !canCancel ? 'Δεν επιτρέπεται η ακύρωση' : cancelNeedsApproval ? 'Με έγκριση διαχειριστή (PIN)' : 'Ακύρωση επιλεγμένων αντικειμένων',
|
||||
icon: (
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="10" stroke={canCancel ? '#ef4444' : '#6b7280'} strokeWidth="2"/>
|
||||
@@ -547,7 +548,7 @@ function DiscountIcon({ width = 20, height = 20 }) {
|
||||
)
|
||||
}
|
||||
|
||||
function ActionsSheet({ order, _tableId, isStandalone, onClose, onTransfer, onMerge, onSetFlags, onAssignWaiter, onPrintSynopsis, onCancelOrder, onMarkAllServed, canCancel, canDiscount, onApplyDiscount }) {
|
||||
function ActionsSheet({ order, _tableId, isStandalone, onClose, onTransfer, onMerge, onSetFlags, onAssignWaiter, onPrintSynopsis, onCancelOrder, onMarkAllServed, canCancel, cancelNeedsApproval, canDiscount, canMove, onApplyDiscount }) {
|
||||
const hasOrder = !!order
|
||||
const hasServable = hasOrder && order.items?.some(i => i.kds_status === 'done')
|
||||
const hasActiveItems = hasOrder && order.items?.some(i => i.status === 'active')
|
||||
@@ -556,15 +557,19 @@ function ActionsSheet({ order, _tableId, isStandalone, onClose, onTransfer, onMe
|
||||
onClick: hasServable ? onMarkAllServed : null, color: hasServable ? '#4ade80' : '#6b7280', iconBg: hasServable ? 'rgba(34,197,94,0.15)' : 'rgba(107,114,128,0.1)' },
|
||||
{ Icon: DiscountIcon, label: 'Εφαρμογή Έκπτωσης', sub: canDiscount ? 'Έκπτωση σε αντικείμενα παραγγελίας' : 'Δεν επιτρέπεται η εφαρμογή έκπτωσης',
|
||||
onClick: (hasActiveItems && canDiscount) ? onApplyDiscount : null, color: (hasActiveItems && canDiscount) ? '#a78bfa' : '#6b7280', iconBg: (hasActiveItems && canDiscount) ? 'rgba(167,139,250,0.15)' : 'rgba(107,114,128,0.1)' },
|
||||
{ Icon: TransferIcon, label: 'Μεταφορά Τραπεζιού', sub: 'Μεταφορά σε άλλο τραπέζι', onClick: hasOrder ? onTransfer : null, color: '#6099db', iconBg: 'rgba(96,165,250,0.15)', tableOnly: true },
|
||||
{ Icon: MergeIcon, label: 'Συγχώνευση Τραπεζιού', sub: 'Συγχώνευση με άλλο τραπέζι', onClick: hasOrder ? onMerge : null, color: '#6099db', iconBg: 'rgba(96,165,250,0.15)', tableOnly: true },
|
||||
{ Icon: TransferIcon, label: 'Μεταφορά Τραπεζιού', sub: 'Μεταφορά σε άλλο τραπέζι', onClick: hasOrder ? onTransfer : null, color: '#6099db', iconBg: 'rgba(96,165,250,0.15)', tableOnly: true, needsMove: true },
|
||||
{ Icon: MergeIcon, label: 'Συγχώνευση Τραπεζιού', sub: 'Συγχώνευση με άλλο τραπέζι', onClick: hasOrder ? onMerge : null, color: '#6099db', iconBg: 'rgba(96,165,250,0.15)', tableOnly: true, needsMove: true },
|
||||
{ Icon: FlagsIcon, label: 'Ενδείξεις Τραπεζιού', sub: 'Επιλογή σημαιών', onClick: onSetFlags, color: '#fac823', iconBg: 'rgba(251,191,36,0.15)', tableOnly: true },
|
||||
{ Icon: WaiterIcon, label: 'Ανάθεση Σερβιτόρου', sub: 'Προσθήκη σερβιτόρου στην παραγγελία', onClick: hasOrder ? onAssignWaiter : null, color: '#39b861', iconBg: 'rgba(34,197,94,0.15)' },
|
||||
{ Icon: PrintIcon, label: 'Εκτύπωση Σύνοψης', sub: 'Εκτύπωση σύνοψης παραγγελίας', onClick: hasOrder ? onPrintSynopsis : null, color: '#cbd5e1', iconBg: 'rgba(148,163,184,0.15)' },
|
||||
{ Icon: CancelIcon, label: 'Ακύρωση Παραγγελίας', sub: canCancel ? 'Ακύρωση ολόκληρης παραγγελίας' : 'Δεν επιτρέπεται η ακύρωση',
|
||||
{ Icon: CancelIcon, label: 'Ακύρωση Παραγγελίας', sub: !canCancel ? 'Δεν επιτρέπεται η ακύρωση' : cancelNeedsApproval ? 'Με έγκριση διαχειριστή (PIN)' : 'Ακύρωση ολόκληρης παραγγελίας',
|
||||
onClick: (hasOrder && canCancel) ? onCancelOrder : null, color: (hasOrder && canCancel) ? '#ef4444' : '#6b7280', iconBg: (hasOrder && canCancel) ? 'rgba(239,68,68,0.15)' : 'rgba(107,114,128,0.1)' },
|
||||
]
|
||||
const actions = isStandalone ? allActions.filter(a => !a.tableOnly) : allActions
|
||||
// plan 4.3: discounts show only with pricing.discounts.apply, transfer/merge with ordering.orders.open
|
||||
const actions = allActions
|
||||
.filter(a => !(isStandalone && a.tableOnly))
|
||||
.filter(a => !(a.needsMove && !canMove))
|
||||
.filter(a => !(a.Icon === DiscountIcon && !canDiscount))
|
||||
|
||||
return (
|
||||
<div className="modal-overlay modal-overlay--top" onClick={onClose}>
|
||||
@@ -1050,8 +1055,17 @@ export default function TableDetailPage() {
|
||||
const [confirmPayAndClose, setConfirmPayAndClose] = useState(false)
|
||||
const [revertConfirm, setRevertConfirm] = useState(null) // null | { itemIds: [...] }
|
||||
const [cardEnabled, setCardEnabled] = useState(false)
|
||||
const [revertAllowed, setRevertAllowed] = useState(false)
|
||||
const [priceAdjAllowed, setPriceAdjAllowed] = useState(false)
|
||||
// What this waiter may do comes from permission keys (plan step 4.3): 'yes', 'approve' (a
|
||||
// manager's PIN on the phone, the approval dialog opens by itself) or 'no'
|
||||
const cancelAccess = useAllowed('ordering.orders.cancel')
|
||||
const revertAccess = useAllowed('ordering.payments.revert')
|
||||
const priceAccess = useAllowed('ordering.prices.modify')
|
||||
const canCancel = cancelAccess !== 'no'
|
||||
const revertAllowed = revertAccess !== 'no'
|
||||
const priceAdjAllowed = priceAccess !== 'no'
|
||||
const canDiscount = useCan('pricing.discounts.apply')
|
||||
const canPay = useCan('ordering.orders.close')
|
||||
const canMove = useCan('ordering.orders.open')
|
||||
const [error, setError] = useState('')
|
||||
|
||||
// Tab: 'active' | 'paid'
|
||||
@@ -1076,8 +1090,6 @@ export default function TableDetailPage() {
|
||||
const [priceAdjustItem, setPriceAdjustItem] = useState(null) // item being price-adjusted
|
||||
const [customerCount, setCustomerCount] = useState(null)
|
||||
const [customerCountOpen, setCustomerCountOpen] = useState(false)
|
||||
const [canCancel, setCanCancel] = useState(false)
|
||||
const [canDiscount, setCanDiscount] = useState(false)
|
||||
const [showDiscountModal, setShowDiscountModal] = useState(false)
|
||||
const [priceEventsMap, setPriceEventsMap] = useState({})
|
||||
const [cancelConfirm, setCancelConfirm] = useState(null) // null | { mode: 'items', ids: [...] } | { mode: 'order' }
|
||||
@@ -1220,18 +1232,8 @@ export default function TableDetailPage() {
|
||||
}, [order?.id, tableId])
|
||||
|
||||
useEffect(() => {
|
||||
client.get('/api/orders/cancel-permissions')
|
||||
.then(r => setCanCancel(!!r.data.can_cancel))
|
||||
.catch(() => {})
|
||||
client.get('/api/pricing/discount-settings/me')
|
||||
.then(r => setCanDiscount(!!r.data.can_apply_discounts))
|
||||
.catch(() => {})
|
||||
getVenueSettings()
|
||||
.then(r => {
|
||||
setCardEnabled(r.data?.['payments.card_enabled']?.value === 'true')
|
||||
setRevertAllowed(r.data?.['payments.waiter_revert_allowed']?.value === 'true')
|
||||
setPriceAdjAllowed(r.data?.['orders.waiter_price_adjust_allowed']?.value === 'true')
|
||||
})
|
||||
.then(r => setCardEnabled(r.data?.['payments.card_enabled']?.value === 'true'))
|
||||
.catch(() => {})
|
||||
}, [])
|
||||
|
||||
@@ -1994,8 +1996,10 @@ export default function TableDetailPage() {
|
||||
<span style={{ marginRight: 6 }}>+</span>ADD
|
||||
</button>
|
||||
|
||||
{canPay && (
|
||||
<button
|
||||
className="btn btn--success"
|
||||
data-testid="pay-button"
|
||||
onClick={() => setConfirmPay(true)}
|
||||
disabled={paying}
|
||||
style={{ borderRadius: 999, flex: 1, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 6 }}
|
||||
@@ -2013,7 +2017,9 @@ export default function TableDetailPage() {
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{canPay && (
|
||||
<button
|
||||
className="btn btn--danger"
|
||||
onClick={() => {
|
||||
@@ -2027,6 +2033,7 @@ export default function TableDetailPage() {
|
||||
>
|
||||
<span style={{ marginRight: 6 }}>✕</span>CLOSE
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -2086,7 +2093,10 @@ export default function TableDetailPage() {
|
||||
<ItemActionModal
|
||||
target={itemActionTarget}
|
||||
canCancel={canCancel && !isOffline}
|
||||
priceAdjAllowed={priceAdjAllowed}
|
||||
cancelNeedsApproval={cancelAccess === 'approve'}
|
||||
priceAdjAllowed={priceAdjAllowed && !isOffline}
|
||||
priceNeedsApproval={priceAccess === 'approve'}
|
||||
canMove={canMove}
|
||||
onOrderAgain={() => {
|
||||
const items = itemActionTarget.items
|
||||
sessionStorage.setItem('orderAgainItems', JSON.stringify(
|
||||
@@ -2263,7 +2273,9 @@ export default function TableDetailPage() {
|
||||
tableId={tableId}
|
||||
isStandalone={isStandalone}
|
||||
canCancel={canCancel}
|
||||
cancelNeedsApproval={cancelAccess === 'approve'}
|
||||
canDiscount={canDiscount}
|
||||
canMove={canMove}
|
||||
onClose={() => setShowActions(false)}
|
||||
onTransfer={() => { setShowActions(false); setActionsMode('transfer') }}
|
||||
onMerge={() => { setShowActions(false); setActionsMode('merge') }}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useRef, useState, useCallback } from 'react'
|
||||
import { useAllowed } from '@xenia/access'
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom'
|
||||
import TableCard from '../components/TableCard'
|
||||
import useAuthStore from '../store/authStore'
|
||||
@@ -310,7 +311,8 @@ export default function TableListPage() {
|
||||
const [, setOffline] = useState(false)
|
||||
const [showFilters, setShowFilters] = useState(false)
|
||||
const [quickModal, setQuickModal] = useState(null)
|
||||
const [canCancel, setCanCancel] = useState(false)
|
||||
// plan 4.3: the key, or a manager's PIN when a manager may approve it
|
||||
const canCancel = useAllowed('ordering.orders.cancel') !== 'no'
|
||||
const [cancelConfirm, setCancelConfirm] = useState(null)
|
||||
// Orders tab filters
|
||||
const [ordersFilter, setOrdersFilter] = useState('all') // status: 'all'|'pending'|'preparing'|'ready'
|
||||
@@ -443,10 +445,6 @@ export default function TableListPage() {
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
client.get('/api/orders/cancel-permissions').then(r => setCanCancel(r.data?.can_cancel === true)).catch(() => {})
|
||||
}, [])
|
||||
|
||||
async function executeCancelOrder(orderId) {
|
||||
try {
|
||||
await client.delete(`/api/orders/${orderId}?print_cancellation=true`)
|
||||
|
||||
Reference in New Issue
Block a user