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,25 @@
|
||||
import { ShieldAlert } from 'lucide-react'
|
||||
import usePermissions from '../hooks/usePermissions'
|
||||
|
||||
/**
|
||||
* Wraps a route element. Renders a 403 screen if the user lacks the required permission.
|
||||
* Usage: <PermissionGuard perm="viewReports"><TodayPage /></PermissionGuard>
|
||||
*/
|
||||
export default function PermissionGuard({ perm, children }) {
|
||||
const perms = usePermissions()
|
||||
|
||||
if (!perms[perm]) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-full gap-4 text-center p-8">
|
||||
<ShieldAlert size={48} className="text-red-400" />
|
||||
<h2 className="text-xl font-semibold text-gray-800">Δεν έχετε πρόσβαση</h2>
|
||||
<p className="text-gray-500 max-w-sm">
|
||||
Δεν έχετε τα απαραίτητα δικαιώματα για αυτή τη σελίδα.
|
||||
Επικοινωνήστε με τον διαχειριστή εάν νομίζετε ότι πρόκειται για λάθος.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
/**
|
||||
* Mounts once inside AppLayout. Holds the WebSocket connection to /api/phone/ws,
|
||||
* matches incoming callers against the customer list, and renders the call popup
|
||||
* over whatever page is currently open.
|
||||
*/
|
||||
import { useEffect, useCallback, useRef, useState } from 'react'
|
||||
import { PhoneIncoming, X, Mail, Phone, MessageSquare, Tag,
|
||||
ShoppingBag, TrendingUp, Clock, User } from 'lucide-react'
|
||||
import client from '../api/client'
|
||||
import usePhoneStore from '../store/phoneStore'
|
||||
|
||||
/* ─── Phone normalisation ─────────────────────────────────────────────────── */
|
||||
function normalisePhone(raw) {
|
||||
if (!raw) return ''
|
||||
let s = raw.replace(/[\s\-().+]/g, '')
|
||||
if (s.startsWith('0030')) s = s.slice(4)
|
||||
else if (s.startsWith('30') && s.length > 10) s = s.slice(2)
|
||||
return s
|
||||
}
|
||||
function phonesMatch(a, b) {
|
||||
const na = normalisePhone(a), nb = normalisePhone(b)
|
||||
return na.length > 0 && na === nb
|
||||
}
|
||||
|
||||
function buildWsUrl() {
|
||||
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws'
|
||||
return `${proto}://${window.location.host}/api/phone/ws`
|
||||
}
|
||||
|
||||
/* ─── Helpers ─────────────────────────────────────────────────────────────── */
|
||||
function formatTime(date) {
|
||||
return date.toLocaleTimeString('el-GR', { hour: '2-digit', minute: '2-digit' })
|
||||
}
|
||||
function formatDate(dateStr) {
|
||||
if (!dateStr) return '—'
|
||||
return new Date(dateStr).toLocaleDateString('el-GR', { day: '2-digit', month: 'short', year: 'numeric' })
|
||||
}
|
||||
function formatCurrency(n) {
|
||||
return `€${Number(n || 0).toFixed(2)}`
|
||||
}
|
||||
|
||||
/* ─── Ripple rings ────────────────────────────────────────────────────────── */
|
||||
function RippleRings({ color }) {
|
||||
return (
|
||||
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', pointerEvents: 'none' }}>
|
||||
{[0, 1, 2].map(i => (
|
||||
<span key={i} style={{
|
||||
position: 'absolute', width: 80, height: 80, borderRadius: '50%',
|
||||
border: `2px solid ${color}`, opacity: 0,
|
||||
animation: `phoneRipple 2s ease-out ${i * 0.6}s infinite`,
|
||||
}} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/* ─── Known customer modal ────────────────────────────────────────────────── */
|
||||
function KnownCustomerModal({ call, customer, orders, onClose }) {
|
||||
const recent = (orders || []).slice(0, 3)
|
||||
return (
|
||||
<div style={{ fontFamily: "'DM Sans','Segoe UI',sans-serif" }}>
|
||||
<div onClick={onClose} style={{
|
||||
position: 'fixed', inset: 0, zIndex: 9990,
|
||||
background: 'rgba(0,0,0,0.65)', backdropFilter: 'blur(8px)',
|
||||
animation: 'fadeIn 0.2s ease',
|
||||
}} />
|
||||
<div style={{
|
||||
position: 'fixed', zIndex: 9991,
|
||||
top: '50%', left: '50%',
|
||||
transform: 'translate(-50%,-50%)',
|
||||
width: '100%', maxWidth: 480, padding: '0 16px',
|
||||
animation: 'slideUp 0.3s cubic-bezier(0.16,1,0.3,1)',
|
||||
}}>
|
||||
<div style={{
|
||||
background: '#0f1117', borderRadius: 20, overflow: 'hidden',
|
||||
boxShadow: '0 32px 80px rgba(0,0,0,0.8),0 0 0 1px rgba(255,255,255,0.06)',
|
||||
}}>
|
||||
<div style={{ height: 3, background: 'linear-gradient(90deg,#d4a853,#f0c87a,#d4a853)' }} />
|
||||
|
||||
<div style={{ padding: '24px 24px 20px', position: 'relative' }}>
|
||||
<button onClick={onClose} style={{
|
||||
position: 'absolute', top: 20, right: 20,
|
||||
width: 32, height: 32, borderRadius: 8,
|
||||
background: 'rgba(255,255,255,0.07)', border: '1px solid rgba(255,255,255,0.1)',
|
||||
color: '#9ca3af', cursor: 'pointer',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}
|
||||
onMouseEnter={e => { e.currentTarget.style.background = 'rgba(255,255,255,0.12)'; e.currentTarget.style.color = '#fff' }}
|
||||
onMouseLeave={e => { e.currentTarget.style.background = 'rgba(255,255,255,0.07)'; e.currentTarget.style.color = '#9ca3af' }}
|
||||
><X size={14} /></button>
|
||||
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 16 }}>
|
||||
<div style={{ position: 'relative', width: 44, height: 44 }}>
|
||||
<RippleRings color="#d4a853" />
|
||||
<div style={{
|
||||
width: 44, height: 44, borderRadius: '50%',
|
||||
background: 'linear-gradient(135deg,#d4a853,#f0c87a)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
position: 'relative', zIndex: 1,
|
||||
}}><PhoneIncoming size={18} color="#0f1117" /></div>
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 10, fontWeight: 600, letterSpacing: '0.12em', color: '#d4a853', textTransform: 'uppercase' }}>Εισερχόμενη Κλήση</div>
|
||||
<div style={{ fontSize: 12, color: '#6b7280', marginTop: 1 }}>{formatTime(call.at)} · {call.caller}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 16 }}>
|
||||
<div style={{
|
||||
width: 56, height: 56, borderRadius: 14, flexShrink: 0,
|
||||
background: 'linear-gradient(135deg,#1e293b,#334155)',
|
||||
border: '1px solid rgba(212,168,83,0.3)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
fontSize: 22, fontWeight: 700, color: '#d4a853',
|
||||
}}>{customer.name?.[0]?.toUpperCase() || '?'}</div>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ fontSize: 22, fontWeight: 700, color: '#f9fafb', lineHeight: 1.2, letterSpacing: '-0.01em' }}>{customer.name}</div>
|
||||
{customer.nickname && (
|
||||
<div style={{ fontSize: 13, color: '#d4a853', marginTop: 2, display: 'flex', alignItems: 'center', gap: 4 }}>
|
||||
<Tag size={11} />{customer.nickname}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ height: 1, background: 'rgba(255,255,255,0.06)', margin: '0 24px' }} />
|
||||
|
||||
<div style={{ padding: '16px 24px', display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
{customer.email && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||
<Mail size={13} color="#6b7280" style={{ flexShrink: 0 }} />
|
||||
<span style={{ fontSize: 13, color: '#d1d5db' }}>{customer.email}</span>
|
||||
</div>
|
||||
)}
|
||||
{customer.phone && (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||
<Phone size={13} color="#6b7280" style={{ flexShrink: 0 }} />
|
||||
<span style={{ fontSize: 13, color: '#d1d5db', fontVariantNumeric: 'tabular-nums' }}>{customer.phone}</span>
|
||||
</div>
|
||||
)}
|
||||
{customer.notes && (
|
||||
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 10, marginTop: 2 }}>
|
||||
<MessageSquare size={13} color="#6b7280" style={{ flexShrink: 0, marginTop: 1 }} />
|
||||
<span style={{ fontSize: 13, color: '#9ca3af', lineHeight: 1.5, fontStyle: 'italic' }}>"{customer.notes}"</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{
|
||||
margin: '0 24px',
|
||||
background: 'rgba(255,255,255,0.04)', border: '1px solid rgba(255,255,255,0.07)',
|
||||
borderRadius: 12, display: 'grid', gridTemplateColumns: '1fr 1fr',
|
||||
}}>
|
||||
<div style={{ padding: '12px 16px', borderRight: '1px solid rgba(255,255,255,0.07)' }}>
|
||||
<div style={{ fontSize: 10, color: '#6b7280', textTransform: 'uppercase', letterSpacing: '0.1em', marginBottom: 4 }}>Επισκέψεις</div>
|
||||
<div style={{ fontSize: 22, fontWeight: 700, color: '#f9fafb', display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<ShoppingBag size={14} color="#d4a853" />{customer.visit_count ?? 0}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ padding: '12px 16px' }}>
|
||||
<div style={{ fontSize: 10, color: '#6b7280', textTransform: 'uppercase', letterSpacing: '0.1em', marginBottom: 4 }}>Σύνολο</div>
|
||||
<div style={{ fontSize: 22, fontWeight: 700, color: '#f9fafb', display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<TrendingUp size={14} color="#d4a853" />{formatCurrency(customer.total_spent)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ padding: '16px 24px 0' }}>
|
||||
<div style={{ fontSize: 10, fontWeight: 600, letterSpacing: '0.1em', color: '#6b7280', textTransform: 'uppercase', marginBottom: 8 }}>Πρόσφατες Παραγγελίες</div>
|
||||
{recent.length === 0 ? (
|
||||
<div style={{ padding: '12px 14px', borderRadius: 10, background: 'rgba(255,255,255,0.03)', border: '1px dashed rgba(255,255,255,0.08)', fontSize: 12, color: '#4b5563', textAlign: 'center' }}>
|
||||
Δεν υπάρχουν παραγγελίες ακόμα
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
{recent.map(order => (
|
||||
<div key={order.id} style={{
|
||||
display: 'flex', alignItems: 'center', gap: 10,
|
||||
padding: '9px 12px', borderRadius: 10,
|
||||
background: 'rgba(255,255,255,0.04)', border: '1px solid rgba(255,255,255,0.06)',
|
||||
}}>
|
||||
<Clock size={12} color="#6b7280" style={{ flexShrink: 0 }} />
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<div style={{ fontSize: 12, color: '#d1d5db', fontVariantNumeric: 'tabular-nums' }}>
|
||||
{formatDate(order.opened_at)}
|
||||
{order.table_name && <span style={{ color: '#6b7280' }}> · {order.table_name}</span>}
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: '#6b7280', marginTop: 1 }}>{order.item_count} είδη</div>
|
||||
</div>
|
||||
<div style={{ fontSize: 13, fontWeight: 600, color: '#d4a853', fontVariantNumeric: 'tabular-nums' }}>{formatCurrency(order.total)}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{ padding: '20px 24px' }}>
|
||||
<button onClick={onClose} style={{
|
||||
width: '100%', padding: '11px 0', borderRadius: 10, border: 'none', cursor: 'pointer',
|
||||
background: 'rgba(212,168,83,0.12)', color: '#d4a853', fontSize: 13, fontWeight: 600,
|
||||
letterSpacing: '0.02em', transition: 'all 0.15s',
|
||||
}}
|
||||
onMouseEnter={e => { e.currentTarget.style.background = 'rgba(212,168,83,0.2)' }}
|
||||
onMouseLeave={e => { e.currentTarget.style.background = 'rgba(212,168,83,0.12)' }}
|
||||
>Κλείσιμο</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/* ─── Unknown caller modal ────────────────────────────────────────────────── */
|
||||
function UnknownCallerModal({ call, onClose }) {
|
||||
return (
|
||||
<div style={{ fontFamily: "'DM Sans','Segoe UI',sans-serif" }}>
|
||||
<div onClick={onClose} style={{
|
||||
position: 'fixed', inset: 0, zIndex: 9990,
|
||||
background: 'rgba(0,0,0,0.65)', backdropFilter: 'blur(8px)',
|
||||
animation: 'fadeIn 0.2s ease',
|
||||
}} />
|
||||
<div style={{
|
||||
position: 'fixed', zIndex: 9991,
|
||||
top: '50%', left: '50%',
|
||||
transform: 'translate(-50%,-50%)',
|
||||
width: '100%', maxWidth: 360, padding: '0 16px',
|
||||
animation: 'slideUp 0.3s cubic-bezier(0.16,1,0.3,1)',
|
||||
}}>
|
||||
<div style={{
|
||||
background: '#0f1117', borderRadius: 20, overflow: 'hidden',
|
||||
boxShadow: '0 32px 80px rgba(0,0,0,0.8),0 0 0 1px rgba(255,255,255,0.06)',
|
||||
}}>
|
||||
<div style={{ height: 3, background: 'linear-gradient(90deg,#3b82f6,#6366f1,#3b82f6)' }} />
|
||||
<div style={{ padding: '28px 24px 24px', position: 'relative' }}>
|
||||
<button onClick={onClose} style={{
|
||||
position: 'absolute', top: 20, right: 20,
|
||||
width: 32, height: 32, borderRadius: 8,
|
||||
background: 'rgba(255,255,255,0.07)', border: '1px solid rgba(255,255,255,0.1)',
|
||||
color: '#9ca3af', cursor: 'pointer',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}
|
||||
onMouseEnter={e => { e.currentTarget.style.background = 'rgba(255,255,255,0.12)'; e.currentTarget.style.color = '#fff' }}
|
||||
onMouseLeave={e => { e.currentTarget.style.background = 'rgba(255,255,255,0.07)'; e.currentTarget.style.color = '#9ca3af' }}
|
||||
><X size={14} /></button>
|
||||
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 20 }}>
|
||||
<div style={{ position: 'relative', width: 44, height: 44 }}>
|
||||
<RippleRings color="#3b82f6" />
|
||||
<div style={{
|
||||
width: 44, height: 44, borderRadius: '50%',
|
||||
background: 'linear-gradient(135deg,#1d4ed8,#3b82f6)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
position: 'relative', zIndex: 1,
|
||||
}}><PhoneIncoming size={18} color="#fff" /></div>
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ fontSize: 10, fontWeight: 600, letterSpacing: '0.12em', color: '#3b82f6', textTransform: 'uppercase' }}>Εισερχόμενη Κλήση</div>
|
||||
<div style={{ fontSize: 12, color: '#6b7280', marginTop: 1 }}>{formatTime(call.at)}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 8, padding: '20px 0 8px' }}>
|
||||
<div style={{
|
||||
width: 56, height: 56, borderRadius: 14,
|
||||
background: 'rgba(255,255,255,0.05)', border: '1px solid rgba(255,255,255,0.08)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}><User size={24} color="#4b5563" /></div>
|
||||
<div style={{ fontSize: 12, color: '#6b7280' }}>Άγνωστος καλών</div>
|
||||
<div style={{ fontSize: 28, fontWeight: 700, color: '#f9fafb', letterSpacing: '0.02em', fontVariantNumeric: 'tabular-nums' }}>
|
||||
{call.caller || '—'}
|
||||
</div>
|
||||
{call.ext && <div style={{ fontSize: 12, color: '#6b7280' }}>Εσωτερικό: {call.ext}</div>}
|
||||
</div>
|
||||
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<button onClick={onClose} style={{
|
||||
width: '100%', padding: '11px 0', borderRadius: 10, border: 'none', cursor: 'pointer',
|
||||
background: 'rgba(59,130,246,0.1)', color: '#3b82f6', fontSize: 13, fontWeight: 600,
|
||||
transition: 'all 0.15s',
|
||||
}}
|
||||
onMouseEnter={e => { e.currentTarget.style.background = 'rgba(59,130,246,0.18)' }}
|
||||
onMouseLeave={e => { e.currentTarget.style.background = 'rgba(59,130,246,0.1)' }}
|
||||
>Κλείσιμο</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/* ─── PhoneListener ───────────────────────────────────────────────────────── */
|
||||
export default function PhoneListener() {
|
||||
const { activeCall, dismissCall, setActiveCall, addCallToLog } = usePhoneStore()
|
||||
const [customers, setCustomers] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
client.get('/api/customers/')
|
||||
.then(r => setCustomers(r.data || []))
|
||||
.catch(() => {})
|
||||
}, [])
|
||||
|
||||
const handleIncoming = useCallback(async ({ caller, ext }) => {
|
||||
const at = new Date()
|
||||
const matched = customers.find(c => phonesMatch(c.phone, caller))
|
||||
let orders = null
|
||||
if (matched) {
|
||||
try {
|
||||
const r = await client.get(`/api/customers/${matched.id}/orders`)
|
||||
orders = r.data?.orders ?? []
|
||||
} catch { orders = [] }
|
||||
}
|
||||
const entry = { caller, ext, at, customer: matched || null, orders }
|
||||
addCallToLog(entry)
|
||||
setActiveCall(entry)
|
||||
}, [customers, addCallToLog, setActiveCall])
|
||||
|
||||
useEffect(() => {
|
||||
let ws, dead = false
|
||||
function connect() {
|
||||
if (dead) return
|
||||
ws = new WebSocket(buildWsUrl())
|
||||
ws.onclose = () => { if (!dead) setTimeout(connect, 3000) }
|
||||
ws.onerror = () => ws.close()
|
||||
ws.onmessage = (ev) => {
|
||||
try {
|
||||
const data = JSON.parse(ev.data)
|
||||
if (data.type === 'incoming_call') handleIncoming({ caller: data.caller, ext: data.ext })
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
connect()
|
||||
return () => { dead = true; ws?.close() }
|
||||
}, [handleIncoming])
|
||||
|
||||
if (!activeCall) return null
|
||||
|
||||
return (
|
||||
<>
|
||||
<style>{`
|
||||
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
|
||||
@keyframes slideUp {
|
||||
from{opacity:0;transform:translate(-50%,calc(-50% + 24px))}
|
||||
to{opacity:1;transform:translate(-50%,-50%)}
|
||||
}
|
||||
@keyframes phoneRipple {
|
||||
0%{transform:scale(1);opacity:0.6}
|
||||
100%{transform:scale(2.8);opacity:0}
|
||||
}
|
||||
`}</style>
|
||||
{activeCall.customer
|
||||
? <KnownCustomerModal call={activeCall} customer={activeCall.customer} orders={activeCall.orders} onClose={dismissCall} />
|
||||
: <UnknownCallerModal call={activeCall} onClose={dismissCall} />
|
||||
}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,24 +1,227 @@
|
||||
import { NavLink } from 'react-router-dom'
|
||||
import { NavLink, useLocation } from 'react-router-dom'
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { BarChart2, LayoutGrid, ClipboardList, Package, Settings, ChevronRight, ChevronLeft, ShoppingBag, NotebookPen, Receipt, BookUser, Users, CreditCard, Trash2, ChefHat, CalendarDays } from 'lucide-react'
|
||||
import {
|
||||
LayoutDashboard, LayoutGrid, ShoppingBag,
|
||||
BookUser, Users, Receipt, CreditCard,
|
||||
Package, TableProperties, UserCog, CalendarDays, Trash2, Boxes,
|
||||
BarChart2, TrendingUp, Users2, ShoppingCart, Tag, Activity, Printer, Ban, Percent, ConciergeBell, FileText,
|
||||
AppWindow, Settings, ChevronDown, CookingPot, StickyNote,
|
||||
} from 'lucide-react'
|
||||
import { getIncomingOrders } from '../api/client'
|
||||
import { isFeatureEnabled } from '../hooks/usePhase2Features'
|
||||
import usePermissions from '../hooks/usePermissions'
|
||||
|
||||
// Phase 2 feature IDs mapped to their sidebar routes (must match usePhase2Features defs)
|
||||
const PHASE2_ROUTES = new Set(['/notes', '/expenses', '/contacts', '/customers', '/tabs', '/waste', '/kds', '/schedule'])
|
||||
// ─── Nav structure ────────────────────────────────────────────────────────────
|
||||
|
||||
// `perm` — key from usePermissions(). If set, item is hidden when user lacks that permission.
|
||||
function buildNav(pendingCount) {
|
||||
return [
|
||||
{
|
||||
category: 'Operation',
|
||||
items: [
|
||||
{ type: 'solo', to: '/dashboard', icon: LayoutDashboard, label: 'Εικόνα' },
|
||||
{ type: 'solo', to: '/tables', icon: LayoutGrid, label: 'Τραπέζια' },
|
||||
{ type: 'solo', to: '/online-orders', icon: ShoppingBag, label: 'Online Παραγγ.', badge: pendingCount, phase2: 'online-orders' },
|
||||
],
|
||||
},
|
||||
{
|
||||
category: 'Financial',
|
||||
items: [
|
||||
{
|
||||
type: 'group', id: 'crm', icon: BookUser, label: 'CRM',
|
||||
children: [
|
||||
{ to: '/crm/contacts', icon: BookUser, label: 'Επαφές', phase2: 'contacts' },
|
||||
{ to: '/crm/customers', icon: Users, label: 'Πελάτες', phase2: 'customers' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'group', id: 'financials', icon: Receipt, label: 'Οικονομικά',
|
||||
children: [
|
||||
{ to: '/financials/expenses', icon: Receipt, label: 'Έξοδα', phase2: 'expenses' },
|
||||
{ to: '/financials/tabs', icon: CreditCard, label: 'Καρτέλες Πελ.', phase2: 'tabs' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
category: 'Headquarters',
|
||||
items: [
|
||||
{
|
||||
type: 'group', id: 'management', icon: Package, label: 'Διαχείριση',
|
||||
children: [
|
||||
{ to: '/management/products', icon: Package, label: 'Προϊόντα', perm: 'manageMenu' },
|
||||
{ to: '/management/tables', icon: TableProperties, label: 'Τραπέζια', perm: 'manageTables' },
|
||||
{ to: '/management/staff', icon: UserCog, label: 'Προσωπικό', perm: 'manageStaff' },
|
||||
{ to: '/management/schedule', icon: CalendarDays, label: 'Πρόγραμμα', perm: 'manageStaff', phase2: 'schedule' },
|
||||
{ to: '/management/prep-zones', icon: CookingPot, label: 'Ζώνες Ετοιμασίας', perm: 'manageMenu' },
|
||||
{ to: '/management/pricing', icon: Percent, label: 'Προσφορές & Τιμές', perm: 'manageMenu' },
|
||||
{ to: '/notes', icon: StickyNote, label: 'Σημειώσεις' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'group', id: 'inventory', icon: Boxes, label: 'Αποθήκη',
|
||||
children: [
|
||||
{ to: '/inventory/throwaways', icon: Trash2, label: 'Απορρίμματα', phase2: 'waste' },
|
||||
{ to: '/inventory/stock', icon: Boxes, label: 'Απόθεμα', placeholder: true },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
category: 'Overwatch',
|
||||
perm: 'viewReports',
|
||||
items: [
|
||||
{
|
||||
type: 'group', id: 'reports', icon: BarChart2, label: 'Αναφορές',
|
||||
children: [
|
||||
{ to: '/reports/today', icon: Activity, label: 'Σήμερα' },
|
||||
{ to: '/reports/store', icon: TrendingUp, label: 'Κατάστημα' },
|
||||
{ to: '/reports/staff', icon: Users2, label: 'Προσωπικό' },
|
||||
{ to: '/reports/products', icon: ShoppingCart, label: 'Προϊόντα' },
|
||||
{ to: '/reports/prep-zones', icon: ConciergeBell, label: 'Ζώνες Ετοιμασίας' },
|
||||
{ to: '/reports/expenses', icon: FileText, label: 'Έξοδα' },
|
||||
{ to: '/reports/technical', icon: Printer, label: 'Τεχνικά' },
|
||||
{ to: '/reports/misc', icon: Tag, label: 'Λοιπά' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
const BOTTOM_ITEMS = [
|
||||
{ to: '/apps', icon: AppWindow, label: 'Εφαρμογές' },
|
||||
{ to: '/settings', icon: Settings, label: 'Ρυθμίσεις', perm: 'manageSettings' },
|
||||
]
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function isChildActive(children, pathname) {
|
||||
return children.some(c => pathname === c.to || pathname.startsWith(c.to + '/'))
|
||||
}
|
||||
|
||||
// ─── Child link ───────────────────────────────────────────────────────────────
|
||||
|
||||
function ChildLink({ to, icon: Icon, label, placeholder }) {
|
||||
if (placeholder) {
|
||||
return (
|
||||
<div className="flex items-center gap-2.5 px-3 py-2 mx-2 rounded-md text-[13px] text-primary-400 cursor-default select-none">
|
||||
<Icon size={14} className="shrink-0 opacity-50" />
|
||||
<span>{label}</span>
|
||||
<span className="ml-auto text-[10px] font-semibold bg-primary-700 text-primary-300 px-1.5 py-0.5 rounded">soon</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<NavLink
|
||||
to={to}
|
||||
end
|
||||
className={({ isActive }) =>
|
||||
`flex items-center gap-2.5 px-3 py-2 mx-2 rounded-md text-[13px] font-medium transition-colors ` +
|
||||
(isActive
|
||||
? 'bg-primary-600 text-white'
|
||||
: 'text-primary-200 hover:bg-primary-700 hover:text-white')
|
||||
}
|
||||
>
|
||||
{({ isActive }) => (
|
||||
<>
|
||||
<Icon size={14} className="shrink-0" />
|
||||
<span>{label}</span>
|
||||
{isActive && <span className="ml-auto w-1 h-1 rounded-full bg-sky-400 shrink-0" />}
|
||||
</>
|
||||
)}
|
||||
</NavLink>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Group item (collapsible parent) ─────────────────────────────────────────
|
||||
|
||||
function GroupItem({ id, icon: Icon, label, children, openGroup, onToggle, perms }) {
|
||||
const location = useLocation()
|
||||
const hasActive = isChildActive(children, location.pathname)
|
||||
const isOpen = openGroup === id
|
||||
|
||||
// Filter out phase2-gated children and children the user lacks permission for
|
||||
const visibleChildren = children.filter(c => {
|
||||
if (c.phase2 && !isFeatureEnabled(c.phase2)) return false
|
||||
if (c.perm && !perms[c.perm]) return false
|
||||
return true
|
||||
})
|
||||
|
||||
if (visibleChildren.length === 0) return null
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button
|
||||
onClick={() => onToggle(id)}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors ` +
|
||||
(hasActive
|
||||
? 'text-white bg-primary-700'
|
||||
: 'text-primary-100 hover:bg-primary-700 hover:text-white')}
|
||||
>
|
||||
<Icon size={18} className="shrink-0" />
|
||||
<span className="flex-1 text-left">{label}</span>
|
||||
<ChevronDown
|
||||
size={14}
|
||||
className={`shrink-0 transition-transform duration-200 ${isOpen ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{isOpen && (
|
||||
<div className="mt-0.5 mb-1 space-y-0.5 py-1 border-l border-primary-600 ml-5">
|
||||
{visibleChildren.map(child => (
|
||||
<ChildLink key={child.to} {...child} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Solo item (direct link) ──────────────────────────────────────────────────
|
||||
|
||||
function SoloItem({ to, icon: Icon, label, badge, onNavigate }) {
|
||||
return (
|
||||
<NavLink
|
||||
to={to}
|
||||
end
|
||||
onClick={onNavigate}
|
||||
className={({ isActive }) =>
|
||||
`flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors ` +
|
||||
(isActive ? 'bg-primary-600 text-white' : 'text-primary-100 hover:bg-primary-700 hover:text-white')
|
||||
}
|
||||
>
|
||||
<div className="relative shrink-0">
|
||||
<Icon size={18} />
|
||||
{badge > 0 && (
|
||||
<span className="absolute -top-1.5 -right-1.5 bg-red-500 text-white text-[10px] font-bold w-4 h-4 rounded-full flex items-center justify-center leading-none">
|
||||
{badge > 9 ? '9+' : badge}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span>{label}</span>
|
||||
</NavLink>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Sidebar ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function Sidebar() {
|
||||
const [collapsed, setCollapsed] = useState(false)
|
||||
const [pendingCount, setPendingCount] = useState(0)
|
||||
const [openGroup, setOpenGroup] = useState(null)
|
||||
const [, featTick] = useState(0)
|
||||
const location = useLocation()
|
||||
const pollRef = useRef(null)
|
||||
const perms = usePermissions()
|
||||
|
||||
// Online orders badge polling
|
||||
useEffect(() => {
|
||||
async function fetchPending() {
|
||||
try {
|
||||
const { data } = await getIncomingOrders()
|
||||
setPendingCount(data.length)
|
||||
} catch { /* silently ignore — sidebar badge is non-critical */ }
|
||||
} catch { /* non-critical */ }
|
||||
}
|
||||
fetchPending()
|
||||
pollRef.current = setInterval(fetchPending, 20_000)
|
||||
@@ -36,62 +239,93 @@ export default function Sidebar() {
|
||||
}
|
||||
}, [])
|
||||
|
||||
const ALL_NAV = [
|
||||
{ to: '/dashboard', icon: BarChart2, label: 'Dashboard' },
|
||||
{ to: '/tables', icon: LayoutGrid, label: 'Τραπέζια' },
|
||||
{ to: '/online-orders', icon: ShoppingBag, label: 'Online Orders', badge: pendingCount, phase2: 'online-orders' },
|
||||
{ to: '/reports', icon: ClipboardList, label: 'Αναφορές' },
|
||||
{ to: '/management', icon: Package, label: 'Διαχείριση' },
|
||||
{ to: '/notes', icon: NotebookPen, label: 'Σημειώσεις', phase2: 'notes' },
|
||||
{ to: '/expenses', icon: Receipt, label: 'Έξοδα', phase2: 'expenses' },
|
||||
{ to: '/contacts', icon: BookUser, label: 'Επαφές', phase2: 'contacts' },
|
||||
{ to: '/customers', icon: Users, label: 'Πελάτες', phase2: 'customers' },
|
||||
{ to: '/tabs', icon: CreditCard, label: 'Καρτέλες', phase2: 'tabs' },
|
||||
{ to: '/waste', icon: Trash2, label: 'Αποβλήτα', phase2: 'waste' },
|
||||
{ to: '/kds', icon: ChefHat, label: 'KDS', phase2: 'kds' },
|
||||
{ to: '/schedule', icon: CalendarDays, label: 'Πρόγραμμα', phase2: 'schedule' },
|
||||
{ to: '/settings', icon: Settings, label: 'Ρυθμίσεις' },
|
||||
]
|
||||
// Auto-open the group that contains the active route on location change
|
||||
useEffect(() => {
|
||||
const nav = buildNav(0)
|
||||
for (const section of nav) {
|
||||
for (const item of section.items) {
|
||||
if (item.type === 'group' && isChildActive(item.children, location.pathname)) {
|
||||
setOpenGroup(item.id)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [location.pathname])
|
||||
|
||||
// Filter out disabled Phase 2 entries
|
||||
const NAV = ALL_NAV.filter(item => !item.phase2 || isFeatureEnabled(item.phase2))
|
||||
function handleGroupToggle(id) {
|
||||
setOpenGroup(prev => (prev === id ? null : id))
|
||||
}
|
||||
|
||||
function handleSoloClick() {
|
||||
setOpenGroup(null)
|
||||
}
|
||||
|
||||
const nav = buildNav(pendingCount)
|
||||
|
||||
return (
|
||||
<aside className={`flex flex-col bg-primary-800 text-white shrink-0 transition-all duration-200 ${collapsed ? 'w-16' : 'w-56'}`}>
|
||||
{/* Logo / collapse toggle */}
|
||||
<div className="flex items-center justify-between px-4 py-4 border-b border-primary-700">
|
||||
{!collapsed && <span className="font-bold text-lg tracking-wide">XeniaPOS</span>}
|
||||
<button
|
||||
onClick={() => setCollapsed(c => !c)}
|
||||
className="p-1 rounded hover:bg-primary-700 transition-colors ml-auto"
|
||||
aria-label="Toggle sidebar"
|
||||
>
|
||||
{collapsed ? <ChevronRight size={18} /> : <ChevronLeft size={18} />}
|
||||
</button>
|
||||
<aside className="flex flex-col bg-primary-800 text-white shrink-0 w-56 h-full sidebar-scroll">
|
||||
{/* Brand */}
|
||||
<div className="flex items-center px-4 py-4 border-b border-primary-700 shrink-0">
|
||||
<span className="font-bold text-lg tracking-wide">XeniaPOS</span>
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 py-4 space-y-1 px-2">
|
||||
{NAV.map(({ to, icon: Icon, label, badge }) => (
|
||||
<NavLink
|
||||
key={to}
|
||||
to={to}
|
||||
className={({ isActive }) =>
|
||||
`flex items-center gap-3 px-3 py-3 rounded-lg font-medium transition-colors min-h-[44px] ` +
|
||||
(isActive ? 'bg-primary-600 text-white' : 'text-primary-100 hover:bg-primary-700')
|
||||
{/* Main nav */}
|
||||
<nav className="flex-1 py-3 px-2 space-y-4">
|
||||
{nav.map(({ category, perm: sectionPerm, items }) => {
|
||||
// Hide entire section if user lacks section-level permission
|
||||
if (sectionPerm && !perms[sectionPerm]) return null
|
||||
|
||||
const visibleItems = items.filter(item => {
|
||||
if (item.type === 'solo') {
|
||||
if (item.perm && !perms[item.perm]) return false
|
||||
return !item.phase2 || isFeatureEnabled(item.phase2)
|
||||
}
|
||||
>
|
||||
<div className="relative shrink-0">
|
||||
<Icon size={20} />
|
||||
{badge > 0 && (
|
||||
<span className="absolute -top-1.5 -right-1.5 bg-red-500 text-white text-[10px] font-bold w-4 h-4 rounded-full flex items-center justify-center leading-none">
|
||||
{badge > 9 ? '9+' : badge}
|
||||
if (item.type === 'group') {
|
||||
const visible = item.children.filter(c => {
|
||||
if (c.phase2 && !isFeatureEnabled(c.phase2)) return false
|
||||
if (c.perm && !perms[c.perm]) return false
|
||||
return true
|
||||
})
|
||||
return visible.length > 0
|
||||
}
|
||||
return true
|
||||
})
|
||||
if (visibleItems.length === 0) return null
|
||||
|
||||
return (
|
||||
<div key={category}>
|
||||
<div className="flex items-center gap-2 px-3 mb-1.5 select-none" style={{ opacity: 0.45 }}>
|
||||
<span className="text-[9.5px] font-bold uppercase tracking-widest text-primary-100 whitespace-nowrap">
|
||||
{category}
|
||||
</span>
|
||||
)}
|
||||
<div className="flex-1" style={{ height: 1, background: 'rgba(255,255,255,0.2)' }} />
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
{visibleItems.map(item =>
|
||||
item.type === 'solo' ? (
|
||||
<SoloItem key={item.to} {...item} onNavigate={handleSoloClick} />
|
||||
) : (
|
||||
<GroupItem
|
||||
key={item.id}
|
||||
{...item}
|
||||
openGroup={openGroup}
|
||||
onToggle={handleGroupToggle}
|
||||
perms={perms}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{!collapsed && <span className="text-sm">{label}</span>}
|
||||
</NavLink>
|
||||
))}
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Divider + bottom items */}
|
||||
<div className="shrink-0 px-2 pb-3 border-t border-primary-700 pt-3 space-y-0.5">
|
||||
{BOTTOM_ITEMS.filter(item => !item.perm || perms[item.perm]).map(item => (
|
||||
<SoloItem key={item.to} {...item} onNavigate={handleSoloClick} />
|
||||
))}
|
||||
</div>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ function fmtDateTime(iso) {
|
||||
return d.toLocaleString('el-GR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' })
|
||||
}
|
||||
|
||||
const MANAGER_ROLES = new Set(['superadmin', 'owner', 'store_manager', 'staff_manager'])
|
||||
function roleBadge(role) {
|
||||
if (role === 'manager' || role === 'sysadmin') {
|
||||
if (MANAGER_ROLES.has(role)) {
|
||||
return { label: 'Διευθυντής', bg: '#ede9fe', color: '#6d28d9' }
|
||||
}
|
||||
return { label: 'Σερβιτόρος', bg: '#e0f2fe', color: '#0369a1' }
|
||||
|
||||
Reference in New Issue
Block a user