feat: bump client-services (accumulated feature work + deploy fixes)
Snapshot of in-progress work across local_backend, manager_dashboard, and waiter_pwa (pricing, chat, fiscal, prep zones, recovery codes, CRM, inventory, permissions), plus the nginx/docker-compose deploy fixes for the Unraid + NPM reverse-proxy setup. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,663 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import UserMenu from './UserMenu'
|
||||
import { useNotifications } from '../context/NotificationContext'
|
||||
import useNotificationSettingsStore from '../store/notificationSettingsStore'
|
||||
import useTableViewStore from '../store/tableViewStore'
|
||||
import useChatStore from '../store/chatStore'
|
||||
import useKdsReadyStore from '../store/kdsReadyStore'
|
||||
import useOfflineQueueCount from '../hooks/useOfflineQueueCount'
|
||||
import useFailedPrintCount from '../hooks/useFailedPrintCount'
|
||||
|
||||
// ─── Nav item registry ────────────────────────────────────────────────────────
|
||||
|
||||
const NAV_REGISTRY = {
|
||||
tables: {
|
||||
key: 'tables',
|
||||
label: 'Τραπέζια',
|
||||
shortLabel: 'Τραπέζια',
|
||||
href: '/tables?tab=tables',
|
||||
match: (loc) => loc.pathname === '/tables' && loc.search !== '?tab=orders',
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<rect x="3" y="3" width="7" height="7" rx="1.5" fill="currentColor"/>
|
||||
<rect x="14" y="3" width="7" height="7" rx="1.5" fill="currentColor"/>
|
||||
<rect x="3" y="14" width="7" height="7" rx="1.5" fill="currentColor"/>
|
||||
<rect x="14" y="14" width="7" height="7" rx="1.5" fill="currentColor"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
orders: {
|
||||
key: 'orders',
|
||||
label: 'Ενεργές Παραγγελίες',
|
||||
shortLabel: 'Παραγγελίες',
|
||||
href: '/tables?tab=orders',
|
||||
match: (loc) => loc.pathname === '/tables' && loc.search === '?tab=orders',
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
|
||||
<path d="M9 12h6M9 16h4" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
messages: {
|
||||
key: 'messages',
|
||||
label: 'Μηνύματα',
|
||||
shortLabel: 'Μηνύματα',
|
||||
href: '/messages',
|
||||
match: (loc) => loc.pathname === '/messages',
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
standalone: {
|
||||
key: 'standalone',
|
||||
label: 'Takeaway',
|
||||
shortLabel: 'Takeaway',
|
||||
href: '/tables',
|
||||
match: () => false,
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M5 12H3l9-9 9 9h-2" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<path d="M10 22v-6h4v6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
'shift-overview': {
|
||||
key: 'shift-overview',
|
||||
label: 'Βάρδια',
|
||||
shortLabel: 'Βάρδια',
|
||||
href: '/shift-overview',
|
||||
match: (loc) => loc.pathname === '/shift-overview',
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="2"/>
|
||||
<path d="M12 7v5l3 3" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
'order-log': {
|
||||
key: 'order-log',
|
||||
label: 'Αρχείο',
|
||||
shortLabel: 'Αρχείο',
|
||||
href: '/order-log',
|
||||
match: (loc) => loc.pathname === '/order-log',
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M6 9V2h12v7" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<rect x="6" y="14" width="12" height="8" rx="1" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
const DRAWER_ITEMS = [
|
||||
{ ...NAV_REGISTRY.tables },
|
||||
{ ...NAV_REGISTRY.orders },
|
||||
{ ...NAV_REGISTRY.messages },
|
||||
]
|
||||
|
||||
// ─── Cache badge (cloud upload) ───────────────────────────────────────────────
|
||||
|
||||
function CacheButton({ count }) {
|
||||
if (!count) return null
|
||||
return (
|
||||
<div style={{
|
||||
position: 'relative',
|
||||
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||||
minWidth: 44, minHeight: 44, borderRadius: 8,
|
||||
color: '#f59e0b',
|
||||
}}>
|
||||
{/* Cloud upload icon */}
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M12 16V10M12 10L9 13M12 10L15 13" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<path d="M6.5 18a4.5 4.5 0 0 1-.5-8.965A6 6 0 0 1 17.5 11h.5a3.5 3.5 0 0 1 .5 6.965" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
<span style={{
|
||||
position: 'absolute', top: 6, right: 6,
|
||||
background: '#f59e0b', color: 'white', fontSize: 10, fontWeight: 700,
|
||||
borderRadius: '50%', width: 16, height: 16,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}>
|
||||
{count > 9 ? '9+' : count}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Failed print badge ───────────────────────────────────────────────────────
|
||||
|
||||
function FailedPrintButton({ count, onClick }) {
|
||||
if (!count) return null
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
style={{
|
||||
position: 'relative',
|
||||
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||||
minWidth: 44, minHeight: 44, borderRadius: 8,
|
||||
background: 'none', border: 'none', cursor: 'pointer',
|
||||
color: '#ef4444',
|
||||
}}
|
||||
>
|
||||
{/* Printer icon */}
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M6 9V2h12v7" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<rect x="6" y="14" width="12" height="8" rx="1" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
<span style={{
|
||||
position: 'absolute', top: 6, right: 6,
|
||||
background: '#ef4444', color: 'white', fontSize: 10, fontWeight: 700,
|
||||
borderRadius: '50%', width: 16, height: 16,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}>
|
||||
{count > 9 ? '9+' : count}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Bell button ──────────────────────────────────────────────────────────────
|
||||
|
||||
function BellButton({ onClick, count }) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
style={{
|
||||
position: 'relative', background: 'none', border: 'none',
|
||||
color: 'var(--text)', cursor: 'pointer',
|
||||
minWidth: 44, minHeight: 44, borderRadius: 8,
|
||||
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M19.3399 14.49L18.3399 12.83C18.1299 12.46 17.9399 11.76 17.9399 11.35V8.82C17.9399 6.47 16.5599 4.44 14.5699 3.49C14.0499 2.57 13.0899 2 11.9899 2C10.8999 2 9.91994 2.59 9.39994 3.52C7.44994 4.49 6.09994 6.5 6.09994 8.82V11.35C6.09994 11.76 5.90994 12.46 5.69994 12.82L4.68994 14.49C4.28994 15.16 4.19994 15.9 4.44994 16.58C4.68994 17.25 5.25994 17.77 5.99994 18.02C7.93994 18.68 9.97994 19 12.0199 19C14.0599 19 16.0999 18.68 18.0399 18.03C18.7399 17.8 19.2799 17.27 19.5399 16.58C19.7999 15.89 19.7299 15.13 19.3399 14.49Z" fill="currentColor"/>
|
||||
<path d="M14.8297 20.01C14.4097 21.17 13.2997 22 11.9997 22C11.2097 22 10.4297 21.68 9.87969 21.11C9.55969 20.81 9.31969 20.41 9.17969 20C9.30969 20.02 9.43969 20.03 9.57969 20.05C9.80969 20.08 10.0497 20.11 10.2897 20.13C10.8597 20.18 11.4397 20.21 12.0197 20.21C12.5897 20.21 13.1597 20.18 13.7197 20.13C13.9297 20.11 14.1397 20.1 14.3397 20.07C14.4997 20.05 14.6597 20.03 14.8297 20.01Z" fill="currentColor"/>
|
||||
</svg>
|
||||
{count > 0 && (
|
||||
<span style={{
|
||||
position: 'absolute', top: 6, right: 6,
|
||||
background: '#ef4444', color: 'white', fontSize: 10, fontWeight: 700,
|
||||
borderRadius: '50%', width: 16, height: 16,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}>
|
||||
{count > 9 ? '9+' : count}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Notification drawer ──────────────────────────────────────────────────────
|
||||
|
||||
function NotificationDrawer({ messages, onClose }) {
|
||||
return (
|
||||
<div className="modal-overlay" onClick={onClose}>
|
||||
<div className="modal-sheet" onClick={e => e.stopPropagation()} style={{ maxHeight: '80svh' }}>
|
||||
<div className="modal-handle" />
|
||||
<h2 className="modal-title" style={{ marginBottom: 8 }}>Ειδοποιήσεις</h2>
|
||||
{messages.length === 0 && (
|
||||
<p style={{ textAlign: 'center', color: 'var(--muted)', padding: '24px 0' }}>
|
||||
Δεν υπάρχουν ειδοποιήσεις
|
||||
</p>
|
||||
)}
|
||||
<div style={{ display: 'flex', flexDirection: 'column', overflowY: 'auto', flex: 1 }}>
|
||||
{messages.map(msg => {
|
||||
const tableIds = (() => { try { return JSON.parse(msg.table_ids || '[]') } catch { return [] } })()
|
||||
return (
|
||||
<div key={msg.id} style={{
|
||||
padding: '12px 4px', borderBottom: '1px solid var(--border)',
|
||||
display: 'flex', gap: 12, alignItems: 'flex-start',
|
||||
}}>
|
||||
<span style={{ fontSize: 20, flexShrink: 0 }}>📢</span>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
{msg.sender_name && (
|
||||
<div style={{ fontSize: 11, fontWeight: 700, color: '#a5b4fc', marginBottom: 2 }}>{msg.sender_name}</div>
|
||||
)}
|
||||
<div style={{ fontSize: 14, fontWeight: 600, color: 'var(--text)' }}>{msg.body}</div>
|
||||
{tableIds.length > 0 && (
|
||||
<div style={{ fontSize: 12, color: 'var(--muted)', marginTop: 2 }}>Τραπέζι: {tableIds.join(', ')}</div>
|
||||
)}
|
||||
<div style={{ fontSize: 11, color: 'var(--muted)', marginTop: 2 }}>
|
||||
{new Date(msg.created_at).toLocaleTimeString('el-GR', { hour: '2-digit', minute: '2-digit' })}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<button className="btn btn--secondary" style={{ width: '100%', marginTop: 4 }} onClick={onClose}>Κλείσιμο</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Side drawer ──────────────────────────────────────────────────────────────
|
||||
|
||||
const DRAWER_NAV_ITEMS = [
|
||||
{ ...NAV_REGISTRY.tables },
|
||||
{
|
||||
key: 'standalone',
|
||||
label: 'Takeaway / Delivery',
|
||||
href: '/tables',
|
||||
match: () => false, // active state handled separately in SideDrawer
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M5 12H3l9-9 9 9h-2" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<path d="M10 22v-6h4v6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{ ...NAV_REGISTRY.orders },
|
||||
{ ...NAV_REGISTRY.messages },
|
||||
{
|
||||
key: 'shift-overview',
|
||||
label: 'Σύνοψη Βάρδιας',
|
||||
href: '/shift-overview',
|
||||
match: (loc) => loc.pathname === '/shift-overview',
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="2"/>
|
||||
<path d="M12 7v5l3 3" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'order-log',
|
||||
label: 'Αρχείο Παραγγελιών',
|
||||
href: '/order-log',
|
||||
match: (loc) => loc.pathname === '/order-log',
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M6 9V2h12v7" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
<rect x="6" y="14" width="12" height="8" rx="1" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
const DRAWER_SETTINGS_ITEM = {
|
||||
key: 'settings',
|
||||
label: 'Settings',
|
||||
href: '/settings',
|
||||
match: (loc) => loc.pathname.startsWith('/settings'),
|
||||
icon: (
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none">
|
||||
<circle cx="12" cy="12" r="3" stroke="currentColor" strokeWidth="2"/>
|
||||
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" stroke="currentColor" strokeWidth="2"/>
|
||||
</svg>
|
||||
),
|
||||
}
|
||||
|
||||
function DrawerButton({ item, location, onNavigate, active: activeProp, onClick }) {
|
||||
const active = activeProp ?? item.match(location)
|
||||
return (
|
||||
<button
|
||||
onClick={onClick ?? (() => onNavigate(item.href))}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 14,
|
||||
padding: '12px 14px', borderRadius: 12, border: 'none',
|
||||
background: active ? 'var(--accent)18' : 'transparent',
|
||||
color: active ? 'var(--accent)' : 'var(--text)',
|
||||
fontSize: 15, fontWeight: active ? 700 : 500,
|
||||
cursor: 'pointer', textAlign: 'left', width: '100%',
|
||||
transition: 'background 0.12s, color 0.12s',
|
||||
}}
|
||||
>
|
||||
<span style={{ opacity: active ? 1 : 0.6, flexShrink: 0 }}>{item.icon}</span>
|
||||
{item.label}
|
||||
{active && (
|
||||
<div style={{ marginLeft: 'auto', width: 6, height: 6, borderRadius: '50%', background: 'var(--accent)' }} />
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function SideDrawer({ open, onClose }) {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const { activeZoneTab, setActiveZoneTab } = useTableViewStore()
|
||||
|
||||
function go(href) {
|
||||
if (href.startsWith('/tables')) setActiveZoneTab('all')
|
||||
onClose()
|
||||
navigate(href, { replace: true })
|
||||
}
|
||||
|
||||
function goStandalone() {
|
||||
setActiveZoneTab('standalone')
|
||||
onClose()
|
||||
navigate('/tables', { replace: true })
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Overlay */}
|
||||
<div
|
||||
onClick={onClose}
|
||||
style={{
|
||||
position: 'fixed', inset: 0, zIndex: 300,
|
||||
background: 'rgba(0,0,0,0.55)',
|
||||
opacity: open ? 1 : 0,
|
||||
pointerEvents: open ? 'all' : 'none',
|
||||
transition: 'opacity 0.22s ease',
|
||||
}}
|
||||
/>
|
||||
{/* Drawer panel */}
|
||||
<div style={{
|
||||
position: 'fixed', top: 0, left: 0, bottom: 0,
|
||||
width: 260, zIndex: 301,
|
||||
background: 'var(--bg2)',
|
||||
borderRight: '1px solid var(--border)',
|
||||
display: 'flex', flexDirection: 'column',
|
||||
transform: open ? 'translateX(0)' : 'translateX(-100%)',
|
||||
transition: 'transform 0.22s ease',
|
||||
boxShadow: open ? '4px 0 24px rgba(0,0,0,0.4)' : 'none',
|
||||
}}>
|
||||
{/* Drawer header */}
|
||||
<div style={{ padding: '20px 20px 16px', borderBottom: '1px solid var(--border)' }}>
|
||||
<div style={{ fontSize: 22, fontWeight: 800, color: 'var(--accent)', letterSpacing: -0.5 }}>Xenia</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--muted)', marginTop: 2 }}>POS System</div>
|
||||
</div>
|
||||
|
||||
{/* Main nav items */}
|
||||
<div style={{ flex: 1, padding: '12px 10px', display: 'flex', flexDirection: 'column', gap: 4, overflowY: 'auto' }}>
|
||||
<div style={{ fontSize: 10, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 1, padding: '4px 10px 8px' }}>
|
||||
Πλοήγηση
|
||||
</div>
|
||||
{DRAWER_NAV_ITEMS.map(item => {
|
||||
const isStandaloneActive = location.pathname === '/tables' && activeZoneTab === 'standalone'
|
||||
const active = item.key === 'standalone'
|
||||
? isStandaloneActive
|
||||
: item.key === 'tables'
|
||||
? item.match(location) && !isStandaloneActive
|
||||
: undefined
|
||||
return (
|
||||
<DrawerButton
|
||||
key={item.key}
|
||||
item={item}
|
||||
location={location}
|
||||
onNavigate={go}
|
||||
active={active}
|
||||
onClick={item.key === 'standalone' ? goStandalone : undefined}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Settings at bottom */}
|
||||
<div style={{ padding: '8px 10px 16px', borderTop: '1px solid var(--border)' }}>
|
||||
<DrawerButton item={DRAWER_SETTINGS_ITEM} location={location} onNavigate={go} />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Triple pill footer ───────────────────────────────────────────────────────
|
||||
|
||||
function PillBadge({ count, color = '#ef4444' }) {
|
||||
if (!count) return null
|
||||
return (
|
||||
<span style={{
|
||||
background: color, color: 'white', fontSize: 12, fontWeight: 800,
|
||||
borderRadius: 11, minWidth: 22, height: 22,
|
||||
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||||
padding: '0 6px', lineHeight: 1, flexShrink: 0,
|
||||
}}>
|
||||
{count > 9 ? '9+' : count}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function TripleFooter({ location, navigate, chatUnread, kdsReady, tripleItems }) {
|
||||
const { activeZoneTab, setActiveZoneTab } = useTableViewStore()
|
||||
const items = (tripleItems || ['tables', 'orders', 'messages']).map(k => NAV_REGISTRY[k]).filter(Boolean)
|
||||
|
||||
function handleNavClick(item) {
|
||||
if (item.key === 'standalone') { setActiveZoneTab('standalone'); navigate('/tables', { replace: true }); return }
|
||||
if (item.key === 'tables' || item.key === 'orders') setActiveZoneTab('all')
|
||||
navigate(item.href, { replace: true })
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
padding: '10px 10px',
|
||||
background: 'var(--bg2)',
|
||||
borderTop: '1px solid var(--border)',
|
||||
flexShrink: 0,
|
||||
}}>
|
||||
<div style={{ display: 'flex', gap: 4, background: 'var(--bg3)', borderRadius: 28, padding: 4, width: '100%' }}>
|
||||
{items.map(item => {
|
||||
const isStandaloneActive = location.pathname === '/tables' && activeZoneTab === 'standalone'
|
||||
const active = item.key === 'standalone'
|
||||
? isStandaloneActive
|
||||
: item.key === 'tables'
|
||||
? item.match(location) && !isStandaloneActive
|
||||
: item.match(location)
|
||||
const badge = item.key === 'messages' && chatUnread > 0
|
||||
? { count: chatUnread, color: '#ef4444' }
|
||||
: item.key === 'orders' && kdsReady > 0
|
||||
? { count: kdsReady, color: '#22c55e' }
|
||||
: null
|
||||
return (
|
||||
<button
|
||||
key={item.key}
|
||||
onClick={() => handleNavClick(item)}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6,
|
||||
flex: 1,
|
||||
padding: '9px 8px', borderRadius: 22,
|
||||
border: '2px solid transparent',
|
||||
background: active ? 'var(--accent)' : 'transparent',
|
||||
color: active ? 'var(--accent-fg)' : 'var(--muted)',
|
||||
fontSize: 14, fontWeight: 700, cursor: 'pointer', lineHeight: 1,
|
||||
transition: 'background 0.15s, color 0.15s',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
<span style={{ display: 'inline-flex', alignItems: 'center', flexShrink: 0 }}>
|
||||
{item.key === 'tables' && <svg width="15" height="15" viewBox="0 0 24 24" fill="none"><rect x="3" y="3" width="7" height="7" rx="1.5" fill="currentColor"/><rect x="14" y="3" width="7" height="7" rx="1.5" fill="currentColor"/><rect x="3" y="14" width="7" height="7" rx="1.5" fill="currentColor"/><rect x="14" y="14" width="7" height="7" rx="1.5" fill="currentColor"/></svg>}
|
||||
{item.key === 'orders' && <svg width="15" height="15" viewBox="0 0 24 24" fill="none"><path d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"/><path d="M9 12h6M9 16h4" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"/></svg>}
|
||||
{item.key === 'messages' && <svg width="15" height="15" viewBox="0 0 24 24" fill="none"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/></svg>}
|
||||
</span>
|
||||
{item.shortLabel ?? item.label}
|
||||
{badge && <PillBadge count={badge.count} color={badge.color} />}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Icon navbar footer ───────────────────────────────────────────────────────
|
||||
|
||||
function IconNavbar({ navItems, location, navigate, chatUnread, kdsReady }) {
|
||||
const { activeZoneTab, setActiveZoneTab } = useTableViewStore()
|
||||
const items = navItems
|
||||
.map(key => NAV_REGISTRY[key])
|
||||
.filter(Boolean)
|
||||
|
||||
function handleNavClick(item) {
|
||||
if (item.key === 'standalone') { setActiveZoneTab('standalone'); navigate('/tables', { replace: true }); return }
|
||||
if (item.key === 'tables' || item.key === 'orders') setActiveZoneTab('all')
|
||||
navigate(item.href, { replace: true })
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'stretch',
|
||||
padding: '0 8px',
|
||||
paddingBottom: 'env(safe-area-inset-bottom, 0px)',
|
||||
background: 'var(--bg2)',
|
||||
borderTop: '1px solid var(--border)',
|
||||
flexShrink: 0,
|
||||
minHeight: 60,
|
||||
}}>
|
||||
{items.map(item => {
|
||||
const isStandaloneActive = location.pathname === '/tables' && activeZoneTab === 'standalone'
|
||||
const active = item.key === 'standalone'
|
||||
? isStandaloneActive
|
||||
: item.key === 'tables'
|
||||
? item.match(location) && !isStandaloneActive
|
||||
: item.match(location)
|
||||
const badge = item.key === 'messages' && chatUnread > 0
|
||||
? { count: chatUnread, color: '#ef4444' }
|
||||
: item.key === 'orders' && kdsReady > 0
|
||||
? { count: kdsReady, color: '#22c55e' }
|
||||
: null
|
||||
return (
|
||||
<button
|
||||
key={item.key}
|
||||
onClick={() => handleNavClick(item)}
|
||||
style={{
|
||||
flex: 1, display: 'flex', flexDirection: 'column',
|
||||
alignItems: 'center', justifyContent: 'center', gap: 4,
|
||||
border: 'none', background: 'none', cursor: 'pointer',
|
||||
color: active ? 'var(--accent)' : 'var(--muted)',
|
||||
padding: '10px 4px',
|
||||
position: 'relative',
|
||||
transition: 'color 0.15s',
|
||||
}}
|
||||
>
|
||||
{active && (
|
||||
<div style={{
|
||||
position: 'absolute', top: 0, left: '25%', right: '25%',
|
||||
height: 2, borderRadius: '0 0 2px 2px',
|
||||
background: 'var(--accent)',
|
||||
}} />
|
||||
)}
|
||||
<span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', position: 'relative' }}>
|
||||
{item.icon}
|
||||
{badge && (
|
||||
<span style={{
|
||||
position: 'absolute', top: -4, right: -6,
|
||||
background: badge.color, color: 'white', fontSize: 9, fontWeight: 800,
|
||||
borderRadius: '50%', minWidth: 14, height: 14,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
padding: '0 2px',
|
||||
}}>
|
||||
{badge.count > 9 ? '9+' : badge.count}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span style={{ fontSize: 10, fontWeight: active ? 700 : 500, letterSpacing: 0.2 }}>
|
||||
{item.shortLabel ?? item.label}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── AppShell ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function AppShell({ children, title, rightActions }) {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const [drawerOpen, setDrawerOpen] = useState(false)
|
||||
const [showNotifs, setShowNotifs] = useState(false)
|
||||
|
||||
const { unreadCount, recentMessages, fetchRecent, ackAll } = useNotifications() || {}
|
||||
const { popupMode } = useNotificationSettingsStore()
|
||||
const { navStyle, navItems, tripleItems } = useTableViewStore()
|
||||
const { totalUnread: chatUnread } = useChatStore()
|
||||
const { readyCount } = useKdsReadyStore()
|
||||
const offlineCacheCount = useOfflineQueueCount()
|
||||
const failedPrintCount = useFailedPrintCount()
|
||||
|
||||
function openNotifs() {
|
||||
setShowNotifs(true)
|
||||
fetchRecent?.()
|
||||
if (popupMode === 'never') ackAll?.()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="page">
|
||||
{/* ── Header ────────────────────────────────────────────── */}
|
||||
<header className="top-bar">
|
||||
{/* Hamburger menu */}
|
||||
<button
|
||||
onClick={() => setDrawerOpen(true)}
|
||||
style={{
|
||||
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||||
background: 'none', border: 'none', cursor: 'pointer',
|
||||
color: 'var(--text)', minWidth: 44, minHeight: 44, borderRadius: 8,
|
||||
}}
|
||||
>
|
||||
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round">
|
||||
<line x1="3" y1="6" x2="21" y2="6"/>
|
||||
<line x1="3" y1="12" x2="21" y2="12"/>
|
||||
<line x1="3" y1="18" x2="21" y2="18"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{/* Title / right-actions area */}
|
||||
{title && (
|
||||
<span className="top-bar__title">{title}</span>
|
||||
)}
|
||||
{!title && <div style={{ flex: 1 }} />}
|
||||
|
||||
{/* Custom right actions (per-page) */}
|
||||
{rightActions}
|
||||
|
||||
{/* Offline cache badge — visible only when ops are pending */}
|
||||
<CacheButton count={offlineCacheCount} />
|
||||
|
||||
{/* Failed print badge — navigates to order log */}
|
||||
<FailedPrintButton count={failedPrintCount} onClick={() => navigate('/order-log?filter=failed')} />
|
||||
|
||||
{/* Bell */}
|
||||
<BellButton onClick={openNotifs} count={unreadCount || 0} />
|
||||
|
||||
{/* Username chip */}
|
||||
<UserMenu />
|
||||
</header>
|
||||
|
||||
{/* ── Side drawer ───────────────────────────────────────── */}
|
||||
<SideDrawer open={drawerOpen} onClose={() => setDrawerOpen(false)} />
|
||||
|
||||
{/* ── Page content ──────────────────────────────────────── */}
|
||||
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', minHeight: 0, overflow: 'hidden' }}>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
{/* ── Footer nav ────────────────────────────────────────── */}
|
||||
{navStyle === 'icon_navbar' ? (
|
||||
<IconNavbar
|
||||
navItems={navItems}
|
||||
location={location}
|
||||
navigate={navigate}
|
||||
chatUnread={chatUnread}
|
||||
kdsReady={readyCount}
|
||||
/>
|
||||
) : (
|
||||
<TripleFooter
|
||||
location={location}
|
||||
navigate={navigate}
|
||||
chatUnread={chatUnread}
|
||||
kdsReady={readyCount}
|
||||
tripleItems={tripleItems}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* ── Notification drawer ───────────────────────────────── */}
|
||||
{showNotifs && (
|
||||
<NotificationDrawer
|
||||
messages={recentMessages || []}
|
||||
onClose={() => setShowNotifs(false)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
export default function ConnectionBanner() {
|
||||
return (
|
||||
<div style={{
|
||||
background: '#7f1d1d',
|
||||
color: '#fca5a5',
|
||||
textAlign: 'center',
|
||||
padding: '8px 16px',
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
}}>
|
||||
⚠ Cannot reach the system — check your WiFi
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import useConnectionStore from '../store/connectionStore'
|
||||
import client from '../api/client'
|
||||
import { useSSEContext } from '../context/SSEContext'
|
||||
|
||||
const RETRY_INTERVAL = 10_000
|
||||
|
||||
export default function ConnectionLostModal() {
|
||||
const { status, setOnline, enterEmergency } = useConnectionStore()
|
||||
const { reconnect, fullRefresh } = useSSEContext()
|
||||
const [retrying, setRetrying] = useState(false)
|
||||
const retryRef = useRef(null)
|
||||
|
||||
const isReconnecting = status === 'reconnecting'
|
||||
const isLost = status === 'lost'
|
||||
|
||||
async function tryReconnect() {
|
||||
setRetrying(true)
|
||||
try {
|
||||
await client.get('/api/system/health')
|
||||
setOnline()
|
||||
reconnect()
|
||||
await fullRefresh()
|
||||
} catch {
|
||||
// Still down — stay in modal
|
||||
} finally {
|
||||
setRetrying(false)
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-retry every 10s while the full "lost" modal is open
|
||||
useEffect(() => {
|
||||
if (!isLost) { clearInterval(retryRef.current); return }
|
||||
retryRef.current = setInterval(tryReconnect, RETRY_INTERVAL)
|
||||
return () => clearInterval(retryRef.current)
|
||||
}, [isLost])
|
||||
|
||||
if (!isReconnecting && !isLost) return null
|
||||
|
||||
// ── Grace-period spinner ───────────────────────────────────────────────────
|
||||
if (isReconnecting) {
|
||||
return (
|
||||
<div style={{
|
||||
position: 'fixed', inset: 0, zIndex: 99999,
|
||||
background: 'rgba(0,0,0,0.55)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
padding: 24,
|
||||
}}>
|
||||
<div style={{
|
||||
background: '#1e293b',
|
||||
border: '2px solid #334155',
|
||||
borderRadius: 20,
|
||||
padding: '32px 28px',
|
||||
maxWidth: 340, width: '100%',
|
||||
textAlign: 'center',
|
||||
boxShadow: '0 24px 64px rgba(0,0,0,0.5)',
|
||||
}}>
|
||||
{/* Spinning ring */}
|
||||
<div style={{
|
||||
width: 52, height: 52, margin: '0 auto 20px',
|
||||
border: '4px solid #334155',
|
||||
borderTopColor: 'var(--accent, #f97316)',
|
||||
borderRadius: '50%',
|
||||
animation: 'gate-spin 0.8s linear infinite',
|
||||
}} />
|
||||
<p style={{ fontSize: 17, fontWeight: 700, color: '#f1f5f9', marginBottom: 8 }}>
|
||||
Επανασύνδεση…
|
||||
</p>
|
||||
<p style={{ fontSize: 13, color: '#64748b', lineHeight: 1.6 }}>
|
||||
Προσπαθώ να φτάσω στον server.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Full "lost" modal ──────────────────────────────────────────────────────
|
||||
return (
|
||||
<div style={{
|
||||
position: 'fixed', inset: 0, zIndex: 99999,
|
||||
background: 'rgba(0,0,0,0.75)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
padding: 24,
|
||||
}}>
|
||||
<div style={{
|
||||
background: '#1e293b',
|
||||
border: '2px solid #ef4444',
|
||||
borderRadius: 20,
|
||||
padding: '32px 28px',
|
||||
maxWidth: 400, width: '100%',
|
||||
textAlign: 'center',
|
||||
boxShadow: '0 24px 64px rgba(0,0,0,0.6)',
|
||||
}}>
|
||||
<div style={{ fontSize: 48, marginBottom: 16 }}>⚠️</div>
|
||||
|
||||
<p style={{ fontSize: 20, fontWeight: 700, color: '#f1f5f9', marginBottom: 10 }}>
|
||||
Χάθηκε η σύνδεση με τον Manager
|
||||
</p>
|
||||
|
||||
<p style={{ fontSize: 14, color: '#94a3b8', lineHeight: 1.6, marginBottom: 28 }}>
|
||||
Δεν μπορώ να φτάσω στον server.{'\n'}
|
||||
Περίμενε ή άνοιξε <strong style={{ color: '#fbbf24' }}>ΕΚΤΑΚΤΗ ΛΕΙΤΟΥΡΓΙΑ</strong>{'\n'}
|
||||
για να συνεχίσεις με τοπικά δεδομένα.
|
||||
</p>
|
||||
|
||||
<div style={{ display: 'flex', gap: 12, justifyContent: 'center' }}>
|
||||
<button
|
||||
onClick={enterEmergency}
|
||||
style={{
|
||||
flex: 1, height: 48, borderRadius: 12, border: 'none',
|
||||
background: '#dc2626', color: '#fff',
|
||||
fontSize: 15, fontWeight: 700, cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
EMERGENCY MODE
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p style={{ fontSize: 11, color: '#475569', marginTop: 16 }}>
|
||||
Αυτόματη επανάληψη κάθε 10 δευτερόλεπτα
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import useConnectionStore from '../store/connectionStore'
|
||||
|
||||
/**
|
||||
* A 3px bar pinned to the very top of the screen (above the header).
|
||||
* Always visible — color signals connection state at a glance:
|
||||
*
|
||||
* sseAlive=true → solid green (SSE stream live)
|
||||
* online only → solid blue (HTTP reachable, SSE not yet connected)
|
||||
* reconnecting → amber, animated sweep
|
||||
* offline → red, animated sweep
|
||||
* offline >5min → flashing red
|
||||
*/
|
||||
export default function ConnectivityBar() {
|
||||
const { status, sseAlive, flashing } = useConnectionStore()
|
||||
|
||||
const isOnline = status === 'online'
|
||||
const isReconnecting = status === 'reconnecting'
|
||||
const isOffline = status === 'offline'
|
||||
|
||||
const color = isOnline
|
||||
? (sseAlive ? '#22c55e' : '#3b82f6')
|
||||
: isReconnecting
|
||||
? '#f59e0b'
|
||||
: '#ef4444'
|
||||
|
||||
const animated = !isOnline
|
||||
|
||||
return (
|
||||
<>
|
||||
<style>{`
|
||||
@keyframes connectivity-sweep {
|
||||
0% { background-position: -200% center; }
|
||||
100% { background-position: 300% center; }
|
||||
}
|
||||
@keyframes connectivity-flash {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.15; }
|
||||
}
|
||||
.connectivity-bar {
|
||||
position: relative;
|
||||
height: 3px;
|
||||
flex-shrink: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.connectivity-bar--sweep {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--cb-color) 0%,
|
||||
var(--cb-color) 30%,
|
||||
color-mix(in srgb, var(--cb-color) 20%, transparent) 50%,
|
||||
var(--cb-color) 70%,
|
||||
var(--cb-color) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: connectivity-sweep 1.8s ease-in-out infinite;
|
||||
}
|
||||
.connectivity-bar--flash {
|
||||
animation: connectivity-flash 0.7s ease-in-out infinite;
|
||||
}
|
||||
`}</style>
|
||||
|
||||
<div
|
||||
className={[
|
||||
'connectivity-bar',
|
||||
animated && !flashing ? 'connectivity-bar--sweep' : '',
|
||||
flashing ? 'connectivity-bar--flash' : '',
|
||||
].join(' ')}
|
||||
style={{
|
||||
'--cb-color': color,
|
||||
backgroundColor: color,
|
||||
boxShadow: `0 0 6px 1px ${color}99`,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import useConnectionStore from '../store/connectionStore'
|
||||
|
||||
export default function EmergencyBar() {
|
||||
const { status, lostAt } = useConnectionStore()
|
||||
const [elapsed, setElapsed] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
if (status !== 'emergency' || !lostAt) return
|
||||
function tick() {
|
||||
const secs = Math.floor((Date.now() - lostAt.getTime()) / 1000)
|
||||
const m = Math.floor(secs / 60)
|
||||
const s = secs % 60
|
||||
setElapsed(`${m}:${String(s).padStart(2, '0')}`)
|
||||
}
|
||||
tick()
|
||||
const id = setInterval(tick, 1000)
|
||||
return () => clearInterval(id)
|
||||
}, [status, lostAt])
|
||||
|
||||
if (status !== 'emergency') return null
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
background: '#dc2626',
|
||||
color: '#fef08a',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
gap: 8,
|
||||
padding: '8px 16px',
|
||||
fontSize: 13, fontWeight: 700,
|
||||
letterSpacing: 0.5,
|
||||
userSelect: 'none',
|
||||
}}>
|
||||
<span>EMERGENCY MODE</span>
|
||||
{elapsed && (
|
||||
<span style={{ opacity: 0.85, fontWeight: 400 }}>({elapsed})</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,19 +1,40 @@
|
||||
import { useState } from 'react'
|
||||
import { useState, useRef } from 'react'
|
||||
|
||||
// Unit metadata: step, min, quick-preset values, quick ± offset buttons
|
||||
const UNIT_CONFIG = {
|
||||
kg: { step: 0.1, min: 0.1, presets: [0.2, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0], offsets: [0.2, 0.5, 1.0], label: 'kg' },
|
||||
liter: { step: 0.1, min: 0.1, presets: [0.2, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0], offsets: [0.2, 0.5, 1.0], label: 'L' },
|
||||
gram: { step: 10, min: 10, presets: [50, 100, 150, 200, 250, 300, 400, 500], offsets: [50, 100, 200], label: 'g' },
|
||||
ml: { step: 5, min: 5, presets: [25, 50, 100, 150, 200, 250, 300, 500], offsets: [25, 50, 100], label: 'mL' },
|
||||
}
|
||||
const DECIMAL_UNITS = new Set(Object.keys(UNIT_CONFIG))
|
||||
|
||||
function fmtQty(qty, unitCfg) {
|
||||
if (!unitCfg) return String(qty)
|
||||
if (unitCfg.label === 'kg' || unitCfg.label === 'L') return Number(qty).toFixed(1)
|
||||
return String(qty)
|
||||
}
|
||||
|
||||
export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
const [selectedOptions, setSelectedOptions] = useState([])
|
||||
const [removedIngredients, setRemovedIngredients] = useState([])
|
||||
const [notes, setNotes] = useState('')
|
||||
const [quantity, setQuantity] = useState(1)
|
||||
|
||||
const unitCfg = UNIT_CONFIG[product.unit_type] ?? null
|
||||
const isDecimal = DECIMAL_UNITS.has(product.unit_type)
|
||||
const [quantity, setQuantity] = useState(isDecimal ? (unitCfg?.presets[0] ?? 0.1) : 1)
|
||||
const [qtyInput, setQtyInput] = useState('')
|
||||
const [editingQty, setEditingQty] = useState(false)
|
||||
const qtyRef = useRef(null)
|
||||
|
||||
const options = product.options || []
|
||||
const ingredients = product.ingredients || []
|
||||
const preferenceSets = product.preference_sets || []
|
||||
|
||||
// selectedPreferences: { [setId]: choice | null }
|
||||
// selectedPreferences: { [setId]: choice | null } (single-select sets)
|
||||
const [selectedPreferences, setSelectedPreferences] = useState(() =>
|
||||
Object.fromEntries(
|
||||
preferenceSets.map(ps => {
|
||||
preferenceSets.filter(ps => !ps.allow_multi_select).map(ps => {
|
||||
const def = ps.default_choice_id != null
|
||||
? ps.choices.find(c => c.id === ps.default_choice_id) ?? null
|
||||
: null
|
||||
@@ -22,10 +43,22 @@ export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
)
|
||||
)
|
||||
|
||||
// multiPreferences: { [setId]: Array<{choice, qty}> } (multi-select sets)
|
||||
const [multiPreferences, setMultiPreferences] = useState(() =>
|
||||
Object.fromEntries(
|
||||
preferenceSets.filter(ps => ps.allow_multi_select).map(ps => {
|
||||
const def = ps.default_choice_id != null
|
||||
? ps.choices.find(c => c.id === ps.default_choice_id) ?? null
|
||||
: null
|
||||
return [ps.id, def ? [{ choice: def, qty: 1 }] : []]
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
// Per-preference-choice inline sub-choices: { [choiceId]: subChoice | null }
|
||||
const [selectedSubChoices, setSelectedSubChoices] = useState(() => {
|
||||
const init = {}
|
||||
preferenceSets.forEach(ps => {
|
||||
preferenceSets.filter(ps => !ps.allow_multi_select).forEach(ps => {
|
||||
const def = ps.default_choice_id != null
|
||||
? ps.choices.find(c => c.id === ps.default_choice_id) ?? null
|
||||
: null
|
||||
@@ -40,7 +73,7 @@ export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
// Shared-subset selections: { [setId]: subChoice | null }
|
||||
const [selectedSharedSubs, setSelectedSharedSubs] = useState(() => {
|
||||
const init = {}
|
||||
preferenceSets.forEach(ps => {
|
||||
preferenceSets.filter(ps => !ps.allow_multi_select).forEach(ps => {
|
||||
if (ps.shared_subset?.choices?.length > 0) {
|
||||
const selectedChoice = ps.default_choice_id != null
|
||||
? ps.choices.find(c => c.id === ps.default_choice_id) ?? null
|
||||
@@ -75,6 +108,27 @@ export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
}
|
||||
}
|
||||
|
||||
function toggleMultiChoice(setId, choice) {
|
||||
setMultiPreferences(prev => {
|
||||
const current = prev[setId] ?? []
|
||||
const idx = current.findIndex(e => e.choice.id === choice.id)
|
||||
if (idx >= 0) return { ...prev, [setId]: current.filter((_, i) => i !== idx) }
|
||||
return { ...prev, [setId]: [...current, { choice, qty: 1 }] }
|
||||
})
|
||||
}
|
||||
|
||||
function setMultiChoiceQty(setId, choiceId, delta) {
|
||||
setMultiPreferences(prev => {
|
||||
const current = prev[setId] ?? []
|
||||
return {
|
||||
...prev,
|
||||
[setId]: current.map(e =>
|
||||
e.choice.id === choiceId ? { ...e, qty: Math.max(1, e.qty + delta) } : e
|
||||
),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function selectSubChoice(parentChoiceId, sub) {
|
||||
setSelectedSubChoices(prev => ({ ...prev, [parentChoiceId]: sub }))
|
||||
}
|
||||
@@ -117,6 +171,9 @@ export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
})
|
||||
|
||||
function isPrefSetComplete(ps) {
|
||||
if (ps.allow_multi_select) {
|
||||
return (multiPreferences[ps.id] ?? []).length > 0
|
||||
}
|
||||
const choice = selectedPreferences[ps.id]
|
||||
if (choice == null) return false
|
||||
if (choice.sub_choices?.length > 0 && selectedSubChoices[choice.id] == null) return false
|
||||
@@ -129,6 +186,9 @@ export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
const canAdd = allPrefsSelected && !optionSubsMissing
|
||||
|
||||
const prefExtra = preferenceSets.reduce((s, ps) => {
|
||||
if (ps.allow_multi_select) {
|
||||
return s + (multiPreferences[ps.id] ?? []).reduce((acc, { choice, qty }) => acc + (choice.extra_cost ?? 0) * qty, 0)
|
||||
}
|
||||
const choice = selectedPreferences[ps.id]
|
||||
if (!choice) return s
|
||||
const inlineSub = choice.sub_choices?.length > 0 ? (selectedSubChoices[choice.id] ?? null) : null
|
||||
@@ -145,6 +205,14 @@ export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
function handleAdd() {
|
||||
if (!canAdd) return
|
||||
const prefChoices = preferenceSets.flatMap(ps => {
|
||||
if (ps.allow_multi_select) {
|
||||
return (multiPreferences[ps.id] ?? []).map(({ choice, qty }) => ({
|
||||
id: choice.id,
|
||||
name: qty > 1 ? `${choice.name} x${qty}` : choice.name,
|
||||
price_delta: (choice.extra_cost ?? 0) * qty,
|
||||
type: 'pref',
|
||||
}))
|
||||
}
|
||||
const choice = selectedPreferences[ps.id]
|
||||
if (!choice) return []
|
||||
const entries = [{ id: choice.id, name: choice.name, price_delta: choice.extra_cost ?? 0, type: 'pref' }]
|
||||
@@ -227,6 +295,47 @@ export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
{/* ── Preference sets ── */}
|
||||
{preferenceSets.map(ps => {
|
||||
const missing = !isPrefSetComplete(ps)
|
||||
|
||||
if (ps.allow_multi_select) {
|
||||
const selected = multiPreferences[ps.id] ?? []
|
||||
return (
|
||||
<section key={ps.id} className="modal-section"
|
||||
style={missing ? { border: '1.5px solid #ef4444', borderRadius: 10, padding: '10px 12px' } : {}}>
|
||||
<h3 style={{ color: missing ? '#ef4444' : undefined }}>
|
||||
{ps.name}
|
||||
{missing && <span style={{ fontSize: 12, marginLeft: 6, fontWeight: 400 }}>— επιλέξτε τουλάχιστον μία</span>}
|
||||
</h3>
|
||||
{ps.choices.map(ch => {
|
||||
const entry = selected.find(e => e.choice.id === ch.id)
|
||||
const isChecked = !!entry
|
||||
return (
|
||||
<div key={ch.id} style={{ marginBottom: 6 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<label className="modal-option" style={{ flex: 1 }}>
|
||||
<input type="checkbox" checked={isChecked}
|
||||
onChange={() => toggleMultiChoice(ps.id, ch)} />
|
||||
<span>{ch.name}</span>
|
||||
{(ch.extra_cost ?? 0) !== 0 && (
|
||||
<span className="option-price">{ch.extra_cost > 0 ? '+' : ''}{Number(ch.extra_cost).toFixed(2)} €</span>
|
||||
)}
|
||||
</label>
|
||||
{isChecked && ps.allow_choice_quantity && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0 }}>
|
||||
<button className="qty-btn" style={{ width: 28, height: 28, fontSize: 16 }}
|
||||
onClick={() => setMultiChoiceQty(ps.id, ch.id, -1)}>−</button>
|
||||
<span style={{ minWidth: 20, textAlign: 'center', fontWeight: 600, fontSize: 15 }}>{entry.qty}</span>
|
||||
<button className="qty-btn" style={{ width: 28, height: 28, fontSize: 16 }}
|
||||
onClick={() => setMultiChoiceQty(ps.id, ch.id, 1)}>+</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
const selectedChoice = selectedPreferences[ps.id] ?? null
|
||||
const showSharedSubset = ps.shared_subset?.choices?.length > 0
|
||||
&& selectedChoice != null
|
||||
@@ -325,11 +434,71 @@ export default function ItemOptionsModal({ product, onAdd, onClose }) {
|
||||
value={notes} onChange={e => setNotes(e.target.value)} rows={2} />
|
||||
</section>
|
||||
|
||||
<div className="modal-qty">
|
||||
<button className="qty-btn" onClick={() => setQuantity(q => Math.max(1, q - 1))}>−</button>
|
||||
<span className="qty-value">{quantity}</span>
|
||||
<button className="qty-btn" onClick={() => setQuantity(q => q + 1)}>+</button>
|
||||
</div>
|
||||
{isDecimal ? (
|
||||
<div className="qty-decimal-panel">
|
||||
{/* Main ‒ / value / + row */}
|
||||
<div className="modal-qty">
|
||||
<button className="qty-btn" onClick={() => setQuantity(q => Math.max(unitCfg.min, Math.round((q - unitCfg.step) * 1000) / 1000))}>−</button>
|
||||
{editingQty ? (
|
||||
<input
|
||||
ref={qtyRef}
|
||||
type="number"
|
||||
inputMode="decimal"
|
||||
className="qty-decimal-input"
|
||||
value={qtyInput}
|
||||
onChange={e => setQtyInput(e.target.value)}
|
||||
onBlur={() => {
|
||||
const v = parseFloat(qtyInput)
|
||||
if (!isNaN(v) && v >= unitCfg.min) setQuantity(Math.round(v * 1000) / 1000)
|
||||
setEditingQty(false)
|
||||
}}
|
||||
onKeyDown={e => { if (e.key === 'Enter') e.target.blur() }}
|
||||
autoFocus
|
||||
/>
|
||||
) : (
|
||||
<span className="qty-value" style={{ cursor: 'text', minWidth: 64 }}
|
||||
onClick={() => { setQtyInput(String(quantity)); setEditingQty(true) }}>
|
||||
{fmtQty(quantity, unitCfg)} <span style={{ fontSize: 14, fontWeight: 500, opacity: 0.7 }}>{unitCfg.label}</span>
|
||||
</span>
|
||||
)}
|
||||
<button className="qty-btn" onClick={() => setQuantity(q => Math.round((q + unitCfg.step) * 1000) / 1000)}>+</button>
|
||||
</div>
|
||||
|
||||
{/* Quick preset values */}
|
||||
<div className="qty-presets">
|
||||
{unitCfg.presets.map(v => (
|
||||
<button key={v} className={`qty-preset-btn${quantity === v ? ' qty-preset-btn--active' : ''}`}
|
||||
onClick={() => setQuantity(v)}>
|
||||
{fmtQty(v, unitCfg)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Quick ± offset buttons */}
|
||||
<div className="qty-offsets">
|
||||
{unitCfg.offsets.map(off => (
|
||||
<button key={`+${off}`} className="qty-offset-btn qty-offset-btn--add"
|
||||
onClick={() => setQuantity(q => Math.round((q + off) * 1000) / 1000)}>
|
||||
+{fmtQty(off, unitCfg)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="qty-offsets">
|
||||
{unitCfg.offsets.map(off => (
|
||||
<button key={`-${off}`} className="qty-offset-btn qty-offset-btn--sub"
|
||||
onClick={() => setQuantity(q => Math.max(unitCfg.min, Math.round((q - off) * 1000) / 1000))}>
|
||||
−{fmtQty(off, unitCfg)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="modal-qty">
|
||||
<button className="qty-btn" onClick={() => setQuantity(q => Math.max(1, q - 1))}>−</button>
|
||||
<span className="qty-value">{quantity}</span>
|
||||
<button className="qty-btn" onClick={() => setQuantity(q => q + 1)}>+</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!allPrefsSelected && (
|
||||
<p style={{ color: '#ef4444', fontSize: 13, textAlign: 'center', marginTop: 8 }}>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,26 @@
|
||||
import { useRef, useState } from 'react'
|
||||
import useTableViewStore from '../store/tableViewStore'
|
||||
|
||||
function fmtPrice(v) {
|
||||
return Number(v).toFixed(2) + ' €'
|
||||
}
|
||||
|
||||
const UNIT_LABELS = { kg: 'kg', liter: 'L', gram: 'g', ml: 'mL' }
|
||||
function fmtQty(qty, unitType) {
|
||||
const label = UNIT_LABELS[unitType]
|
||||
if (!label) return `×${qty}`
|
||||
if (unitType === 'kg' || unitType === 'liter') return `${Number(qty).toFixed(1)}${label}`
|
||||
return `${qty}${label}`
|
||||
}
|
||||
|
||||
function fmtDateTime(iso) {
|
||||
if (!iso) return null
|
||||
try {
|
||||
const d = new Date(iso)
|
||||
return d.toLocaleString('el-GR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' })
|
||||
} catch { return null }
|
||||
}
|
||||
|
||||
// ── Icons ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
function SectionIcon({ type }) {
|
||||
@@ -17,7 +34,24 @@ function SectionIcon({ type }) {
|
||||
return <span style={{ display: 'inline-flex', alignItems: 'center', flexShrink: 0 }}>{icons[type] ?? null}</span>
|
||||
}
|
||||
|
||||
// ── Parse selected_options into grouped sections (same logic as cart) ────────
|
||||
function ExpandArrow({ expanded, onClick }) {
|
||||
return (
|
||||
<button
|
||||
onClick={e => { e.stopPropagation(); onClick() }}
|
||||
style={{
|
||||
background: 'none', border: 'none', padding: 4, cursor: 'pointer',
|
||||
color: 'var(--muted)', display: 'flex', alignItems: 'center', flexShrink: 0,
|
||||
}}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"
|
||||
style={{ transform: `rotate(${expanded ? 180 : 0}deg)`, transition: 'transform 180ms' }}>
|
||||
<path d="M6 9L12 15L18 9" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Parse selected_options into grouped sections ──────────────────────────────
|
||||
|
||||
function buildSections(item) {
|
||||
const sections = []
|
||||
@@ -28,24 +62,13 @@ function buildSections(item) {
|
||||
try { return item.removed_ingredients ? JSON.parse(item.removed_ingredients) : [] } catch { return [] }
|
||||
})()
|
||||
|
||||
// We don't have product metadata here, so we classify by heuristics:
|
||||
// - id != null → could be a pref choice or extra; we use the _type hint if present, else we group them
|
||||
// - id == null → sub-choice (follows its parent)
|
||||
// Strategy: walk through opts in order, attaching sub-choices to their parent,
|
||||
// then classify parent items: items with a real id that appear multiple times → extra (stacked),
|
||||
// but without product metadata we can't fully distinguish prefs from extras.
|
||||
// We use a simple rule: if an option with id appears only once in the stream → treat as pref
|
||||
// (since extras can be added multiple times). This matches how handleAdd() emits them.
|
||||
const prefGroups = []
|
||||
const extraGroups = []
|
||||
const quickLines = []
|
||||
|
||||
const prefGroups = [] // { setName: null (unknown), values: [...] }
|
||||
const extraGroups = [] // { id, name, subName, qty }
|
||||
const quickLines = [] // { name, _qty }
|
||||
|
||||
// Count how many times each id appears (extras can be stacked → appear multiple times)
|
||||
const idCount = {}
|
||||
opts.forEach(o => { if (o.id != null) idCount[o.id] = (idCount[o.id] || 0) + 1 })
|
||||
|
||||
// Single pass: consume each item and its optional following sub (id=null)
|
||||
const consumedAsSubAtIndex = new Set()
|
||||
let i = 0
|
||||
while (i < opts.length) {
|
||||
@@ -53,7 +76,6 @@ function buildSections(item) {
|
||||
if (consumedAsSubAtIndex.has(i)) { i++; continue }
|
||||
|
||||
if (o.id == null) {
|
||||
// Standalone id=null → quick option
|
||||
const existing = quickLines.find(x => x.name === o.name)
|
||||
if (existing) existing._qty = (existing._qty || 1) + 1
|
||||
else quickLines.push({ name: o.name, _qty: 1 })
|
||||
@@ -61,7 +83,6 @@ function buildSections(item) {
|
||||
continue
|
||||
}
|
||||
|
||||
// id != null — look ahead for immediate sub
|
||||
let subName = null
|
||||
if (i + 1 < opts.length && opts[i + 1].id == null) {
|
||||
subName = opts[i + 1].name
|
||||
@@ -69,12 +90,10 @@ function buildSections(item) {
|
||||
}
|
||||
|
||||
if (idCount[o.id] > 1) {
|
||||
// Extra — appears multiple times in the list
|
||||
const existing = extraGroups.find(g => g.id === o.id && g.subName === subName)
|
||||
if (existing) existing.qty++
|
||||
else extraGroups.push({ id: o.id, name: o.name, subName, qty: 1 })
|
||||
} else {
|
||||
// Single occurrence → preference choice
|
||||
const value = subName ? `${o.name} · ${subName}` : o.name
|
||||
prefGroups.push({ setName: null, values: [value] })
|
||||
}
|
||||
@@ -90,23 +109,231 @@ function buildSections(item) {
|
||||
return sections
|
||||
}
|
||||
|
||||
// ── KDS colour strip ──────────────────────────────────────────────────────────
|
||||
|
||||
const KDS_COLORS = {
|
||||
pending: { textColor: '#f59e0b', label: 'ΕΚΚΡΕΜΕΙ', icon: '⏳', dot: '#f59e0b' },
|
||||
preparing: { textColor: '#60a5fa', label: 'ΕΤΟΙΜΑΖΕΤΑΙ', icon: '🔥', dot: '#60a5fa' },
|
||||
done: { textColor: '#4ade80', label: 'READY', icon: '✓', dot: '#4ade80' },
|
||||
served: { textColor: null, label: null, icon: null, dot: null },
|
||||
}
|
||||
|
||||
// ── Shared expanded details panel ─────────────────────────────────────────────
|
||||
|
||||
function OptionsPanel({ sections }) {
|
||||
return (
|
||||
<div style={{ paddingBottom: 8 }}>
|
||||
{sections.map((sec, si) => (
|
||||
<div key={si}>
|
||||
<div style={{ margin: '0 12px', height: 1, background: 'var(--border)' }} />
|
||||
<div style={{ padding: '5px 12px 2px', display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
{sec.type === 'prefs' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 7 }}>
|
||||
<SectionIcon type="prefs" />
|
||||
<span style={{ fontSize: 12, lineHeight: 1.4, flex: 1 }}>
|
||||
{line.setName && (
|
||||
<span style={{ color: 'var(--muted)', display: 'block', fontSize: 11 }}>{line.setName}</span>
|
||||
)}
|
||||
<span style={{ color: 'var(--text)' }}>{line.values.join(' · ')}</span>
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{sec.type === 'quick' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||||
<SectionIcon type="quick" />
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>
|
||||
{line.name}
|
||||
{line._qty > 1 && <span style={{ color: '#f59e0b', marginLeft: 4, fontWeight: 700 }}>×{line._qty}</span>}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{sec.type === 'extras' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||||
<SectionIcon type="extras" />
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>
|
||||
{line.name}
|
||||
{line.subName && <span> · {line.subName}</span>}
|
||||
{line.qty > 1 && <span style={{ color: '#f59e0b', marginLeft: 4, fontWeight: 700 }}>×{line.qty}</span>}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{sec.type === 'removed' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||||
<SectionIcon type="removed" />
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>Χωρίς {line.name}</span>
|
||||
</div>
|
||||
))}
|
||||
{sec.type === 'note' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 7 }}>
|
||||
<SectionIcon type="note" />
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', lineHeight: 1.4, flex: 1, whiteSpace: 'pre-wrap' }}>{line.name}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── KDS badge/icon renderer ───────────────────────────────────────────────────
|
||||
|
||||
function KdsBadge({ kdsColor, kdsDisplayStyle }) {
|
||||
if (!kdsColor?.label) return null
|
||||
if (kdsDisplayStyle === 'icon' && kdsColor.dot) {
|
||||
return (
|
||||
<span style={{
|
||||
width: 8, height: 8, borderRadius: '50%',
|
||||
background: kdsColor.dot, flexShrink: 0, display: 'inline-block',
|
||||
}} title={kdsColor.label} />
|
||||
)
|
||||
}
|
||||
return (
|
||||
<span style={{
|
||||
fontSize: 9, fontWeight: 800, letterSpacing: 0.4,
|
||||
color: kdsColor.textColor,
|
||||
borderRadius: 3, padding: '1px 5px',
|
||||
border: `1px solid ${kdsColor.textColor}60`,
|
||||
flexShrink: 0,
|
||||
}}>{kdsColor.label}</span>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Price event label helpers ─────────────────────────────────────────────────
|
||||
|
||||
const PRICING_EVENT_STYLE = {
|
||||
modifier_applied: { color: '#60a5fa', label: null }, // label comes from modifier_name
|
||||
waiter_discount: { color: '#c084fc', label: 'Έκπτωση' },
|
||||
free_item_added: { color: '#4ade80', label: 'Δωρεάν' },
|
||||
deal_offer_accepted: { color: '#4ade80', label: null }, // label from deal_name
|
||||
}
|
||||
|
||||
function PricingRows({ events, layout, nameIndent = 12 }) {
|
||||
const rows = events.filter(ev =>
|
||||
ev.event_type === 'modifier_applied' ||
|
||||
ev.event_type === 'waiter_discount' ||
|
||||
ev.event_type === 'free_item_added'
|
||||
)
|
||||
if (rows.length === 0) return null
|
||||
|
||||
// Match OptionsPanel container padding: section divider + inner padding
|
||||
return (
|
||||
<div>
|
||||
<div style={{ margin: `0 12px`, height: 1, background: 'var(--border)' }} />
|
||||
<div style={{ padding: `4px 12px 4px ${nameIndent}px`, display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||||
{rows.map((ev, i) => {
|
||||
const evStyle = PRICING_EVENT_STYLE[ev.event_type] || { color: '#94a3b8', label: ev.event_type }
|
||||
const label = ev.modifier_name || ev.deal_name || evStyle.label || ev.event_type
|
||||
const delta = ev.delta_amount
|
||||
const afterPrice = ev.price_after
|
||||
|
||||
return (
|
||||
<div key={i} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" style={{ flexShrink: 0 }}>
|
||||
<circle cx="9" cy="9" r="2" stroke={evStyle.color} strokeWidth="2"/>
|
||||
<circle cx="15" cy="15" r="2" stroke={evStyle.color} strokeWidth="2"/>
|
||||
<path d="M5 19L19 5" stroke={evStyle.color} strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
<span style={{ fontSize: 12, color: evStyle.color, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', lineHeight: 1.4 }}>
|
||||
{label}
|
||||
</span>
|
||||
{delta != null && (
|
||||
<span style={{ fontSize: 12, color: evStyle.color, fontWeight: 700, flexShrink: 0, marginLeft: 8 }}>
|
||||
{delta > 0 ? '+' : ''}{delta.toFixed(2)} €
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Small badge shown on the main item row to hint that pricing changes exist
|
||||
function PricingBadge({ events }) {
|
||||
if (!events || events.length === 0) return null
|
||||
const hasDiscount = events.some(ev => ev.event_type === 'waiter_discount')
|
||||
const hasModifier = events.some(ev => ev.event_type === 'modifier_applied')
|
||||
const hasFree = events.some(ev => ev.event_type === 'free_item_added')
|
||||
|
||||
const icons = []
|
||||
if (hasModifier) icons.push(
|
||||
<svg key="mod" width="10" height="10" viewBox="0 0 24 24" fill="none" title="Τροποποιητής">
|
||||
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="#60a5fa" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
)
|
||||
if (hasDiscount) icons.push(
|
||||
<svg key="disc" width="10" height="10" viewBox="0 0 24 24" fill="none" title="Έκπτωση">
|
||||
<circle cx="9" cy="9" r="2" stroke="#c084fc" strokeWidth="2"/>
|
||||
<circle cx="15" cy="15" r="2" stroke="#c084fc" strokeWidth="2"/>
|
||||
<path d="M5 19L19 5" stroke="#c084fc" strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
)
|
||||
if (hasFree) icons.push(
|
||||
<svg key="free" width="10" height="10" viewBox="0 0 24 24" fill="none" title="Δωρεάν">
|
||||
<path d="M20 12v10H4V12M22 7H2v5h20V7z" stroke="#4ade80" strokeWidth="2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
)
|
||||
|
||||
if (icons.length === 0) return null
|
||||
return (
|
||||
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 2, marginLeft: 3 }}>
|
||||
{icons}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// Deal badge on items that triggered or were added by a deal
|
||||
function DealBadge({ item }) {
|
||||
if (item.deal_id) {
|
||||
return (
|
||||
<span style={{
|
||||
fontSize: 9, fontWeight: 700, padding: '1px 5px', borderRadius: 4,
|
||||
background: 'rgba(167,139,250,0.15)', color: '#a78bfa',
|
||||
border: '1px solid rgba(167,139,250,0.4)', flexShrink: 0, letterSpacing: 0.3,
|
||||
}}>
|
||||
ΔΩΡΕΑΝ
|
||||
</span>
|
||||
)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function MergedBadge({ item }) {
|
||||
if (!item._isMerged) return null
|
||||
return (
|
||||
<span style={{
|
||||
fontSize: 9, fontWeight: 700, padding: '1px 5px', borderRadius: 4,
|
||||
background: 'rgba(99,102,241,0.15)', color: '#a5b4fc',
|
||||
border: '1px solid rgba(99,102,241,0.35)', flexShrink: 0, letterSpacing: 0.3,
|
||||
}}>
|
||||
∑{item._sourceIds?.length}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// ── ItemRow ───────────────────────────────────────────────────────────────────
|
||||
|
||||
function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast }) {
|
||||
function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast, kdsDisplayStyle, orderItemLayout, waiterMap, courses, priceEvents }) {
|
||||
const isPaid = item.status === 'paid'
|
||||
const isCancelled = item.status === 'cancelled'
|
||||
const effectiveKds = item.kds_status || 'pending'
|
||||
const isServed = effectiveKds === 'served'
|
||||
const kdsColor = !isCancelled && !isServed ? KDS_COLORS[effectiveKds] : null
|
||||
|
||||
const sections = buildSections(item)
|
||||
const hasDetails = sections.length > 0
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
|
||||
// Long-press detection
|
||||
const pressTimer = useRef(null)
|
||||
const didLongPress = useRef(false)
|
||||
const touchStartPos = useRef({ x: 0, y: 0 })
|
||||
|
||||
const canSelect = selectable && !isCancelled
|
||||
|
||||
function handleTouchStart(e) {
|
||||
if (!selectable || isPaid || isCancelled || !onLongPress) return
|
||||
if (!canSelect || !onLongPress) return
|
||||
didLongPress.current = false
|
||||
touchStartPos.current = { x: e.touches[0].clientX, y: e.touches[0].clientY }
|
||||
pressTimer.current = setTimeout(() => {
|
||||
@@ -125,98 +352,292 @@ function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast })
|
||||
|
||||
function handleBodyClick() {
|
||||
if (didLongPress.current) { didLongPress.current = false; return }
|
||||
if (selectable && !isPaid && !isCancelled) onToggle(item.id)
|
||||
if (canSelect) onToggle(item.id)
|
||||
}
|
||||
|
||||
const nameColor = !isCancelled && !isServed ? kdsColor?.textColor : null
|
||||
const totalPrice = fmtPrice(((item.unit_price ?? 0) + (item.price_adjustment ?? 0)) * item.quantity)
|
||||
const unitPriceAdjusted = (item.unit_price ?? 0) + (item.price_adjustment ?? 0)
|
||||
// Cast to boolean so JSX never renders the raw number 0
|
||||
const hasPriceAdj = !!(item.price_adjustment && item.price_adjustment !== 0)
|
||||
|
||||
const courseBadge = item.course_id != null && courses?.length > 0 ? (() => {
|
||||
const course = courses.find(c => c.id === item.course_id)
|
||||
if (!course) return null
|
||||
return (
|
||||
<span style={{
|
||||
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||||
width: 16, height: 16, borderRadius: '50%',
|
||||
background: course.color, color: '#fff',
|
||||
fontSize: 9, fontWeight: 700, flexShrink: 0, marginLeft: 4,
|
||||
}}>
|
||||
{courses.indexOf(course) + 1}
|
||||
</span>
|
||||
)
|
||||
})() : null
|
||||
|
||||
const nameEl = (
|
||||
<span
|
||||
className={[
|
||||
'order-item__name',
|
||||
isCancelled ? 'order-item__name--cancelled' : '',
|
||||
isServed ? 'order-item__name--served' : '',
|
||||
effectiveKds === 'done' && !isCancelled && !isServed ? 'kds-ready-flash-text' : '',
|
||||
].filter(Boolean).join(' ')}
|
||||
style={nameColor ? { color: nameColor } : undefined}
|
||||
>
|
||||
{item.product?.name || `#${item.product_id}`}
|
||||
{courseBadge}
|
||||
</span>
|
||||
)
|
||||
|
||||
const paidBadge = isPaid && !isServed ? <span className="badge badge--paid">Paid</span> : null
|
||||
const cancelledBadge = isCancelled ? <span className="badge badge--cancelled">Cancelled</span> : null
|
||||
const draftBadge = !isPaid && !isCancelled && !item.printed
|
||||
? <span className="badge badge--draft" title="Δεν εκτυπώθηκε ακόμα">⏳</span>
|
||||
: null
|
||||
|
||||
// Whole-card click+touch handlers on the outer wrapper
|
||||
const cardHandlers = {
|
||||
onClick: handleBodyClick,
|
||||
onTouchStart: handleTouchStart,
|
||||
onTouchMove: handleTouchMove,
|
||||
onTouchEnd: handleTouchEnd,
|
||||
onTouchCancel: handleTouchEnd,
|
||||
}
|
||||
|
||||
const cardClass = [
|
||||
'order-item',
|
||||
isPaid && isServed ? 'order-item--paid' : '',
|
||||
isCancelled ? 'order-item--cancelled' : '',
|
||||
selectable && selected ? 'order-item--selected' : '',
|
||||
isLast ? 'order-item--last' : '',
|
||||
].filter(Boolean).join(' ')
|
||||
|
||||
// Indent of secondary rows — lines up with the start of the item name
|
||||
const nameIndent = selectable && !isCancelled ? 44 : 12
|
||||
|
||||
// ── COMPACT ──────────────────────────────────────────────────────────────────
|
||||
const hasPricingRows = priceEvents && priceEvents.some(ev => ['modifier_applied','waiter_discount','free_item_added'].includes(ev.event_type))
|
||||
const [pricingExpanded, setPricingExpanded] = useState(false)
|
||||
|
||||
if (orderItemLayout === 'compact') {
|
||||
return (
|
||||
<div
|
||||
className={cardClass}
|
||||
style={{ userSelect: 'none', position: 'relative', cursor: canSelect ? 'pointer' : 'default' }}
|
||||
{...cardHandlers}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '7px 12px' }}>
|
||||
{selectable && !isCancelled && (
|
||||
<span style={{ color: selected ? '#f59e0b' : '#475569', flexShrink: 0, fontSize: 16 }}>
|
||||
{selected ? '☑' : '☐'}
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
{nameEl}
|
||||
<MergedBadge item={item} />
|
||||
<DealBadge item={item} />
|
||||
<PricingBadge events={priceEvents} />
|
||||
{(hasDetails || hasPricingRows) && (
|
||||
<ExpandArrow
|
||||
expanded={expanded || pricingExpanded}
|
||||
onClick={() => {
|
||||
const next = !(expanded || pricingExpanded)
|
||||
if (hasDetails) setExpanded(next)
|
||||
if (hasPricingRows) setPricingExpanded(next)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{paidBadge}
|
||||
{cancelledBadge}
|
||||
{draftBadge}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<KdsBadge kdsColor={kdsColor} kdsDisplayStyle={kdsDisplayStyle} />
|
||||
<span className="order-item__qty">{fmtQty(item.quantity, item.unit_type)}</span>
|
||||
<span className="order-item__price" style={hasPriceAdj ? { color: '#60a5fa' } : undefined}>
|
||||
{totalPrice}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{(expanded || pricingExpanded) && hasPricingRows && (
|
||||
<PricingRows events={priceEvents} layout="compact" nameIndent={nameIndent} />
|
||||
)}
|
||||
{expanded && hasDetails && <OptionsPanel sections={sections} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── EXPANDED ─────────────────────────────────────────────────────────────────
|
||||
if (orderItemLayout === 'expanded') {
|
||||
return (
|
||||
<div
|
||||
className={cardClass}
|
||||
style={{ userSelect: 'none', position: 'relative', cursor: canSelect ? 'pointer' : 'default' }}
|
||||
{...cardHandlers}
|
||||
>
|
||||
{/* Row 1: checkbox · name · badges · expand arrow · KDS badge */}
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 12px 2px' }}>
|
||||
{selectable && !isCancelled && (
|
||||
<span style={{ color: selected ? '#f59e0b' : '#475569', flexShrink: 0, fontSize: 16 }}>
|
||||
{selected ? '☑' : '☐'}
|
||||
</span>
|
||||
)}
|
||||
<div style={{ flex: 1, minWidth: 0, display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
{nameEl}
|
||||
<DealBadge item={item} />
|
||||
<PricingBadge events={priceEvents} />
|
||||
{(hasDetails || hasPricingRows) && (
|
||||
<ExpandArrow
|
||||
expanded={expanded || pricingExpanded}
|
||||
onClick={() => {
|
||||
const next = !(expanded || pricingExpanded)
|
||||
if (hasDetails) setExpanded(next)
|
||||
if (hasPricingRows) setPricingExpanded(next)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{paidBadge}
|
||||
{cancelledBadge}
|
||||
{draftBadge}
|
||||
</div>
|
||||
<KdsBadge kdsColor={kdsColor} kdsDisplayStyle={kdsDisplayStyle} />
|
||||
</div>
|
||||
|
||||
{/* Row 2: unit price · qty · total */}
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center',
|
||||
padding: `2px 12px ${hasPricingRows && !pricingExpanded ? 2 : 8}px ${nameIndent}px`,
|
||||
}}>
|
||||
<span style={{ fontSize: 12, color: 'var(--muted)', flex: 1 }}>
|
||||
{hasPriceAdj
|
||||
? <><span style={{ textDecoration: 'line-through', marginRight: 4, opacity: 0.6 }}>{fmtPrice(item.unit_price)}</span><span style={{ color: '#60a5fa' }}>{fmtPrice(unitPriceAdjusted)}</span></>
|
||||
: fmtPrice(unitPriceAdjusted)
|
||||
}
|
||||
</span>
|
||||
<span className="order-item__qty" style={{ textAlign: 'center', minWidth: 48 }}>
|
||||
{fmtQty(item.quantity, item.unit_type)}
|
||||
</span>
|
||||
<span className="order-item__price" style={{ minWidth: 64, textAlign: 'right', ...(hasPriceAdj ? { color: '#60a5fa' } : {}) }}>
|
||||
{totalPrice}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{(pricingExpanded || expanded) && hasPricingRows && <PricingRows events={priceEvents} layout="expanded" nameIndent={nameIndent} />}
|
||||
{expanded && hasDetails && <OptionsPanel sections={sections} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── FULLY DETAILED ────────────────────────────────────────────────────────────
|
||||
const addedByName = waiterMap?.[item.added_by] ?? null
|
||||
const paidByName = waiterMap?.[item.paid_by] ?? null
|
||||
const addedAtFmt = fmtDateTime(item.added_at)
|
||||
const paidAtFmt = fmtDateTime(item.paid_at)
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`order-item ${isPaid ? 'order-item--paid' : ''} ${isCancelled ? 'order-item--cancelled' : ''} ${selectable && selected ? 'order-item--selected' : ''} ${isLast ? 'order-item--last' : ''}`}
|
||||
style={{ userSelect: 'none' }}
|
||||
className={cardClass}
|
||||
style={{ userSelect: 'none', position: 'relative', cursor: canSelect ? 'pointer' : 'default' }}
|
||||
{...cardHandlers}
|
||||
>
|
||||
{/* Main row — click to select */}
|
||||
<div
|
||||
onClick={handleBodyClick}
|
||||
onTouchStart={handleTouchStart}
|
||||
onTouchMove={handleTouchMove}
|
||||
onTouchEnd={handleTouchEnd}
|
||||
onTouchCancel={handleTouchEnd}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 8,
|
||||
padding: '10px 12px',
|
||||
cursor: selectable && !isPaid && !isCancelled ? 'pointer' : 'default',
|
||||
}}
|
||||
>
|
||||
{/* Selection checkbox */}
|
||||
{selectable && !isPaid && !isCancelled && (
|
||||
{/* Row 1 */}
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 12px 2px' }}>
|
||||
{selectable && !isCancelled && (
|
||||
<span style={{ color: selected ? '#f59e0b' : '#475569', flexShrink: 0, fontSize: 16 }}>
|
||||
{selected ? '☑' : '☐'}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Name + badges */}
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
<span className="order-item__name">{item.product?.name || `#${item.product_id}`}</span>
|
||||
{isPaid && <span className="badge badge--paid">Paid</span>}
|
||||
{isCancelled && <span className="badge badge--cancelled">Cancelled</span>}
|
||||
{!isPaid && !isCancelled && !item.printed && (
|
||||
<span className="badge badge--draft" title="Δεν εκτυπώθηκε ακόμα">⏳</span>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ flex: 1, minWidth: 0, display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
{nameEl}
|
||||
<DealBadge item={item} />
|
||||
<PricingBadge events={priceEvents} />
|
||||
{paidBadge}
|
||||
{cancelledBadge}
|
||||
{draftBadge}
|
||||
</div>
|
||||
|
||||
{/* Qty + price */}
|
||||
<span className="order-item__qty">×{item.quantity}</span>
|
||||
<span className="order-item__price">{fmtPrice(item.unit_price * item.quantity)}</span>
|
||||
|
||||
{/* Expand arrow — only if there are details; stops propagation so it doesn't trigger select */}
|
||||
{hasDetails && (
|
||||
<button
|
||||
onClick={e => { e.stopPropagation(); setExpanded(v => !v) }}
|
||||
style={{
|
||||
background: 'none', border: 'none', padding: 4, cursor: 'pointer',
|
||||
color: 'var(--muted)', display: 'flex', alignItems: 'center', flexShrink: 0,
|
||||
}}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"
|
||||
style={{ transform: `rotate(${expanded ? 180 : 0}deg)`, transition: 'transform 180ms' }}>
|
||||
<path d="M6 9L12 15L18 9" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
<KdsBadge kdsColor={kdsColor} kdsDisplayStyle={kdsDisplayStyle} />
|
||||
</div>
|
||||
|
||||
{/* Expanded details */}
|
||||
{expanded && hasDetails && (
|
||||
<div style={{ paddingBottom: 8 }}>
|
||||
{sections.map((sec, si) => (
|
||||
<div key={si}>
|
||||
<div style={{ margin: '0 12px', height: 1, background: 'var(--border)' }} />
|
||||
<div style={{ padding: '5px 12px 2px', display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
{/* Row 2 — pricing */}
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center',
|
||||
padding: `2px 12px 6px ${nameIndent}px`,
|
||||
}}>
|
||||
<span style={{ fontSize: 12, color: 'var(--muted)', flex: 1 }}>
|
||||
{hasPriceAdj
|
||||
? <><span style={{ textDecoration: 'line-through', marginRight: 4, opacity: 0.6 }}>{fmtPrice(item.unit_price)}</span><span style={{ color: '#60a5fa' }}>{fmtPrice(unitPriceAdjusted)}</span></>
|
||||
: fmtPrice(unitPriceAdjusted)
|
||||
}
|
||||
</span>
|
||||
<span className="order-item__qty" style={{ textAlign: 'center', minWidth: 48 }}>
|
||||
{fmtQty(item.quantity, item.unit_type)}
|
||||
</span>
|
||||
<span className="order-item__price" style={{ minWidth: 64, textAlign: 'right', ...(hasPriceAdj ? { color: '#60a5fa' } : {}) }}>
|
||||
{totalPrice}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{hasPricingRows && <PricingRows events={priceEvents} layout="full" nameIndent={nameIndent} />}
|
||||
|
||||
{/* Detail rows */}
|
||||
<div style={{
|
||||
padding: `0 12px 8px ${nameIndent}px`,
|
||||
display: 'flex', flexDirection: 'column', gap: 3,
|
||||
}}>
|
||||
<div style={{ height: 1, background: 'var(--border)', marginBottom: 4 }} />
|
||||
|
||||
{/* Ordered by */}
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span style={{ fontSize: 11, color: 'var(--muted)', minWidth: 90 }}>Παραγγέλθηκε</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 11, color: 'var(--muted)', textAlign: 'right' }}>
|
||||
{addedByName && addedAtFmt ? `${addedByName} · ${addedAtFmt}` : addedByName || addedAtFmt || '—'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Paid by — only if paid */}
|
||||
{isPaid && (
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span style={{ fontSize: 11, color: 'var(--muted)', minWidth: 90 }}>Πληρώθηκε</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 11, color: 'var(--muted)', textAlign: 'right' }}>
|
||||
{paidByName && paidAtFmt ? `${paidByName} · ${paidAtFmt}` : paidByName || paidAtFmt || '—'}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Options — inline, no expand needed */}
|
||||
{hasDetails && (
|
||||
<div style={{ marginTop: 2 }}>
|
||||
{sections.map((sec, si) => (
|
||||
<div key={si} style={{ display: 'flex', flexDirection: 'column', gap: 2, marginTop: 2 }}>
|
||||
{sec.type === 'prefs' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 7 }}>
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 6 }}>
|
||||
<SectionIcon type="prefs" />
|
||||
<span style={{ fontSize: 12, lineHeight: 1.4, flex: 1 }}>
|
||||
{line.setName && (
|
||||
<span style={{ color: 'var(--muted)', display: 'block', fontSize: 11 }}>{line.setName}</span>
|
||||
)}
|
||||
<span style={{ color: 'var(--text)' }}>{line.values.join(' · ')}</span>
|
||||
<span style={{ fontSize: 11, lineHeight: 1.4, flex: 1, color: 'var(--text)' }}>
|
||||
{line.setName && <span style={{ color: 'var(--muted)' }}>{line.setName}: </span>}
|
||||
{line.values.join(' · ')}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{sec.type === 'quick' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<SectionIcon type="quick" />
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>
|
||||
<span style={{ fontSize: 11, color: 'var(--text)', flex: 1 }}>
|
||||
{line.name}
|
||||
{line._qty > 1 && <span style={{ color: '#f59e0b', marginLeft: 4, fontWeight: 700 }}>×{line._qty}</span>}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{sec.type === 'extras' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<SectionIcon type="extras" />
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>
|
||||
<span style={{ fontSize: 11, color: 'var(--text)', flex: 1 }}>
|
||||
{line.name}
|
||||
{line.subName && <span> · {line.subName}</span>}
|
||||
{line.qty > 1 && <span style={{ color: '#f59e0b', marginLeft: 4, fontWeight: 700 }}>×{line.qty}</span>}
|
||||
@@ -224,34 +645,36 @@ function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast })
|
||||
</div>
|
||||
))}
|
||||
{sec.type === 'removed' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<SectionIcon type="removed" />
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>Χωρίς {line.name}</span>
|
||||
<span style={{ fontSize: 11, color: 'var(--text)', flex: 1 }}>Χωρίς {line.name}</span>
|
||||
</div>
|
||||
))}
|
||||
{sec.type === 'note' && sec.lines.map((line, li) => (
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 7 }}>
|
||||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 6 }}>
|
||||
<SectionIcon type="note" />
|
||||
<span style={{ fontSize: 12, color: 'var(--text)', lineHeight: 1.4, flex: 1, whiteSpace: 'pre-wrap' }}>{line.name}</span>
|
||||
<span style={{ fontSize: 11, color: 'var(--text)', lineHeight: 1.4, flex: 1, whiteSpace: 'pre-wrap' }}>{line.name}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem }) {
|
||||
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem, waiterMap, courses = [], priceEventsMap = {} }) {
|
||||
const kdsDisplayStyle = useTableViewStore(s => s.kdsDisplayStyle || 'badge')
|
||||
const orderItemLayout = useTableViewStore(s => s.orderItemLayout || 'compact')
|
||||
const activeItems = order.items?.filter(i => i.status !== 'cancelled') || []
|
||||
const total = activeItems
|
||||
.filter(i => i.status !== 'cancelled')
|
||||
.reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
.reduce((s, i) => s + ((i.unit_price ?? 0) + (i.price_adjustment ?? 0)) * i.quantity, 0)
|
||||
const paidTotal = activeItems
|
||||
.filter(i => i.status === 'paid')
|
||||
.reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
.reduce((s, i) => s + ((i.unit_price ?? 0) + (i.price_adjustment ?? 0)) * i.quantity, 0)
|
||||
|
||||
return (
|
||||
<div className="order-summary">
|
||||
@@ -265,6 +688,11 @@ export default function OrderSummary({ order, selectable = false, selectedIds =
|
||||
onToggle={onToggle}
|
||||
onLongPress={onLongPressItem}
|
||||
isLast={idx === activeItems.length - 1}
|
||||
kdsDisplayStyle={kdsDisplayStyle}
|
||||
orderItemLayout={orderItemLayout}
|
||||
waiterMap={waiterMap}
|
||||
courses={courses}
|
||||
priceEvents={priceEventsMap[item.id] ?? []}
|
||||
/>
|
||||
))}
|
||||
<div className="order-summary__total">
|
||||
@@ -272,13 +700,13 @@ export default function OrderSummary({ order, selectable = false, selectedIds =
|
||||
<span>{fmtPrice(total)}</span>
|
||||
</div>
|
||||
{paidTotal > 0 && paidTotal < total && (
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', paddingBottom: 8, fontSize: 13, color: '#64748b' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', padding: '0 12px 8px', fontSize: 13, color: '#64748b' }}>
|
||||
<span>Πληρωμένο</span>
|
||||
<span style={{ color: '#22c55e' }}>{fmtPrice(paidTotal)}</span>
|
||||
</div>
|
||||
)}
|
||||
{paidTotal > 0 && paidTotal < total && (
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', paddingBottom: 8, fontSize: 13, color: '#94a3b8' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', padding: '0 12px 8px', fontSize: 13, color: '#94a3b8' }}>
|
||||
<span>Εκκρεμεί</span>
|
||||
<span style={{ color: '#f59e0b', fontWeight: 700 }}>{fmtPrice(total - paidTotal)}</span>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
import { useState } from 'react'
|
||||
|
||||
const _UNIT_LABELS = { kg: 'kg', liter: 'L', gram: 'g', ml: 'mL' }
|
||||
function fmtQty(qty, unitType) {
|
||||
const label = _UNIT_LABELS[unitType]
|
||||
if (!label) return `×${qty}`
|
||||
if (unitType === 'kg' || unitType === 'liter') return `${Number(qty).toFixed(1)}${label}`
|
||||
return `${qty}${label}`
|
||||
}
|
||||
function fmtEUR(v) { return Number(v || 0).toFixed(2) + ' €' }
|
||||
|
||||
// Flatten selected_options into readable lines
|
||||
function describeOptions(selected_options) {
|
||||
if (!selected_options?.length) return []
|
||||
return selected_options.map(o => {
|
||||
let s = o.name || ''
|
||||
if (o.price_delta && Math.abs(o.price_delta) > 0.001) {
|
||||
s += ` (${o.price_delta > 0 ? '+' : ''}${o.price_delta.toFixed(2)} €)`
|
||||
}
|
||||
return s
|
||||
}).filter(Boolean)
|
||||
}
|
||||
|
||||
function CartItemSummaryRow({ item, product, onEdit }) {
|
||||
const price = (item.unit_price ?? product?.base_price ?? 0) * item.quantity
|
||||
const opts = describeOptions(item.selected_options)
|
||||
const removed = item.removed_ingredients || []
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
background: 'var(--bg2)', borderRadius: 14, padding: '12px 14px',
|
||||
border: '1px solid var(--border)',
|
||||
}}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 8 }}>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'baseline', gap: 7 }}>
|
||||
<span style={{ fontSize: 15, fontWeight: 700, color: 'var(--text)' }}>{product?.name ?? `#${item.product_id}`}</span>
|
||||
<span style={{ fontSize: 13, color: 'var(--muted)', fontWeight: 500 }}>{fmtQty(item.quantity, item.unit_type)}</span>
|
||||
</div>
|
||||
{opts.length > 0 && (
|
||||
<div style={{ marginTop: 5, display: 'flex', flexWrap: 'wrap', gap: '3px 8px' }}>
|
||||
{opts.map((o, i) => (
|
||||
<span key={i} style={{ fontSize: 12, color: '#f59e0b', fontWeight: 600, background: 'rgba(245,158,11,0.08)', borderRadius: 6, padding: '1px 6px' }}>{o}</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{removed.length > 0 && (
|
||||
<div style={{ marginTop: 4, display: 'flex', flexWrap: 'wrap', gap: '3px 8px' }}>
|
||||
{removed.map((r, i) => (
|
||||
<span key={i} style={{ fontSize: 12, color: '#ef4444', fontWeight: 600, background: 'rgba(239,68,68,0.08)', borderRadius: 6, padding: '1px 6px' }}>− {r}</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{item.notes && (
|
||||
<div style={{ marginTop: 5, fontSize: 12, color: 'var(--muted)', fontStyle: 'italic', background: 'var(--bg3)', borderRadius: 7, padding: '4px 8px' }}>
|
||||
"{item.notes}"
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: 8, flexShrink: 0 }}>
|
||||
<span style={{ fontSize: 15, fontWeight: 700, color: 'var(--text)', fontVariantNumeric: 'tabular-nums' }}>{fmtEUR(price)}</span>
|
||||
{onEdit && (
|
||||
<button
|
||||
onClick={onEdit}
|
||||
style={{ background: 'var(--bg3)', border: '1px solid var(--border)', borderRadius: 7, padding: '3px 10px', fontSize: 12, color: 'var(--muted)', cursor: 'pointer', fontWeight: 600 }}
|
||||
>
|
||||
Επεξεργασία
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function OrderSummaryModal({ cart, products, orderNote, setOrderNote, onSend, onClose, sending }) {
|
||||
const [noteEditing, setNoteEditing] = useState(false)
|
||||
|
||||
const total = cart.reduce((s, item) => s + (item.unit_price ?? 0) * item.quantity, 0)
|
||||
|
||||
function getProduct(id) { return products.find(p => p.id === id) }
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Backdrop */}
|
||||
<div
|
||||
onClick={onClose}
|
||||
style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.65)', zIndex: 200 }}
|
||||
/>
|
||||
|
||||
{/* Sheet */}
|
||||
<div style={{
|
||||
position: 'fixed', inset: 0,
|
||||
background: 'var(--bg)',
|
||||
zIndex: 201,
|
||||
display: 'flex', flexDirection: 'column',
|
||||
animation: 'summarySlideUp 260ms cubic-bezier(0.32,0.72,0,1)',
|
||||
}}>
|
||||
{/* Header */}
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
||||
padding: '14px 16px', borderBottom: '1px solid var(--border)', flexShrink: 0,
|
||||
}}>
|
||||
<div>
|
||||
<div style={{ fontSize: 17, fontWeight: 800, color: 'var(--text)' }}>Επισκόπηση Παραγγελίας</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--muted)', marginTop: 1 }}>{cart.length} {cart.length === 1 ? 'προϊόν' : 'προϊόντα'} · {fmtEUR(total)}</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={onClose}
|
||||
style={{ background: 'var(--bg3)', border: 'none', borderRadius: '50%', width: 36, height: 36, display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', color: 'var(--text)' }}
|
||||
>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M6 6L18 18M6 18L18 6" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Item list */}
|
||||
<div style={{ flex: 1, overflowY: 'auto', padding: '12px 12px 0' }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{cart.map(item => (
|
||||
<CartItemSummaryRow
|
||||
key={item._key}
|
||||
item={item}
|
||||
product={getProduct(item.product_id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Order note section */}
|
||||
<div style={{ marginTop: 16, marginBottom: 8 }}>
|
||||
<div style={{ fontSize: 11, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.7, marginBottom: 8 }}>
|
||||
Σημείωση Παραγγελίας
|
||||
</div>
|
||||
{noteEditing ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
<textarea
|
||||
autoFocus
|
||||
value={orderNote}
|
||||
onChange={e => setOrderNote(e.target.value)}
|
||||
placeholder="Σημείωση για ολόκληρη την παραγγελία…"
|
||||
rows={3}
|
||||
style={{
|
||||
width: '100%', resize: 'none', padding: '10px 12px',
|
||||
background: 'rgba(245,158,11,0.07)', border: '1.5px solid rgba(245,158,11,0.35)',
|
||||
borderRadius: 10, fontSize: 14, color: 'var(--text)', lineHeight: 1.5,
|
||||
outline: 'none', boxSizing: 'border-box', fontFamily: 'inherit',
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
onClick={() => setNoteEditing(false)}
|
||||
style={{ alignSelf: 'flex-end', background: 'none', border: 'none', fontSize: 12, fontWeight: 700, color: 'var(--accent)', cursor: 'pointer' }}
|
||||
>
|
||||
Αποθήκευση
|
||||
</button>
|
||||
</div>
|
||||
) : orderNote ? (
|
||||
<div
|
||||
onClick={() => setNoteEditing(true)}
|
||||
style={{ cursor: 'pointer', padding: '10px 13px', background: 'rgba(245,158,11,0.09)', border: '1.5px solid rgba(245,158,11,0.3)', borderRadius: 10, fontSize: 14, color: 'var(--text)', lineHeight: 1.5, whiteSpace: 'pre-wrap', position: 'relative' }}
|
||||
>
|
||||
{orderNote}
|
||||
<span style={{ position: 'absolute', top: 8, right: 10, fontSize: 12, color: '#f59e0b', fontWeight: 700 }}>✎</span>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setNoteEditing(true)}
|
||||
style={{
|
||||
width: '100%', padding: '10px 13px',
|
||||
background: 'var(--bg2)', border: '1.5px dashed var(--border)',
|
||||
borderRadius: 10, fontSize: 13, color: 'var(--muted)',
|
||||
cursor: 'pointer', textAlign: 'left', display: 'flex', alignItems: 'center', gap: 7,
|
||||
}}
|
||||
>
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none"><path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/><path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/></svg>
|
||||
Προσθήκη σημείωσης παραγγελίας
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Total */}
|
||||
<div style={{ marginTop: 12, marginBottom: 4, display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 4px', borderTop: '1px solid var(--border)' }}>
|
||||
<span style={{ fontSize: 14, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.6 }}>Σύνολο</span>
|
||||
<span style={{ fontSize: 20, fontWeight: 800, color: 'var(--text)', fontVariantNumeric: 'tabular-nums' }}>{fmtEUR(total)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer — Send button */}
|
||||
<div style={{ padding: '12px 12px 28px', borderTop: '1px solid var(--border)', flexShrink: 0 }}>
|
||||
<button
|
||||
className="btn btn--primary btn--lg"
|
||||
style={{ width: '100%' }}
|
||||
onClick={onSend}
|
||||
disabled={sending}
|
||||
>
|
||||
{sending ? 'Αποστολή…' : `ΑΠΟΣΤΟΛΗ (${cart.length})`}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
@keyframes summarySlideUp {
|
||||
from { transform: translateY(100%); opacity: 0; }
|
||||
to { transform: translateY(0); opacity: 1; }
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
import { useState } from 'react'
|
||||
import { useState, useRef, useCallback, useEffect } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import OrderDrawer from './OrderDrawer'
|
||||
import useWaiterFavoritesStore from '../store/waiterFavoritesStore'
|
||||
|
||||
const FAV_CAT_ID = '__favorites__'
|
||||
const SVC_CAT_ID = '__service__'
|
||||
|
||||
function CategoriesIcon({ width = 20, height = 20 }) {
|
||||
return (
|
||||
@@ -22,35 +27,375 @@ function hexToRgba(hex, alpha) {
|
||||
return `rgba(${r},${g},${b},${alpha})`
|
||||
}
|
||||
|
||||
function ProductGrid({ products, onOpen }) {
|
||||
// A preference set blocks QuickAdd if it has NO default choice set
|
||||
function productAllowsQuickAdd(product) {
|
||||
if (!product.quick_add_enabled) return false
|
||||
const sets = product.preference_sets || []
|
||||
for (const ps of sets) {
|
||||
if (ps.default_choice_id == null) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Decimal unit types (add 1.0 instead of 1)
|
||||
const DECIMAL_UNITS = new Set(['kg', 'liter', 'gram', 'ml'])
|
||||
|
||||
function buildQuickAddItem(product) {
|
||||
const qty = DECIMAL_UNITS.has(product.unit_type) ? 1.0 : 1
|
||||
|
||||
// Auto-resolve preference sets via their default choice
|
||||
const selectedOptions = []
|
||||
for (const ps of (product.preference_sets || [])) {
|
||||
const defaultChoice = ps.choices?.find(c => c.id === ps.default_choice_id)
|
||||
if (defaultChoice) {
|
||||
selectedOptions.push({ id: defaultChoice.id, name: defaultChoice.name, price_delta: defaultChoice.extra_cost ?? 0 })
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
product_id: product.id,
|
||||
quantity: qty,
|
||||
unit_type: product.unit_type || 'piece',
|
||||
unit_price: product.base_price,
|
||||
notes: '',
|
||||
selected_options: selectedOptions,
|
||||
removed_ingredients: [],
|
||||
}
|
||||
}
|
||||
|
||||
// ── Product Detail Modal (long-press) ─────────────────────────────────────────
|
||||
function ProductDetailModal({ product, onClose }) {
|
||||
// Dismiss on Escape
|
||||
useEffect(() => {
|
||||
function onKey(e) { if (e.key === 'Escape') onClose() }
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [onClose])
|
||||
|
||||
const initials = product.name.trim().split(/\s+/).slice(0, 2).map(w => w[0]).join('').toUpperCase()
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
onClick={onClose}
|
||||
style={{
|
||||
position: 'fixed', inset: 0,
|
||||
background: 'rgba(0,0,0,0.65)',
|
||||
zIndex: 300,
|
||||
}}
|
||||
/>
|
||||
<div style={{
|
||||
position: 'fixed',
|
||||
top: '50%', left: '50%',
|
||||
transform: 'translate(-50%, -50%)',
|
||||
zIndex: 301,
|
||||
width: 'min(88vw, 360px)',
|
||||
background: 'var(--bg)',
|
||||
borderRadius: 20,
|
||||
overflow: 'hidden',
|
||||
boxShadow: '0 20px 60px rgba(0,0,0,0.5)',
|
||||
}}>
|
||||
{/* Close button */}
|
||||
<button
|
||||
onClick={onClose}
|
||||
style={{
|
||||
position: 'absolute', top: 12, right: 12,
|
||||
width: 32, height: 32, borderRadius: '50%',
|
||||
background: 'rgba(0,0,0,0.45)',
|
||||
border: 'none', cursor: 'pointer',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
zIndex: 1,
|
||||
}}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M6 6L18 18M6 18L18 6" stroke="#fff" strokeWidth="2.2" strokeLinecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{/* Image */}
|
||||
<div style={{
|
||||
width: '100%', height: 220,
|
||||
background: 'var(--bg2)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
overflow: 'hidden',
|
||||
}}>
|
||||
{product.image_url
|
||||
? <img src={product.image_url} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
|
||||
: <span style={{ fontSize: 48, fontWeight: 800, color: 'var(--muted)', letterSpacing: -2 }}>{initials}</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div style={{ padding: '18px 20px 24px' }}>
|
||||
<div style={{ fontSize: 20, fontWeight: 800, color: 'var(--text)', lineHeight: 1.2, marginBottom: 6 }}>
|
||||
{product.name}
|
||||
</div>
|
||||
<div style={{ fontSize: 18, fontWeight: 700, color: 'var(--accent, #f59e0b)', marginBottom: product.description ? 14 : 0 }}>
|
||||
{Number(product.base_price).toFixed(2)} €
|
||||
</div>
|
||||
{product.description && (
|
||||
<div style={{
|
||||
fontSize: 14, color: 'var(--muted)', lineHeight: 1.6,
|
||||
borderTop: '1px solid var(--border)', paddingTop: 12,
|
||||
}}>
|
||||
{product.description}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// ── useLongPress ──────────────────────────────────────────────────────────────
|
||||
function useLongPress(callback, delay = 2000) {
|
||||
const timerRef = useRef(null)
|
||||
const firedRef = useRef(false)
|
||||
|
||||
const start = useCallback((e) => {
|
||||
firedRef.current = false
|
||||
timerRef.current = setTimeout(() => {
|
||||
firedRef.current = true
|
||||
callback(e)
|
||||
}, delay)
|
||||
}, [callback, delay])
|
||||
|
||||
const cancel = useCallback(() => {
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current)
|
||||
timerRef.current = null
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Return true if the long-press fired, so the click handler can skip normal open
|
||||
const didFire = useCallback(() => firedRef.current, [])
|
||||
|
||||
return { handlers: { onPointerDown: start, onPointerUp: cancel, onPointerLeave: cancel, onPointerCancel: cancel }, didFire }
|
||||
}
|
||||
|
||||
// ── Product card ──────────────────────────────────────────────────────────────
|
||||
function ProductCard({ product, onOpen, onQuickAdd, onShowDetail }) {
|
||||
const canQuickAdd = productAllowsQuickAdd(product)
|
||||
|
||||
const onDetail = useCallback(() => onShowDetail(product), [onShowDetail, product])
|
||||
const longPress = useLongPress(onDetail, 1200)
|
||||
|
||||
function handleClick(e) {
|
||||
// If a long-press just fired, don't open the drawer
|
||||
if (longPress.didFire()) return
|
||||
onOpen(product)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="product-btn"
|
||||
style={{ position: 'relative' }}
|
||||
onClick={handleClick}
|
||||
{...longPress.handlers}
|
||||
>
|
||||
<div className="product-btn__thumb">
|
||||
<div className="product-btn__thumb-inner">
|
||||
{product.image_url
|
||||
? <img src={product.image_url} alt="" className="product-btn__img" />
|
||||
: <span className="product-btn__initials">
|
||||
{product.name.trim().split(/\s+/).slice(0, 2).map(w => w[0]).join('').toUpperCase()}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div className="product-btn__info">
|
||||
<span className="product-btn__name">{product.name}</span>
|
||||
{product.tags?.length > 0 && (
|
||||
<div className="product-btn__tags">
|
||||
{product.tags.map(tag => (
|
||||
<span key={tag} className="product-tag-pill">{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<span className="product-btn__price">{Number(product.base_price).toFixed(2)} €</span>
|
||||
</div>
|
||||
|
||||
{canQuickAdd && (
|
||||
<div style={{
|
||||
flexShrink: 0,
|
||||
width: 80, display: 'flex',
|
||||
alignItems: 'center', justifyContent: 'center',
|
||||
}}>
|
||||
<button
|
||||
onPointerDown={e => e.stopPropagation()}
|
||||
onClick={e => { e.stopPropagation(); onQuickAdd(product) }}
|
||||
style={{
|
||||
width: 44, height: 44, borderRadius: '50%',
|
||||
background: 'var(--bg3)',
|
||||
border: '1.5px solid var(--border)',
|
||||
cursor: 'pointer',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
flexShrink: 0,
|
||||
}}
|
||||
>
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M12 5v14M5 12h14" stroke="var(--accent)" strokeWidth="2.8" strokeLinecap="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Service Item Card ─────────────────────────────────────────────────────────
|
||||
function ServiceItemCard({ product, customerCount, onAdd }) {
|
||||
const [qty, setQty] = useState(0)
|
||||
|
||||
function dec() { setQty(q => Math.max(0, q - 1)) }
|
||||
function inc() { setQty(q => q + 1) }
|
||||
function setToCustomerCount() { setQty(Math.max(1, customerCount ?? 1)) }
|
||||
|
||||
const hasPrice = product.base_price != null && product.base_price > 0
|
||||
|
||||
const btnBase = {
|
||||
width: 38, height: 38, borderRadius: '50%',
|
||||
border: '1.5px solid var(--border)',
|
||||
cursor: 'pointer', fontSize: 20, fontWeight: 700,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
flexShrink: 0,
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
padding: '10px 14px',
|
||||
background: 'var(--bg2)',
|
||||
borderRadius: 14,
|
||||
border: '1.5px solid var(--border)',
|
||||
display: 'flex', flexDirection: 'column', gap: 8,
|
||||
}}>
|
||||
{/* Top row: name + price */}
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
|
||||
<span style={{ fontSize: 15, fontWeight: 700, color: 'var(--text)', lineHeight: 1.2, flex: 1, minWidth: 0 }}>
|
||||
{product.name}
|
||||
</span>
|
||||
<span style={{ fontSize: 13, fontWeight: 600, color: hasPrice ? '#f59e0b' : 'var(--muted)', flexShrink: 0 }}>
|
||||
{hasPrice ? `${Number(product.base_price).toFixed(2)} €` : 'no charge'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Bottom row: stepper + count + ADD */}
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
{/* − */}
|
||||
<button
|
||||
onPointerDown={e => e.stopPropagation()}
|
||||
onClick={dec}
|
||||
style={{
|
||||
...btnBase,
|
||||
background: qty === 0 ? 'var(--bg3)' : 'rgba(245,158,11,0.15)',
|
||||
color: qty === 0 ? 'var(--muted)' : '#f59e0b',
|
||||
}}
|
||||
>−</button>
|
||||
|
||||
{/* X = set to customer count */}
|
||||
<button
|
||||
onPointerDown={e => e.stopPropagation()}
|
||||
onClick={setToCustomerCount}
|
||||
title={`Ορισμός σε ${customerCount ?? 1} άτομα`}
|
||||
style={{
|
||||
...btnBase,
|
||||
background: 'rgba(245,158,11,0.12)',
|
||||
color: '#f59e0b',
|
||||
fontSize: 14, fontWeight: 800,
|
||||
}}
|
||||
>
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
|
||||
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
|
||||
<circle cx="9" cy="7" r="4"/>
|
||||
<path d="M23 21v-2a4 4 0 0 0-3-3.87"/>
|
||||
<path d="M16 3.13a4 4 0 0 1 0 7.75"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{/* + */}
|
||||
<button
|
||||
onPointerDown={e => e.stopPropagation()}
|
||||
onClick={inc}
|
||||
style={{
|
||||
...btnBase,
|
||||
background: 'rgba(245,158,11,0.15)',
|
||||
color: '#f59e0b',
|
||||
}}
|
||||
>+</button>
|
||||
|
||||
{/* COUNT indicator */}
|
||||
<span style={{
|
||||
flex: 1, textAlign: 'center',
|
||||
fontSize: 22, fontWeight: 800,
|
||||
color: qty === 0 ? 'var(--muted)' : 'var(--text)',
|
||||
}}>{qty}</span>
|
||||
|
||||
{/* ADD button */}
|
||||
<button
|
||||
onPointerDown={e => e.stopPropagation()}
|
||||
onClick={() => {
|
||||
if (qty === 0) return
|
||||
onAdd({
|
||||
product_id: product.id,
|
||||
quantity: qty,
|
||||
unit_type: 'piece',
|
||||
unit_price: product.base_price ?? 0,
|
||||
notes: '',
|
||||
selected_options: [],
|
||||
removed_ingredients: [],
|
||||
is_service_item: true,
|
||||
}, product)
|
||||
setQty(0)
|
||||
}}
|
||||
disabled={qty === 0}
|
||||
style={{
|
||||
padding: '8px 16px', borderRadius: 10,
|
||||
background: qty === 0 ? 'var(--bg3)' : '#f59e0b',
|
||||
border: 'none', cursor: qty === 0 ? 'default' : 'pointer',
|
||||
fontSize: 12, fontWeight: 800,
|
||||
color: qty === 0 ? 'var(--muted)' : '#fff',
|
||||
flexShrink: 0,
|
||||
}}
|
||||
>
|
||||
ADD
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ServiceItemView({ products, customerCount, onAdd }) {
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, padding: '12px 14px' }}>
|
||||
{products.length === 0 ? (
|
||||
<p style={{ color: 'var(--muted)', textAlign: 'center', padding: 32 }}>
|
||||
Δεν υπάρχουν service αντικείμενα
|
||||
</p>
|
||||
) : products.map(p => (
|
||||
<ServiceItemCard
|
||||
key={p.id}
|
||||
product={p}
|
||||
customerCount={customerCount}
|
||||
onAdd={onAdd}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ProductGrid({ products, onOpen, onQuickAdd, onShowDetail }) {
|
||||
if (products.length === 0) return null
|
||||
return (
|
||||
<div className="product-grid">
|
||||
{products.map(product => {
|
||||
const initials = product.name
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.slice(0, 2)
|
||||
.map(w => w[0])
|
||||
.join('')
|
||||
.toUpperCase()
|
||||
return (
|
||||
<button key={product.id} className="product-btn" onClick={() => onOpen(product)}>
|
||||
<div className="product-btn__thumb">
|
||||
<div className="product-btn__thumb-inner">
|
||||
{product.image_url
|
||||
? <img src={product.image_url} alt="" className="product-btn__img" />
|
||||
: <span className="product-btn__initials">{initials}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div className="product-btn__info">
|
||||
<span className="product-btn__name">{product.name}</span>
|
||||
<span className="product-btn__price">{Number(product.base_price).toFixed(2)} €</span>
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
{products.map(product => (
|
||||
<ProductCard
|
||||
key={product.id}
|
||||
product={product}
|
||||
onOpen={onOpen}
|
||||
onQuickAdd={onQuickAdd}
|
||||
onShowDetail={onShowDetail}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -72,30 +417,42 @@ function buildSections(parent, subcategories, directProducts) {
|
||||
return sections.sort((a, b) => a.sort_order - b.sort_order)
|
||||
}
|
||||
|
||||
export default function ProductPicker({ categories, products, onAdd, viewAllOpen, setViewAllOpen }) {
|
||||
export default function ProductPicker({ categories, products, onAdd, onQuickAdd: onQuickAddProp, viewAllOpen, setViewAllOpen, customerCount, courses = [], globalCourseId = null, quickNotes }) {
|
||||
const navigate = useNavigate()
|
||||
const favorites = useWaiterFavoritesStore(s => s.favorites)
|
||||
|
||||
const serviceProducts = products.filter(p => p.is_service_item)
|
||||
// Service items with a category also appear in that category view
|
||||
const regularProducts = products.filter(p => !p.is_service_item || p.category_id)
|
||||
|
||||
const topLevel = categories.filter(c => !c.parent_id).sort((a, b) => a.sort_order - b.sort_order)
|
||||
const initialCatId = topLevel[0]?.id ?? null
|
||||
// Start on FAVORITES chip if there are any, otherwise first category
|
||||
const initialCatId = favorites.length > 0 ? FAV_CAT_ID : (topLevel[0]?.id ?? null)
|
||||
const [activeCat, setActiveCat] = useState(initialCatId)
|
||||
const [drawerProduct, setDrawerProduct] = useState(null)
|
||||
const [detailProduct, setDetailProduct] = useState(null)
|
||||
const [modalTab, setModalTab] = useState('categories') // 'categories' | 'tags'
|
||||
const [activeTag, setActiveTag] = useState(null)
|
||||
// Track which sub-category sections are expanded (by sub-cat id or '__general__')
|
||||
const [expandedSubs, setExpandedSubs] = useState(() => {
|
||||
if (!initialCatId) return {}
|
||||
if (!initialCatId || initialCatId === FAV_CAT_ID) return {}
|
||||
const subs = categories.filter(c => c.parent_id === initialCatId)
|
||||
const state = {}
|
||||
subs.forEach(s => { if (s.auto_expanded) state[String(s.id)] = true })
|
||||
return state
|
||||
})
|
||||
|
||||
const isSvcActive = activeCat === SVC_CAT_ID
|
||||
|
||||
const activeParent = categories.find(c => c.id === activeCat)
|
||||
const subcategories = activeParent
|
||||
? categories.filter(c => c.parent_id === activeCat).sort((a, b) => a.sort_order - b.sort_order)
|
||||
: []
|
||||
const hasSubcats = subcategories.length > 0
|
||||
|
||||
// Products directly on this top-level category (no sub-cat)
|
||||
const directProducts = products.filter(p => p.category_id === activeCat)
|
||||
const directProducts = regularProducts.filter(p => p.category_id === activeCat)
|
||||
// Products for the flat view (no sub-cats)
|
||||
const flatProducts = products.filter(p => p.category_id === activeCat)
|
||||
const flatProducts = regularProducts.filter(p => p.category_id === activeCat)
|
||||
|
||||
// Build sections for accordion view
|
||||
const sections = hasSubcats ? buildSections(activeParent, subcategories, directProducts) : []
|
||||
@@ -110,7 +467,7 @@ export default function ProductPicker({ categories, products, onAdd, viewAllOpen
|
||||
function selectCategory(id) {
|
||||
setActiveCat(id)
|
||||
setViewAllOpen(false)
|
||||
setExpandedSubs(buildDefaultExpanded(id))
|
||||
setExpandedSubs(id === FAV_CAT_ID || id === SVC_CAT_ID ? {} : buildDefaultExpanded(id))
|
||||
}
|
||||
|
||||
function toggleSub(key) {
|
||||
@@ -120,11 +477,69 @@ export default function ProductPicker({ categories, products, onAdd, viewAllOpen
|
||||
function openDrawer(product) { setDrawerProduct(product) }
|
||||
function closeDrawer() { setDrawerProduct(null) }
|
||||
|
||||
function handleQuickAdd(product) {
|
||||
const base = buildQuickAddItem(product)
|
||||
const item = product.is_service_item ? { ...base, is_service_item: true } : base
|
||||
if (onQuickAddProp) {
|
||||
onQuickAddProp(item, product)
|
||||
} else {
|
||||
onAdd(item)
|
||||
}
|
||||
}
|
||||
|
||||
const isFavActive = activeCat === FAV_CAT_ID
|
||||
const favProducts = favorites.map(id => regularProducts.find(p => p.id === id)).filter(Boolean)
|
||||
|
||||
function handleServiceAdd(item, product) {
|
||||
// Service items go into the cart like regular items
|
||||
if (onQuickAddProp) {
|
||||
onQuickAddProp(item, product)
|
||||
} else {
|
||||
onAdd(item)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="product-picker">
|
||||
<div className="category-tabs">
|
||||
<div className="category-tabs__scroll-wrap">
|
||||
<div className="category-tabs__scroll">
|
||||
{/* SERVICE chip — first if service items exist */}
|
||||
{serviceProducts.length > 0 && (
|
||||
<button
|
||||
className="cat-tab"
|
||||
style={{
|
||||
background: isSvcActive ? '#f59e0b' : hexToRgba('#f59e0b', 0.22),
|
||||
color: isSvcActive ? '#fff' : '#b45309',
|
||||
border: isSvcActive ? '2px solid #f59e0b' : undefined,
|
||||
display: 'flex', alignItems: 'center', gap: 5,
|
||||
}}
|
||||
onClick={() => selectCategory(SVC_CAT_ID)}
|
||||
>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
||||
<path d="M3 11l19-9-9 19-2-8-8-2z"/>
|
||||
</svg>
|
||||
Service
|
||||
</button>
|
||||
)}
|
||||
{/* FAVORITES chip */}
|
||||
{favorites.length > 0 && (
|
||||
<button
|
||||
className="cat-tab"
|
||||
style={{
|
||||
background: isFavActive ? '#ef4444' : hexToRgba('#ef4444', 0.22),
|
||||
color: isFavActive ? '#fff' : '#ef4444',
|
||||
border: isFavActive ? '2px solid #ef4444' : undefined,
|
||||
display: 'flex', alignItems: 'center', gap: 5,
|
||||
}}
|
||||
onClick={() => selectCategory(FAV_CAT_ID)}
|
||||
>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round">
|
||||
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/>
|
||||
</svg>
|
||||
Αγαπημένα
|
||||
</button>
|
||||
)}
|
||||
{topLevel.map(cat => {
|
||||
const isActive = activeCat === cat.id
|
||||
const bg = cat.color
|
||||
@@ -148,12 +563,53 @@ export default function ProductPicker({ categories, products, onAdd, viewAllOpen
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Product area — flat grid or accordion depending on sub-cats */}
|
||||
{/* Product area — service, favorites, flat grid, or accordion depending on sub-cats */}
|
||||
<div className="product-area">
|
||||
{!hasSubcats ? (
|
||||
{isSvcActive ? (
|
||||
// SERVICE view
|
||||
<ServiceItemView
|
||||
products={serviceProducts}
|
||||
customerCount={customerCount}
|
||||
onAdd={handleServiceAdd}
|
||||
/>
|
||||
) : isFavActive ? (
|
||||
// FAVORITES view
|
||||
favProducts.length > 0 ? (
|
||||
<ProductGrid
|
||||
products={favProducts}
|
||||
onOpen={openDrawer}
|
||||
onQuickAdd={handleQuickAdd}
|
||||
onShowDetail={setDetailProduct}
|
||||
/>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', padding: '48px 24px', gap: 14 }}>
|
||||
<svg width="44" height="44" viewBox="0 0 24 24" fill="none" stroke="#ef4444" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" style={{ opacity: 0.4 }}>
|
||||
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/>
|
||||
</svg>
|
||||
<p style={{ color: 'var(--muted)', fontSize: 14, textAlign: 'center', lineHeight: 1.6 }}>
|
||||
Δεν έχεις αγαπημένα ακόμα.
|
||||
</p>
|
||||
<button
|
||||
onClick={() => navigate('/settings/favorites')}
|
||||
style={{
|
||||
padding: '10px 20px', borderRadius: 12,
|
||||
background: 'var(--accent)', color: 'var(--accent-fg)',
|
||||
border: 'none', fontSize: 14, fontWeight: 700, cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
Ρύθμιση Αγαπημένων
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
) : !hasSubcats ? (
|
||||
// No sub-categories: original flat grid
|
||||
<>
|
||||
<ProductGrid products={flatProducts} onOpen={openDrawer} />
|
||||
<ProductGrid
|
||||
products={flatProducts}
|
||||
onOpen={openDrawer}
|
||||
onQuickAdd={handleQuickAdd}
|
||||
onShowDetail={setDetailProduct}
|
||||
/>
|
||||
{flatProducts.length === 0 && (
|
||||
<p style={{ color: '#64748b', textAlign: 'center', padding: 32 }}>
|
||||
Δεν υπάρχουν προϊόντα
|
||||
@@ -168,14 +624,19 @@ export default function ProductPicker({ categories, products, onAdd, viewAllOpen
|
||||
const isOpen = !!expandedSubs[key]
|
||||
const sectionProducts = section._isGeneral
|
||||
? section.products
|
||||
: products.filter(p => p.category_id === section.id)
|
||||
: regularProducts.filter(p => p.category_id === section.id)
|
||||
if (sectionProducts.length === 0) return null
|
||||
|
||||
// General products appear flat — no collapsible header
|
||||
if (section._isGeneral) {
|
||||
return (
|
||||
<div key={key} className="subcat-general">
|
||||
<ProductGrid products={sectionProducts} onOpen={openDrawer} />
|
||||
<ProductGrid
|
||||
products={sectionProducts}
|
||||
onOpen={openDrawer}
|
||||
onQuickAdd={handleQuickAdd}
|
||||
onShowDetail={setDetailProduct}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -202,7 +663,12 @@ export default function ProductPicker({ categories, products, onAdd, viewAllOpen
|
||||
|
||||
{isOpen && (
|
||||
<div className="subcat-body">
|
||||
<ProductGrid products={sectionProducts} onOpen={openDrawer} />
|
||||
<ProductGrid
|
||||
products={sectionProducts}
|
||||
onOpen={openDrawer}
|
||||
onQuickAdd={handleQuickAdd}
|
||||
onShowDetail={setDetailProduct}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -212,35 +678,143 @@ export default function ProductPicker({ categories, products, onAdd, viewAllOpen
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* View All modal — top-level categories only */}
|
||||
{/* View All modal — Κατηγορίες + Tags tabs */}
|
||||
{viewAllOpen && (
|
||||
<div className="modal-overlay" onClick={() => setViewAllOpen(false)}>
|
||||
<div
|
||||
className="cat-all-modal"
|
||||
onClick={e => e.stopPropagation()}
|
||||
style={{ display: 'flex', flexDirection: 'column' }}
|
||||
>
|
||||
<div className="cat-all-modal__header">
|
||||
<span className="cat-all-modal__title">Κατηγορίες</span>
|
||||
<span className="cat-all-modal__title">{modalTab === 'categories' ? 'Κατηγορίες' : 'Tags'}</span>
|
||||
<button className="icon-btn" onClick={() => setViewAllOpen(false)}>✕</button>
|
||||
</div>
|
||||
<div className="cat-all-grid">
|
||||
{topLevel.map(cat => {
|
||||
const isActive = activeCat === cat.id
|
||||
const bg = cat.color || 'var(--bg3)'
|
||||
const overlay = isActive ? 'rgba(255,255,255,0.18)' : 'rgba(0,0,0,0.35)'
|
||||
return (
|
||||
<button
|
||||
key={cat.id}
|
||||
className={`cat-all-tile ${isActive ? 'cat-all-tile--active' : ''}`}
|
||||
style={{ background: bg, boxShadow: isActive ? `0 0 0 3px #fff` : undefined }}
|
||||
onClick={() => selectCategory(cat.id)}
|
||||
>
|
||||
<span className="cat-all-tile__overlay" style={{ background: overlay }} />
|
||||
<span className="cat-all-tile__name">{cat.name}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Tab strip */}
|
||||
<div style={{ display: 'flex', borderBottom: '1px solid var(--border)', flexShrink: 0 }}>
|
||||
{['categories', 'tags'].map(tab => (
|
||||
<button
|
||||
key={tab}
|
||||
onClick={() => setModalTab(tab)}
|
||||
style={{
|
||||
flex: 1, padding: '10px 0',
|
||||
background: 'none', border: 'none', cursor: 'pointer',
|
||||
fontSize: 13, fontWeight: 700,
|
||||
color: modalTab === tab ? 'var(--accent)' : 'var(--muted)',
|
||||
borderBottom: `2px solid ${modalTab === tab ? 'var(--accent)' : 'transparent'}`,
|
||||
marginBottom: -1,
|
||||
transition: 'color 0.12s',
|
||||
}}
|
||||
>
|
||||
{tab === 'categories' ? 'Κατηγορίες' : 'Tags'}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{modalTab === 'categories' && (
|
||||
<div className="cat-all-grid" style={{ flex: 1, overflowY: 'auto' }}>
|
||||
{favorites.length > 0 && (
|
||||
<button
|
||||
className={`cat-all-tile ${isFavActive ? 'cat-all-tile--active' : ''}`}
|
||||
style={{ background: '#ef4444', boxShadow: isFavActive ? `0 0 0 3px #fff` : undefined }}
|
||||
onClick={() => selectCategory(FAV_CAT_ID)}
|
||||
>
|
||||
<span className="cat-all-tile__overlay" style={{ background: isFavActive ? 'rgba(255,255,255,0.18)' : 'rgba(0,0,0,0.22)' }} />
|
||||
<span className="cat-all-tile__name" style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="white" stroke="white" strokeWidth="1" style={{ flexShrink: 0 }}>
|
||||
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/>
|
||||
</svg>
|
||||
Αγαπημένα
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
{topLevel.map(cat => {
|
||||
const isActive = activeCat === cat.id
|
||||
const bg = cat.color || 'var(--bg3)'
|
||||
const overlay = isActive ? 'rgba(255,255,255,0.18)' : 'rgba(0,0,0,0.35)'
|
||||
return (
|
||||
<button
|
||||
key={cat.id}
|
||||
className={`cat-all-tile ${isActive ? 'cat-all-tile--active' : ''}`}
|
||||
style={{ background: bg, boxShadow: isActive ? `0 0 0 3px #fff` : undefined }}
|
||||
onClick={() => selectCategory(cat.id)}
|
||||
>
|
||||
<span className="cat-all-tile__overlay" style={{ background: overlay }} />
|
||||
<span className="cat-all-tile__name">{cat.name}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{modalTab === 'tags' && (() => {
|
||||
const allTags = [...new Set(products.flatMap(p => p.tags || []))].sort()
|
||||
const taggedProducts = activeTag ? products.filter(p => (p.tags || []).includes(activeTag)) : []
|
||||
const byCategory = taggedProducts.reduce((acc, p) => {
|
||||
const cat = categories.find(c => c.id === p.category_id)
|
||||
const key = cat?.name || 'Χωρίς Κατηγορία'
|
||||
if (!acc[key]) acc[key] = []
|
||||
acc[key].push(p)
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return (
|
||||
<div style={{ flex: 1, overflowY: 'auto', display: 'flex', flexDirection: 'column' }}>
|
||||
{allTags.length === 0 && (
|
||||
<div style={{ padding: '32px 16px', textAlign: 'center', color: 'var(--muted)', fontSize: 14 }}>
|
||||
Δεν υπάρχουν tags ακόμα.
|
||||
</div>
|
||||
)}
|
||||
{allTags.length > 0 && (
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, padding: '12px 16px', borderBottom: '1px solid var(--border)' }}>
|
||||
{allTags.map(tag => (
|
||||
<button
|
||||
key={tag}
|
||||
onClick={() => setActiveTag(tag === activeTag ? null : tag)}
|
||||
style={{
|
||||
padding: '6px 14px', borderRadius: 20, border: 'none',
|
||||
background: activeTag === tag ? 'var(--accent)' : 'var(--bg3)',
|
||||
color: activeTag === tag ? 'var(--accent-fg)' : 'var(--text)',
|
||||
fontSize: 13, fontWeight: 700, cursor: 'pointer',
|
||||
transition: 'background 0.12s, color 0.12s',
|
||||
}}
|
||||
>
|
||||
#{tag}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{activeTag && taggedProducts.length === 0 && (
|
||||
<div style={{ padding: '24px 16px', textAlign: 'center', color: 'var(--muted)', fontSize: 14 }}>
|
||||
Κανένα προϊόν με αυτό το tag.
|
||||
</div>
|
||||
)}
|
||||
{activeTag && Object.entries(byCategory).map(([catName, prods]) => (
|
||||
<div key={catName}>
|
||||
<div style={{ padding: '10px 16px 4px', fontSize: 11, fontWeight: 700, color: 'var(--muted)', textTransform: 'uppercase', letterSpacing: 0.7 }}>
|
||||
{catName}
|
||||
</div>
|
||||
{prods.map(p => (
|
||||
<button
|
||||
key={p.id}
|
||||
onClick={() => { setDrawerProduct(p); setViewAllOpen(false) }}
|
||||
style={{
|
||||
display: 'flex', justifyContent: 'space-between', alignItems: 'center',
|
||||
width: '100%', padding: '10px 16px',
|
||||
background: 'none', border: 'none', borderBottom: '1px solid var(--border)',
|
||||
cursor: 'pointer', textAlign: 'left',
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 14, fontWeight: 600, color: 'var(--text)' }}>{p.name}</span>
|
||||
<span style={{ fontSize: 13, color: 'var(--muted)' }}>€{Number(p.base_price).toFixed(2)}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -249,8 +823,24 @@ export default function ProductPicker({ categories, products, onAdd, viewAllOpen
|
||||
product={drawerProduct}
|
||||
isOpen={!!drawerProduct}
|
||||
onClose={closeDrawer}
|
||||
onAdd={item => { onAdd(item); closeDrawer() }}
|
||||
onAdd={item => {
|
||||
const finalItem = drawerProduct?.is_service_item
|
||||
? { ...item, is_service_item: true }
|
||||
: item
|
||||
onAdd(finalItem)
|
||||
closeDrawer()
|
||||
}}
|
||||
courses={courses}
|
||||
quickNotes={quickNotes}
|
||||
initialState={globalCourseId != null ? { courseId: globalCourseId } : undefined}
|
||||
/>
|
||||
|
||||
{detailProduct && (
|
||||
<ProductDetailModal
|
||||
product={detailProduct}
|
||||
onClose={() => setDetailProduct(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,38 @@
|
||||
import { useRef, useState } from 'react'
|
||||
import { useRef, useState, useEffect } from 'react'
|
||||
import useThemeStore from '../store/themeStore'
|
||||
import useTableColourStore from '../store/tableColourStore'
|
||||
|
||||
function useFlashToggle(active, intervalMs = 900) {
|
||||
const [frame, setFrame] = useState(false)
|
||||
useEffect(() => {
|
||||
if (!active) { setFrame(false); return }
|
||||
const id = setInterval(() => setFrame(f => !f), intervalMs)
|
||||
return () => clearInterval(id)
|
||||
}, [active, intervalMs])
|
||||
return frame
|
||||
}
|
||||
|
||||
// Overlay div that smoothly transitions between two colours (or transparent)
|
||||
function FlashOverlay({ c1, c2, frame }) {
|
||||
const bg = frame ? (c2 || 'transparent') : (c1 || 'transparent')
|
||||
return (
|
||||
<div style={{
|
||||
position: 'absolute', inset: 0, borderRadius: 'inherit',
|
||||
background: bg,
|
||||
pointerEvents: 'none', zIndex: 1,
|
||||
transition: 'background 0.45s ease-in-out',
|
||||
}} />
|
||||
)
|
||||
}
|
||||
|
||||
const _UNIT_LABELS_TC = { kg: 'kg', liter: 'L', gram: 'g', ml: 'mL' }
|
||||
function fmtItemQtyTC(qty, unitType) {
|
||||
const label = _UNIT_LABELS_TC[unitType]
|
||||
if (!label) return `${qty}×`
|
||||
if (unitType === 'kg' || unitType === 'liter') return `${Number(qty).toFixed(1)}${label}`
|
||||
return `${qty}${label}`
|
||||
}
|
||||
|
||||
|
||||
const STATUS_LABELS = {
|
||||
free: 'ΕΛΕΥΘΕΡΟ',
|
||||
@@ -11,6 +42,49 @@ const STATUS_LABELS = {
|
||||
partially_paid: 'ΜΕΡ. ΠΛHΡ.',
|
||||
}
|
||||
|
||||
// ─── KDS badge helpers ────────────────────────────────────────────────────────
|
||||
|
||||
const kds = s => s || 'pending'
|
||||
|
||||
function computeKdsBadge(order) {
|
||||
if (!order?.items) return null
|
||||
const relevant = order.items.filter(i => i.status !== 'cancelled' && kds(i.kds_status) !== 'served')
|
||||
if (relevant.length === 0) return null
|
||||
const pending = relevant.filter(i => kds(i.kds_status) === 'pending').length
|
||||
const preparing = relevant.filter(i => kds(i.kds_status) === 'preparing').length
|
||||
const done = relevant.filter(i => kds(i.kds_status) === 'done').length
|
||||
const total = relevant.length
|
||||
if (preparing > 0) return { label: 'PREP', color: '#60a5fa', bg: 'rgba(37,99,235,0.18)' }
|
||||
if (done === total) return { label: 'READY', color: '#4ade80', bg: 'rgba(22,163,74,0.20)' }
|
||||
if (done > 0) return { label: `${done}/${total} READY`, color: '#4ade80', bg: 'rgba(22,163,74,0.18)' }
|
||||
return null // all pending — no badge needed
|
||||
}
|
||||
|
||||
// Whether the order has any "done" (ready) items — used for flash overlay
|
||||
function orderHasReadyItems(order) {
|
||||
if (!order?.items) return false
|
||||
return order.items.some(i => i.status !== 'cancelled' && kds(i.kds_status) === 'done')
|
||||
}
|
||||
|
||||
function KdsBadge({ badge, small }) {
|
||||
if (!badge) return null
|
||||
return (
|
||||
<span style={{
|
||||
display: 'inline-flex', alignItems: 'center',
|
||||
height: small ? 16 : 20,
|
||||
padding: small ? '0 5px' : '0 8px',
|
||||
borderRadius: 4,
|
||||
background: badge.bg,
|
||||
color: badge.color,
|
||||
fontSize: small ? 8 : 10,
|
||||
fontWeight: 800,
|
||||
letterSpacing: 0.3,
|
||||
whiteSpace: 'nowrap',
|
||||
border: `1px solid ${badge.color}40`,
|
||||
}}>{badge.label}</span>
|
||||
)
|
||||
}
|
||||
|
||||
const DRAG_THRESHOLD = 8
|
||||
const HOLD_MS = 480
|
||||
|
||||
@@ -206,8 +280,8 @@ function Amount({ value, size = 22, color }) {
|
||||
|
||||
// ─── Card variants ────────────────────────────────────────────────────────────
|
||||
|
||||
// 1x1 — square-ish, 4 per row. Badges top (up to 2 + +N), name center, status bottom.
|
||||
function Card1x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
// 1x1 — square-ish, 4 per row. Badges top (up to 2 + +N), name center, KDS badge bottom (replaces status).
|
||||
function Card1x1({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
|
||||
return (
|
||||
<div style={{
|
||||
width: '100%', aspectRatio: '1 / 1.05',
|
||||
@@ -217,8 +291,10 @@ function Card1x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
padding: 8,
|
||||
boxShadow: '0 2px 8px rgba(0,0,0,0.12)',
|
||||
}}>
|
||||
{/* top strip: badges up to 2, then +N */}
|
||||
<div style={{ height: '20%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 3 }}>
|
||||
{flashOverlay}
|
||||
|
||||
{/* top strip: flags up to 2, then +N */}
|
||||
<div style={{ height: '20%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 3, position: 'relative', zIndex: 2 }}>
|
||||
<FlagDots flags={flags} size={16} maxShow={2} />
|
||||
</div>
|
||||
|
||||
@@ -227,27 +303,32 @@ function Card1x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
fontWeight: 800, fontSize: 'clamp(18px, 5vw, 26px)',
|
||||
letterSpacing: -0.5, color: cfg.nameText, lineHeight: 1,
|
||||
position: 'relative', zIndex: 2,
|
||||
}}>
|
||||
{table.label || `T${table.number}`}
|
||||
</div>
|
||||
|
||||
{/* bottom strip: status */}
|
||||
<div style={{ height: '20%', display: 'flex', alignItems: 'flex-end', justifyContent: 'center' }}>
|
||||
<span style={{
|
||||
fontSize: 7, fontWeight: 800, letterSpacing: 0.3,
|
||||
color: cfg.badgeText, textTransform: 'uppercase',
|
||||
background: cfg.badgeBg, borderRadius: 3,
|
||||
padding: '1px 4px', whiteSpace: 'nowrap',
|
||||
}}>
|
||||
{STATUS_LABELS[statusKey]}
|
||||
</span>
|
||||
{/* bottom strip: KDS badge if present, else status */}
|
||||
<div style={{ height: '20%', display: 'flex', alignItems: 'flex-end', justifyContent: 'center', position: 'relative', zIndex: 2 }}>
|
||||
{kdsBadge ? (
|
||||
<KdsBadge badge={kdsBadge} small />
|
||||
) : (
|
||||
<span style={{
|
||||
fontSize: 7, fontWeight: 800, letterSpacing: 0.3,
|
||||
color: cfg.badgeText, textTransform: 'uppercase',
|
||||
background: cfg.badgeBg, borderRadius: 3,
|
||||
padding: '1px 4px', whiteSpace: 'nowrap',
|
||||
}}>
|
||||
{STATUS_LABELS[statusKey]}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 2x1 — half width, compact horizontal. Name left, status + badges (up to 3 + +N) right.
|
||||
function Card2x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
// 2x1 — half width, compact horizontal. Name left, KDS badge (or status) + flags right.
|
||||
function Card2x1({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
|
||||
return (
|
||||
<div style={{
|
||||
width: '100%', height: 64,
|
||||
@@ -256,10 +337,14 @@ function Card2x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'space-between',
|
||||
gap: 10, overflow: 'hidden',
|
||||
boxShadow: '0 2px 8px rgba(0,0,0,0.12)',
|
||||
position: 'relative',
|
||||
}}>
|
||||
{flashOverlay}
|
||||
|
||||
<div style={{
|
||||
fontWeight: 800, fontSize: 'clamp(18px, 4.5vw, 24px)',
|
||||
letterSpacing: -0.5, color: cfg.nameText, lineHeight: 1, flexShrink: 0,
|
||||
position: 'relative', zIndex: 2,
|
||||
}}>
|
||||
{table.label || `T${table.number}`}
|
||||
</div>
|
||||
@@ -267,8 +352,13 @@ function Card2x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
<div style={{
|
||||
display: 'flex', flexDirection: 'column',
|
||||
alignItems: 'flex-end', justifyContent: 'center', gap: 4,
|
||||
position: 'relative', zIndex: 2,
|
||||
}}>
|
||||
<StatusPill label={STATUS_LABELS[statusKey]} badgeBg={cfg.badgeBg} badgeText={cfg.badgeText} small />
|
||||
{kdsBadge ? (
|
||||
<KdsBadge badge={kdsBadge} small />
|
||||
) : (
|
||||
<StatusPill label={STATUS_LABELS[statusKey]} badgeBg={cfg.badgeBg} badgeText={cfg.badgeText} small />
|
||||
)}
|
||||
{flags.length > 0 && (
|
||||
<FlagDots flags={flags} size={18} maxShow={3} />
|
||||
)}
|
||||
@@ -277,8 +367,8 @@ function Card2x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
)
|
||||
}
|
||||
|
||||
// 2x2 — current-style square. Name top-left, status (slightly smaller) below, amount bottom-left, flags right.
|
||||
function Card2x2({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
// 2x2 — current-style square. Name top-left, status below, amount bottom-left, KDS badge top-right, flags right.
|
||||
function Card2x2({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
|
||||
const isFree = !order
|
||||
const total = order?.items?.filter(i => i.status === 'active').reduce((s, i) => s + i.unit_price * i.quantity, 0) ?? 0
|
||||
|
||||
@@ -289,9 +379,12 @@ function Card2x2({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
padding: '12px 12px 12px',
|
||||
display: 'flex', gap: 8, overflow: 'hidden',
|
||||
boxShadow: '0 2px 10px rgba(0,0,0,0.12)',
|
||||
position: 'relative',
|
||||
}}>
|
||||
{flashOverlay}
|
||||
|
||||
{/* left column */}
|
||||
<div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column' }}>
|
||||
<div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', position: 'relative', zIndex: 2 }}>
|
||||
<span style={{
|
||||
fontSize: 'clamp(22px, 5.5vw, 36px)', fontWeight: 800,
|
||||
lineHeight: 1.05, color: cfg.nameText, letterSpacing: -0.5,
|
||||
@@ -307,21 +400,25 @@ function Card2x2({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* right column: flags — show 2, then +N */}
|
||||
{flags.length > 0 && (
|
||||
<div style={{
|
||||
display: 'flex', flexDirection: 'column-reverse',
|
||||
gap: 4, alignItems: 'flex-end', justifyContent: 'flex-start',
|
||||
}}>
|
||||
<FlagDots flags={flags} size={26} maxShow={2} />
|
||||
</div>
|
||||
)}
|
||||
{/* right column: KDS badge top, flags bottom */}
|
||||
<div style={{
|
||||
display: 'flex', flexDirection: 'column',
|
||||
gap: 4, alignItems: 'flex-end', justifyContent: 'space-between',
|
||||
position: 'relative', zIndex: 2,
|
||||
}}>
|
||||
{kdsBadge && <KdsBadge badge={kdsBadge} small />}
|
||||
{flags.length > 0 && (
|
||||
<div style={{ display: 'flex', flexDirection: 'column-reverse', gap: 4, alignItems: 'flex-end' }}>
|
||||
<FlagDots flags={flags} size={26} maxShow={2} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 4x1 — full width horizontal. Name + amount left-center, badges (up to 3 + +N) + status right.
|
||||
function Card4x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
// 4x1 — full width horizontal. Name + amount left-center, flags, KDS badge (or status) right.
|
||||
function Card4x1({ table, order, flags, waiterObjects, cfg, statusKey, kdsBadge, flashOverlay }) {
|
||||
const isFree = !order
|
||||
const total = order?.items?.filter(i => i.status === 'active').reduce((s, i) => s + i.unit_price * i.quantity, 0) ?? 0
|
||||
|
||||
@@ -332,36 +429,48 @@ function Card4x1({ table, order, flags, waiterObjects, cfg, statusKey }) {
|
||||
padding: '12px 14px',
|
||||
display: 'flex', alignItems: 'center', gap: 14, overflow: 'hidden',
|
||||
boxShadow: '0 2px 8px rgba(0,0,0,0.12)',
|
||||
position: 'relative',
|
||||
}}>
|
||||
{flashOverlay}
|
||||
|
||||
{/* name */}
|
||||
<div style={{
|
||||
fontWeight: 800, fontSize: 'clamp(20px, 4.5vw, 28px)',
|
||||
letterSpacing: -0.5, color: cfg.nameText, lineHeight: 1, flexShrink: 0,
|
||||
position: 'relative', zIndex: 2,
|
||||
}}>
|
||||
{table.label || `T${table.number}`}
|
||||
</div>
|
||||
|
||||
{/* separator dot */}
|
||||
<span style={{ color: cfg.nameText, opacity: 0.3, fontSize: 20, lineHeight: 1, flexShrink: 0 }}>·</span>
|
||||
<span style={{ color: cfg.nameText, opacity: 0.3, fontSize: 20, lineHeight: 1, flexShrink: 0, position: 'relative', zIndex: 2 }}>·</span>
|
||||
|
||||
{/* amount — always reserve space, invisible when free */}
|
||||
<div style={{ flex: 1, display: 'flex', alignItems: 'center', visibility: isFree ? 'hidden' : 'visible' }}>
|
||||
<div style={{ flex: 1, display: 'flex', alignItems: 'center', visibility: isFree ? 'hidden' : 'visible', position: 'relative', zIndex: 2 }}>
|
||||
<Amount value={total} size={'clamp(20px, 4.5vw, 28px)'} color={cfg.nameText} />
|
||||
</div>
|
||||
|
||||
{/* flags up to 3 + +N */}
|
||||
{flags.length > 0 && (
|
||||
<FlagDots flags={flags} size={24} maxShow={3} />
|
||||
<div style={{ position: 'relative', zIndex: 2 }}>
|
||||
<FlagDots flags={flags} size={24} maxShow={3} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* status */}
|
||||
<StatusPill label={STATUS_LABELS[statusKey]} badgeBg={cfg.badgeBg} badgeText={cfg.badgeText} />
|
||||
{/* KDS badge or status */}
|
||||
<div style={{ position: 'relative', zIndex: 2 }}>
|
||||
{kdsBadge ? (
|
||||
<KdsBadge badge={kdsBadge} />
|
||||
) : (
|
||||
<StatusPill label={STATUS_LABELS[statusKey]} badgeBg={cfg.badgeBg} badgeText={cfg.badgeText} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 4x2 — full width, tall. One main row: name+zone left, status center, amount+flags right. Flag chips below. Waiter footer.
|
||||
function Card4x2({ table, order, flags, waiterObjects, groupName, cfg, statusKey }) {
|
||||
// 4x2 — full width, tall. Top row: name LEFT | status + KDS badge CENTER (v-centered with amount) | amount RIGHT.
|
||||
function Card4x2({ table, order, flags, waiterObjects, groupName, cfg, statusKey, kdsBadge, flashOverlay }) {
|
||||
const isFree = !order
|
||||
const total = order?.items?.filter(i => i.status === 'active').reduce((s, i) => s + i.unit_price * i.quantity, 0) ?? 0
|
||||
const showWaiters = !isFree && waiterObjects.length > 0
|
||||
@@ -373,11 +482,14 @@ function Card4x2({ table, order, flags, waiterObjects, groupName, cfg, statusKey
|
||||
overflow: 'hidden',
|
||||
boxShadow: '0 2px 10px rgba(0,0,0,0.12)',
|
||||
display: 'flex', flexDirection: 'column',
|
||||
position: 'relative',
|
||||
}}>
|
||||
{flashOverlay}
|
||||
|
||||
{/* main body */}
|
||||
<div style={{ padding: '14px 14px 12px', display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
{/* top row: name LEFT | status CENTER | amount RIGHT — all top-aligned */}
|
||||
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 10 }}>
|
||||
<div style={{ padding: '14px 14px 12px', display: 'flex', flexDirection: 'column', gap: 10, position: 'relative', zIndex: 2 }}>
|
||||
{/* top row: name LEFT | badges CENTER | amount RIGHT — vertically centered */}
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||
{/* left: name + zone */}
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{
|
||||
@@ -397,9 +509,10 @@ function Card4x2({ table, order, flags, waiterObjects, groupName, cfg, statusKey
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* center: status pill — top-aligned via paddingTop to optically align with name cap */}
|
||||
<div style={{ paddingTop: 4, flexShrink: 0 }}>
|
||||
{/* center: status + KDS badge side-by-side, vertically centered */}
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0 }}>
|
||||
<StatusPill label={STATUS_LABELS[statusKey]} badgeBg={cfg.badgeBg} badgeText={cfg.badgeText} />
|
||||
{kdsBadge && <KdsBadge badge={kdsBadge} />}
|
||||
</div>
|
||||
|
||||
{/* right: amount — always reserve space, invisible when free */}
|
||||
@@ -429,6 +542,7 @@ function Card4x2({ table, order, flags, waiterObjects, groupName, cfg, statusKey
|
||||
borderTop: `1px solid ${cfg.nameText}22`,
|
||||
padding: '10px 14px', minHeight: 40,
|
||||
display: 'flex', alignItems: 'center',
|
||||
position: 'relative', zIndex: 2,
|
||||
}}>
|
||||
{showWaiters
|
||||
? <WaiterRow waiters={waiterObjects} size={24} cfg={cfg} />
|
||||
@@ -439,13 +553,28 @@ function Card4x2({ table, order, flags, waiterObjects, groupName, cfg, statusKey
|
||||
)
|
||||
}
|
||||
|
||||
// 4x3 — full width, two-column detail card. Left: name/zone/status/amount. Right: order items list. Footer: waiters.
|
||||
function Card4x3({ table, order, flags, waiterObjects, groupName, cfg, statusKey }) {
|
||||
// 4x3 — full width, two-column detail card. Left: name/zone/status/amount. Right: items. KDS footer. Waiter footer.
|
||||
function Card4x3({ table, order, flags, waiterObjects, groupName, cfg, statusKey, kdsBadge, flashOverlay }) {
|
||||
const isFree = !order
|
||||
const activeItems = order?.items?.filter(i => i.status === 'active') ?? []
|
||||
const total = activeItems.reduce((s, i) => s + i.unit_price * i.quantity, 0)
|
||||
const showWaiters = !isFree && waiterObjects.length > 0
|
||||
|
||||
// KDS footer summary text
|
||||
const kdsFooter = (() => {
|
||||
if (!order?.items) return null
|
||||
const relevant = order.items.filter(i => i.status !== 'cancelled' && kds(i.kds_status) !== 'served')
|
||||
if (relevant.length === 0) return null
|
||||
const preparing = relevant.filter(i => kds(i.kds_status) === 'preparing').length
|
||||
const done = relevant.filter(i => kds(i.kds_status) === 'done').length
|
||||
const total = relevant.length
|
||||
if (done === total && total > 0) return { text: 'Όλα Έτοιμα για Παράδοση', color: '#4ade80' }
|
||||
const parts = []
|
||||
if (preparing > 0) parts.push(`${preparing} Ετοιμάζεται`)
|
||||
if (done > 0) parts.push(`${done} Έτοιμα`)
|
||||
return parts.length > 0 ? { text: parts.join(' · '), color: done > 0 ? '#4ade80' : '#60a5fa' } : null
|
||||
})()
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
width: '100%',
|
||||
@@ -453,8 +582,10 @@ function Card4x3({ table, order, flags, waiterObjects, groupName, cfg, statusKey
|
||||
overflow: 'hidden',
|
||||
boxShadow: '0 2px 10px rgba(0,0,0,0.12)',
|
||||
display: 'flex', flexDirection: 'column',
|
||||
position: 'relative',
|
||||
}}>
|
||||
<div style={{ display: 'flex', padding: '14px 14px 10px', gap: 14, minWidth: 0, overflow: 'hidden' }}>
|
||||
{flashOverlay}
|
||||
<div style={{ display: 'flex', padding: '14px 14px 10px', gap: 14, minWidth: 0, overflow: 'hidden', position: 'relative', zIndex: 2 }}>
|
||||
{/* left column: name, zone, amount, status, flags */}
|
||||
<div style={{ display: 'flex', flexDirection: 'column', minWidth: 100, flexShrink: 0, justifyContent: 'space-between' }}>
|
||||
<div>
|
||||
@@ -511,7 +642,7 @@ function Card4x3({ table, order, flags, waiterObjects, groupName, cfg, statusKey
|
||||
fontSize: 11, fontWeight: 700, color: cfg.nameText,
|
||||
background: `${cfg.nameText}18`, borderRadius: 3,
|
||||
padding: '1px 5px', flexShrink: 0,
|
||||
}}>{item.quantity}×</span>
|
||||
}}>{fmtItemQtyTC(item.quantity, item.unit_type)}</span>
|
||||
<span style={{
|
||||
fontSize: 12, fontWeight: 500, color: cfg.nameText,
|
||||
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', flex: 1,
|
||||
@@ -531,11 +662,26 @@ function Card4x3({ table, order, flags, waiterObjects, groupName, cfg, statusKey
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* KDS footer row — only when there's something to show */}
|
||||
{kdsFooter && (
|
||||
<div style={{
|
||||
borderTop: `1px solid ${cfg.nameText}22`,
|
||||
padding: '6px 14px',
|
||||
display: 'flex', alignItems: 'center', gap: 6,
|
||||
position: 'relative', zIndex: 2,
|
||||
}}>
|
||||
<span style={{ fontSize: 10, fontWeight: 800, color: kdsFooter.color, letterSpacing: 0.3 }}>
|
||||
{kdsFooter.text}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* footer: waiters */}
|
||||
<div style={{
|
||||
borderTop: `1px solid ${cfg.nameText}22`,
|
||||
padding: '10px 14px', minHeight: 38,
|
||||
display: 'flex', alignItems: 'center',
|
||||
position: 'relative', zIndex: 2,
|
||||
}}>
|
||||
{showWaiters
|
||||
? <WaiterRow waiters={waiterObjects} size={22} cfg={cfg} />
|
||||
@@ -573,8 +719,30 @@ export default function TableCard({
|
||||
else if (order && isMine) statusKey = 'mine'
|
||||
else if (order) statusKey = 'open'
|
||||
|
||||
const mode = dark ? 'dark' : 'light'
|
||||
const cfg = colours[mode][statusKey]
|
||||
const mode = dark ? 'dark' : 'light'
|
||||
const baseCfg = colours[mode][statusKey]
|
||||
const readyCfg = colours[mode]['kds_ready']
|
||||
const kdsBadge = computeKdsBadge(order)
|
||||
const hasReady = orderHasReadyItems(order)
|
||||
const flashOn = hasReady && !!readyCfg?.flash
|
||||
const flashFrame = useFlashToggle(flashOn)
|
||||
|
||||
// 'transparent' in a flash color means "show the base card color for that slot".
|
||||
// The settings UI stores transparent as 'rgba(0,0,0,0)', so we check both forms.
|
||||
const isTransparent = (v) => !v || v === 'transparent' || v === 'rgba(0,0,0,0)'
|
||||
const fc = (flashColor, baseColor) => isTransparent(flashColor) ? baseColor : flashColor
|
||||
|
||||
// cfg always = baseCfg for card background (so table status colour shows through flash overlay)
|
||||
// For text/badge when flashing, alternate between readyCfg set-1 and set-2;
|
||||
// transparent values fall back to the matching baseCfg slot so they're never invisible.
|
||||
const cfg = flashOn
|
||||
? {
|
||||
cardBg: baseCfg.cardBg,
|
||||
badgeBg: fc(flashFrame ? (readyCfg.badgeBg2 ?? readyCfg.badgeBg) : readyCfg.badgeBg, baseCfg.badgeBg),
|
||||
nameText: fc(flashFrame ? (readyCfg.nameText2 ?? readyCfg.nameText) : readyCfg.nameText, baseCfg.nameText),
|
||||
badgeText: fc(flashFrame ? (readyCfg.badgeText2?? readyCfg.badgeText) : readyCfg.badgeText, baseCfg.badgeText),
|
||||
}
|
||||
: baseCfg
|
||||
|
||||
function cancel() {
|
||||
clearTimeout(holdTimer.current)
|
||||
@@ -625,7 +793,10 @@ export default function TableCard({
|
||||
onClick?.()
|
||||
}
|
||||
|
||||
const cardProps = { table, order, flags, waiterObjects, groupName, cfg, statusKey }
|
||||
const flashOverlay = flashOn
|
||||
? <FlashOverlay c1={readyCfg.cardBg} c2={readyCfg.cardBg2} frame={flashFrame} />
|
||||
: null
|
||||
const cardProps = { table, order, flags, waiterObjects, groupName, cfg, statusKey, kdsBadge, flashOverlay }
|
||||
|
||||
const CardComponent = {
|
||||
'1x1': Card1x1,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { useRegisterSW } from 'virtual:pwa-register/react'
|
||||
|
||||
export default function UpdatePrompt() {
|
||||
const {
|
||||
needRefresh: [needRefresh],
|
||||
updateServiceWorker,
|
||||
} = useRegisterSW()
|
||||
|
||||
if (!needRefresh) return null
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
position: 'fixed',
|
||||
bottom: 80,
|
||||
left: '50%',
|
||||
transform: 'translateX(-50%)',
|
||||
zIndex: 9999,
|
||||
background: 'var(--bg2)',
|
||||
border: '1px solid var(--accent)',
|
||||
borderRadius: 16,
|
||||
padding: '14px 20px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 16,
|
||||
boxShadow: '0 8px 32px rgba(0,0,0,0.4)',
|
||||
whiteSpace: 'nowrap',
|
||||
}}>
|
||||
<span style={{ fontSize: 14, color: 'var(--text)', fontWeight: 500 }}>
|
||||
Νέα έκδοση διαθέσιμη
|
||||
</span>
|
||||
<button
|
||||
onClick={() => updateServiceWorker(true)}
|
||||
style={{
|
||||
background: 'var(--accent)',
|
||||
color: '#0f172a',
|
||||
border: 'none',
|
||||
borderRadius: 10,
|
||||
padding: '8px 16px',
|
||||
fontSize: 14,
|
||||
fontWeight: 700,
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
Ενημέρωση
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -82,21 +82,27 @@ export default function UserMenu() {
|
||||
return (
|
||||
<div ref={ref} style={{ position: 'relative' }}>
|
||||
<button
|
||||
className="icon-btn"
|
||||
onClick={() => setOpen(o => !o)}
|
||||
title="Μενού χρήστη"
|
||||
style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '0 10px' }}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 6,
|
||||
padding: '8px 14px', borderRadius: 20, border: '2px solid transparent',
|
||||
background: open ? 'var(--accent)' : 'var(--bg3)',
|
||||
color: open ? 'var(--accent-fg)' : 'var(--text)',
|
||||
fontSize: 14, fontWeight: 600, cursor: 'pointer', lineHeight: 1,
|
||||
transition: 'background 0.12s, color 0.12s',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{/* Break indicator dot */}
|
||||
{activeBreak && (
|
||||
<span style={{
|
||||
width: 8, height: 8, borderRadius: '50%',
|
||||
background: 'var(--accent)', flexShrink: 0,
|
||||
width: 7, height: 7, borderRadius: '50%',
|
||||
background: open ? 'var(--accent-fg)' : 'var(--accent)', flexShrink: 0,
|
||||
animation: 'tab-pulse 1.5s ease-in-out infinite',
|
||||
}} />
|
||||
)}
|
||||
<span style={{ fontSize: 14, fontWeight: 600, color: 'var(--text)' }}>{user?.username}</span>
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" style={{ color: 'var(--muted)', flexShrink: 0 }}>
|
||||
<span>{user?.username}</span>
|
||||
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" style={{ flexShrink: 0, opacity: 0.6 }}>
|
||||
<path d="M4 6l4 4 4-4" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
@@ -168,12 +174,6 @@ export default function UserMenu() {
|
||||
<span>{dark ? 'Φωτεινό θέμα' : 'Σκοτεινό θέμα'}</span>
|
||||
</button>
|
||||
|
||||
{/* ── Settings ──────────────────────────────────────── */}
|
||||
<button className="user-menu-item" onClick={() => { setOpen(false); navigate('/settings') }}>
|
||||
<span className="user-menu-item__icon">⚙️</span>
|
||||
<span>Ρυθμίσεις</span>
|
||||
</button>
|
||||
|
||||
<div className="user-menu-divider" />
|
||||
|
||||
<button className="user-menu-item user-menu-item--danger" onClick={handleLogout}>
|
||||
|
||||
Reference in New Issue
Block a user