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,810 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import toast from 'react-hot-toast'
|
||||
import {
|
||||
Plus, Pencil, Trash2, Printer, X, Check, ChevronDown,
|
||||
Zap, Settings2, ArrowUpDown, Layers, CheckSquare, SkipForward,
|
||||
GripVertical, ChevronUp, AlertTriangle, FlameKindling,
|
||||
} from 'lucide-react'
|
||||
import client from '../../api/client'
|
||||
|
||||
// ── API ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
const fetchZones = () => client.get('/api/prep-zones').then(r => r.data)
|
||||
const fetchPrinters = () => client.get('/api/system/printers').then(r => r.data)
|
||||
const fetchCategories = () => client.get('/api/products/categories').then(r => r.data)
|
||||
|
||||
// ── Constants ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const AUTO_PRINT_OPTIONS = [
|
||||
{ value: 'none', label: 'Χωρίς εκτύπωση', desc: 'Μη αυτόματη εκτύπωση' },
|
||||
{ value: 'master', label: 'Μόνο κύριος', desc: 'Εκτύπωση στον κύριο' },
|
||||
{ value: 'all', label: 'Όλοι εκτυπωτές', desc: 'Master + δευτερεύοντες' },
|
||||
]
|
||||
|
||||
const SORT_OPTIONS = [
|
||||
{ value: 'order_time', label: 'Σειρά παραγγελίας', desc: 'Όπως προστέθηκαν στο καλάθι' },
|
||||
{ value: 'item_count', label: 'Πλήθος (φθίνον)', desc: 'Πρώτα τα αντικείμενα με τη μεγαλύτερη ποσότητα' },
|
||||
{ value: 'alpha', label: 'Αλφαβητικά', desc: 'Ταξινόμηση κατά όνομα' },
|
||||
]
|
||||
|
||||
const EMPTY_ZONE = {
|
||||
name: '', description: '', notification_name: '',
|
||||
printer_ids: [], master_printer_id: null,
|
||||
auto_print: 'none', master_copies: 1, secondary_copies: 1,
|
||||
sort_items_by: 'order_time', group_by_category: false, category_order: [], print_checkboxes: false,
|
||||
bypass_pending: false, bypass_kds: false, auto_ready_to_served: false,
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
function Toggle({ value, onChange, disabled }) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => !disabled && onChange(!value)}
|
||||
disabled={disabled}
|
||||
className={`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors duration-200 focus:outline-none
|
||||
${value ? 'bg-primary-600' : 'bg-gray-200'} ${disabled ? 'opacity-40 cursor-not-allowed' : 'cursor-pointer'}`}
|
||||
>
|
||||
<span className={`inline-block h-3.5 w-3.5 rounded-full bg-white shadow transition-transform duration-200
|
||||
${value ? 'translate-x-4' : 'translate-x-0.5'}`} />
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function CopySpinner({ value, onChange, min = 1, max = 9 }) {
|
||||
return (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange(Math.max(min, value - 1))}
|
||||
className="w-8 h-8 rounded-lg border border-gray-300 flex items-center justify-center text-gray-600 hover:bg-gray-100 hover:border-gray-400 transition-colors text-base font-medium"
|
||||
>−</button>
|
||||
<span className="w-9 text-center text-sm font-bold text-gray-800 tabular-nums">{value}×</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange(Math.min(max, value + 1))}
|
||||
className="w-8 h-8 rounded-lg border border-gray-300 flex items-center justify-center text-gray-600 hover:bg-gray-100 hover:border-gray-400 transition-colors text-base font-medium"
|
||||
>+</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Click-outside hook for dropdowns ─────────────────────────────────────────
|
||||
|
||||
function useClickOutside(ref, onClose) {
|
||||
useEffect(() => {
|
||||
function handle(e) {
|
||||
if (ref.current && !ref.current.contains(e.target)) onClose()
|
||||
}
|
||||
document.addEventListener('mousedown', handle)
|
||||
return () => document.removeEventListener('mousedown', handle)
|
||||
}, [ref, onClose])
|
||||
}
|
||||
|
||||
// ── Master printer single-select ──────────────────────────────────────────────
|
||||
|
||||
function MasterPrinterPicker({ printers, value, onChange }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const ref = useRef(null)
|
||||
useClickOutside(ref, () => setOpen(false))
|
||||
const selected = printers.find(p => p.id === value)
|
||||
|
||||
return (
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(v => !v)}
|
||||
className="w-full flex items-center justify-between gap-2 px-3 py-2 border border-gray-300 rounded-lg bg-white text-sm text-left hover:border-gray-400 transition-colors"
|
||||
>
|
||||
<span className="flex items-center gap-2 flex-1 min-w-0">
|
||||
{selected ? (
|
||||
<>
|
||||
<span className="w-2 h-2 rounded-full bg-green-500 shrink-0" />
|
||||
<span className="font-medium text-gray-800 truncate">{selected.name}</span>
|
||||
<span className="text-xs text-gray-400 font-mono ml-auto shrink-0">{selected.ip_address}:{selected.port}</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-gray-400">— Χωρίς κύριο —</span>
|
||||
)}
|
||||
</span>
|
||||
<ChevronDown size={13} className={`text-gray-400 shrink-0 transition-transform ${open ? 'rotate-180' : ''}`} />
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute z-50 top-full left-0 right-0 mt-1 bg-white border border-gray-200 rounded-xl shadow-xl overflow-hidden">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { onChange(null); setOpen(false) }}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2.5 text-sm text-left transition-colors hover:bg-gray-50 ${!value ? 'bg-gray-50' : ''}`}
|
||||
>
|
||||
<span className="w-4 h-4 rounded border border-gray-300 flex items-center justify-center shrink-0">
|
||||
{!value && <Check size={10} className="text-gray-600" />}
|
||||
</span>
|
||||
<span className="text-gray-400 italic text-xs">Χωρίς κύριο εκτυπωτή</span>
|
||||
</button>
|
||||
{printers.map(p => (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
onClick={() => { onChange(p.id); setOpen(false) }}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2.5 text-sm text-left transition-colors hover:bg-gray-50 ${value === p.id ? 'bg-primary-50' : ''}`}
|
||||
>
|
||||
<span className={`w-4 h-4 rounded border flex items-center justify-center shrink-0 ${value === p.id ? 'bg-primary-600 border-primary-600' : 'border-gray-300'}`}>
|
||||
{value === p.id && <Check size={10} className="text-white" />}
|
||||
</span>
|
||||
<Printer size={13} className="text-gray-400 shrink-0" />
|
||||
<span className={`flex-1 ${value === p.id ? 'font-semibold text-primary-700' : 'text-gray-700'}`}>{p.name}</span>
|
||||
<span className="text-xs text-gray-400 font-mono">{p.ip_address}:{p.port}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Secondary printers multi-select ──────────────────────────────────────────
|
||||
|
||||
function SecondaryPrinterPicker({ printers, selected, masterId, onChange }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const ref = useRef(null)
|
||||
useClickOutside(ref, () => setOpen(false))
|
||||
|
||||
const selectedSet = new Set(selected)
|
||||
const eligible = printers.filter(p => p.id !== masterId)
|
||||
const selectedPrinters = eligible.filter(p => selectedSet.has(p.id))
|
||||
|
||||
const toggle = (id) => {
|
||||
const next = new Set(selectedSet)
|
||||
if (next.has(id)) next.delete(id); else next.add(id)
|
||||
onChange([...next])
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(v => !v)}
|
||||
className="w-full flex items-center justify-between gap-2 px-3 py-2 border border-gray-300 rounded-lg bg-white text-sm text-left hover:border-gray-400 transition-colors min-h-[38px]"
|
||||
>
|
||||
<span className="flex flex-wrap gap-1 flex-1 min-w-0">
|
||||
{selectedPrinters.length === 0 ? (
|
||||
<span className="text-gray-400">— Χωρίς δευτερεύοντες —</span>
|
||||
) : (
|
||||
selectedPrinters.map(p => (
|
||||
<span key={p.id} className="inline-flex items-center gap-1 bg-gray-100 text-gray-600 rounded px-1.5 py-0.5 text-xs font-medium">
|
||||
<Printer size={10} />{p.name}
|
||||
</span>
|
||||
))
|
||||
)}
|
||||
</span>
|
||||
<ChevronDown size={13} className={`text-gray-400 shrink-0 transition-transform ${open ? 'rotate-180' : ''}`} />
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute z-50 top-full left-0 right-0 mt-1 bg-white border border-gray-200 rounded-xl shadow-xl overflow-hidden">
|
||||
{eligible.length === 0 ? (
|
||||
<div className="px-3 py-4 text-sm text-gray-400 text-center italic">
|
||||
{printers.length <= 1 ? 'Δεν υπάρχουν άλλοι εκτυπωτές' : 'Ο μόνος εκτυπωτής είναι ο κύριος'}
|
||||
</div>
|
||||
) : eligible.map(p => {
|
||||
const on = selectedSet.has(p.id)
|
||||
return (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
onClick={() => toggle(p.id)}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2.5 text-sm text-left transition-colors hover:bg-gray-50 ${on ? 'bg-gray-50' : ''}`}
|
||||
>
|
||||
<span className={`w-4 h-4 rounded border flex items-center justify-center shrink-0 ${on ? 'bg-gray-700 border-gray-700' : 'border-gray-300'}`}>
|
||||
{on && <Check size={10} className="text-white" />}
|
||||
</span>
|
||||
<Printer size={13} className="text-gray-400 shrink-0" />
|
||||
<span className={`flex-1 ${on ? 'font-semibold text-gray-800' : 'text-gray-700'}`}>{p.name}</span>
|
||||
<span className="text-xs text-gray-400 font-mono">{p.ip_address}:{p.port}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
<div className="border-t border-gray-100 px-3 py-2 text-xs text-gray-400 italic">
|
||||
Κλικ έξω για κλείσιμο
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Category order modal ──────────────────────────────────────────────────────
|
||||
|
||||
function CategoryOrderModal({ categories, order, onSave, onClose }) {
|
||||
const ranked = order.map(id => categories.find(c => c.id === id)).filter(Boolean)
|
||||
const unranked = categories.filter(c => !order.includes(c.id))
|
||||
const [list, setList] = useState([...ranked, ...unranked])
|
||||
const dragIdx = useRef(null)
|
||||
|
||||
const onDragStart = (i) => { dragIdx.current = i }
|
||||
const onDragOver = (e, i) => {
|
||||
e.preventDefault()
|
||||
if (dragIdx.current === null || dragIdx.current === i) return
|
||||
const next = [...list]
|
||||
const [moved] = next.splice(dragIdx.current, 1)
|
||||
next.splice(i, 0, moved)
|
||||
dragIdx.current = i
|
||||
setList(next)
|
||||
}
|
||||
const onDragEnd = () => { dragIdx.current = null }
|
||||
const move = (i, dir) => {
|
||||
const j = i + dir
|
||||
if (j < 0 || j >= list.length) return
|
||||
const next = [...list];
|
||||
[next[i], next[j]] = [next[j], next[i]]
|
||||
setList(next)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4">
|
||||
<div className="bg-white rounded-2xl shadow-2xl w-full max-w-md overflow-hidden">
|
||||
<div className="px-5 py-4 border-b border-gray-100 flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-sm font-bold text-gray-900">Σειρά Κατηγοριών Εκτύπωσης</h2>
|
||||
<p className="text-xs text-gray-500 mt-0.5">Σύρετε για αλλαγή σειράς</p>
|
||||
</div>
|
||||
<button type="button" onClick={onClose} className="p-1.5 rounded-lg text-gray-400 hover:text-gray-600 hover:bg-gray-100 transition-colors">
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="px-3 py-3 max-h-80 overflow-y-auto space-y-1">
|
||||
{list.map((cat, i) => (
|
||||
<div
|
||||
key={cat.id}
|
||||
draggable
|
||||
onDragStart={() => onDragStart(i)}
|
||||
onDragOver={e => onDragOver(e, i)}
|
||||
onDragEnd={onDragEnd}
|
||||
className="flex items-center gap-2.5 px-3 py-2.5 bg-gray-50 rounded-xl border border-gray-100 cursor-grab active:cursor-grabbing select-none group hover:bg-white hover:border-gray-200 hover:shadow-sm transition-all"
|
||||
>
|
||||
<GripVertical size={14} className="text-gray-300 group-hover:text-gray-400 shrink-0" />
|
||||
<span className="w-2.5 h-2.5 rounded-full shrink-0" style={{ background: cat.color || '#94a3b8' }} />
|
||||
<span className="text-sm text-gray-700 font-medium flex-1 min-w-0 truncate">{cat.name}</span>
|
||||
<div className="flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<button type="button" onClick={() => move(i, -1)} disabled={i === 0}
|
||||
className="p-1 rounded text-gray-400 hover:text-gray-600 disabled:opacity-20">
|
||||
<ChevronUp size={13} />
|
||||
</button>
|
||||
<button type="button" onClick={() => move(i, 1)} disabled={i === list.length - 1}
|
||||
className="p-1 rounded text-gray-400 hover:text-gray-600 disabled:opacity-20">
|
||||
<ChevronDown size={13} />
|
||||
</button>
|
||||
</div>
|
||||
<span className="text-xs text-gray-300 font-mono w-5 text-right shrink-0">{i + 1}</span>
|
||||
</div>
|
||||
))}
|
||||
{list.length === 0 && (
|
||||
<div className="py-8 text-center text-sm text-gray-400">Δεν υπάρχουν κατηγορίες</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="px-5 py-4 border-t border-gray-100 flex gap-2 justify-end">
|
||||
<button type="button" onClick={onClose} className="btn btn-secondary">Ακύρωση</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { onSave(list.map(c => c.id)); onClose() }}
|
||||
className="btn btn-primary flex items-center gap-2"
|
||||
>
|
||||
<Check size={14} /> Αποθήκευση σειράς
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Section header ────────────────────────────────────────────────────────────
|
||||
|
||||
function Section({ icon: Icon_, label, children }) {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center gap-2 pb-1.5 border-b border-gray-100">
|
||||
<Icon_ size={13} className="text-gray-400" />
|
||||
<span className="text-[11px] font-bold text-gray-400 uppercase tracking-widest">{label}</span>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Toggle row ────────────────────────────────────────────────────────────────
|
||||
|
||||
function ToggleRow({ label, desc, value, onChange, disabled, children, warning }) {
|
||||
return (
|
||||
<div className={`rounded-xl border transition-colors ${value ? 'border-primary-200 bg-primary-50/40' : 'border-gray-200 bg-gray-50/40'} ${disabled ? 'opacity-60' : ''}`}>
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="text-sm font-semibold text-gray-800">{label}</span>
|
||||
{warning && <AlertTriangle size={12} className="text-amber-500 shrink-0" />}
|
||||
</div>
|
||||
{desc && <p className="text-xs text-gray-500 mt-0.5 leading-relaxed">{desc}</p>}
|
||||
</div>
|
||||
<Toggle value={value} onChange={onChange} disabled={disabled} />
|
||||
</div>
|
||||
{value && children && (
|
||||
<div className="px-4 pb-3">{children}</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Zone Form ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function ZoneForm({ initial, printers, categories, onSave, onCancel, saving }) {
|
||||
const z = initial || EMPTY_ZONE
|
||||
const [name, setName] = useState(z.name)
|
||||
const [description, setDesc] = useState(z.description || '')
|
||||
const [notifName, setNotifName] = useState(z.notification_name || '')
|
||||
const [allPrinterIds, setAllPrinterIds] = useState(z.printer_ids || [])
|
||||
const [masterId, setMasterId] = useState(z.master_printer_id ?? null)
|
||||
const [autoPrint, setAutoPrint] = useState(z.auto_print || 'none')
|
||||
const [masterCopies, setMasterCopies] = useState(z.master_copies || 1)
|
||||
const [secondaryCopies, setSecondaryCopies] = useState(z.secondary_copies || 1)
|
||||
const [sortBy, setSortBy] = useState(z.sort_items_by || 'order_time')
|
||||
const [groupCat, setGroupCat] = useState(z.group_by_category || false)
|
||||
const [catOrder, setCatOrder] = useState(z.category_order || [])
|
||||
const [checkboxes, setCheckboxes] = useState(z.print_checkboxes || false)
|
||||
const [bypassPending, setBypassPending] = useState(z.bypass_pending || false)
|
||||
const [bypassKds, setBypassKds] = useState(z.bypass_kds || false)
|
||||
const [autoReadyServed, setAutoReadyServed] = useState(z.auto_ready_to_served || false)
|
||||
const [catModal, setCatModal] = useState(false)
|
||||
|
||||
const secondaryIds = allPrinterIds.filter(id => id !== masterId)
|
||||
|
||||
const handleMasterChange = (id) => {
|
||||
setMasterId(id)
|
||||
if (id && !allPrinterIds.includes(id)) setAllPrinterIds(prev => [...prev, id])
|
||||
}
|
||||
|
||||
const handleSecondaryChange = (ids) => {
|
||||
const next = new Set(ids)
|
||||
if (masterId) next.add(masterId)
|
||||
setAllPrinterIds([...next])
|
||||
}
|
||||
|
||||
const handleBypassKds = (v) => { setBypassKds(v); if (v) setBypassPending(true) }
|
||||
const handleBypassPending = (v) => { setBypassPending(v); if (!v) setBypassKds(false) }
|
||||
|
||||
const valid = name.trim().length > 0
|
||||
|
||||
const submit = (e) => {
|
||||
e.preventDefault()
|
||||
if (!valid) return
|
||||
onSave({
|
||||
name: name.trim(),
|
||||
description: description.trim() || null,
|
||||
notification_name: notifName.trim() || null,
|
||||
printer_ids: allPrinterIds,
|
||||
master_printer_id: masterId || null,
|
||||
auto_print: autoPrint,
|
||||
master_copies: masterCopies,
|
||||
secondary_copies: secondaryCopies,
|
||||
sort_items_by: sortBy,
|
||||
group_by_category: groupCat,
|
||||
category_order: catOrder,
|
||||
print_checkboxes: checkboxes,
|
||||
bypass_pending: bypassPending,
|
||||
bypass_kds: bypassKds,
|
||||
auto_ready_to_served: autoReadyServed,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<form onSubmit={submit} className="space-y-5">
|
||||
|
||||
{/* Identity */}
|
||||
<Section icon={Settings2} label="Στοιχεία Ζώνης">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="label">Όνομα ζώνης *</label>
|
||||
<input className="input" value={name} onChange={e => setName(e.target.value)}
|
||||
placeholder="π.χ. Kitchen – Grill" autoFocus />
|
||||
</div>
|
||||
<div>
|
||||
<label className="label">Όνομα ειδοποίησης</label>
|
||||
<input className="input" value={notifName} onChange={e => setNotifName(e.target.value)}
|
||||
placeholder="π.χ. Κουζίνα" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="label">Περιγραφή</label>
|
||||
<input className="input" value={description} onChange={e => setDesc(e.target.value)}
|
||||
placeholder="Προαιρετική περιγραφή" />
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* Printers */}
|
||||
<Section icon={Printer} label="Εκτυπωτές">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="label">Κύριος εκτυπωτής</label>
|
||||
<MasterPrinterPicker printers={printers} value={masterId} onChange={handleMasterChange} />
|
||||
<p className="mt-1 text-xs text-gray-400">Ένας μόνο, υψηλή προτεραιότητα.</p>
|
||||
</div>
|
||||
<div>
|
||||
<label className="label">Δευτερεύοντες εκτυπωτές</label>
|
||||
<SecondaryPrinterPicker
|
||||
printers={printers} selected={secondaryIds}
|
||||
masterId={masterId} onChange={handleSecondaryChange}
|
||||
/>
|
||||
<p className="mt-1 text-xs text-gray-400">Μόνο στη λειτουργία «Όλοι».</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="label">Αυτόματη εκτύπωση</label>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{AUTO_PRINT_OPTIONS.map(opt => (
|
||||
<button key={opt.value} type="button" onClick={() => setAutoPrint(opt.value)}
|
||||
className={`px-3 py-2.5 rounded-xl border text-left transition-all
|
||||
${autoPrint === opt.value
|
||||
? 'border-primary-500 bg-primary-50 ring-1 ring-primary-500'
|
||||
: 'border-gray-200 hover:border-gray-300 bg-white'}`}>
|
||||
<div className={`text-xs font-bold leading-tight ${autoPrint === opt.value ? 'text-primary-700' : 'text-gray-700'}`}>{opt.label}</div>
|
||||
<div className="text-[11px] text-gray-400 mt-0.5">{opt.desc}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{autoPrint !== 'none' && (
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="label">Αντίτυπα κύριου</label>
|
||||
<CopySpinner value={masterCopies} onChange={setMasterCopies} />
|
||||
</div>
|
||||
{autoPrint === 'all' && (
|
||||
<div>
|
||||
<label className="label">Αντίτυπα δευτερευόντων</label>
|
||||
<CopySpinner value={secondaryCopies} onChange={setSecondaryCopies} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
{/* Ticket formatting */}
|
||||
<Section icon={ArrowUpDown} label="Μορφοποίηση Δελτίου">
|
||||
<div>
|
||||
<label className="label">Ταξινόμηση αντικειμένων</label>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{SORT_OPTIONS.map(opt => (
|
||||
<button key={opt.value} type="button" onClick={() => setSortBy(opt.value)}
|
||||
className={`px-3 py-2.5 rounded-xl border text-left transition-all
|
||||
${sortBy === opt.value
|
||||
? 'border-primary-500 bg-primary-50 ring-1 ring-primary-500'
|
||||
: 'border-gray-200 hover:border-gray-300 bg-white'}`}>
|
||||
<div className={`text-xs font-bold leading-tight ${sortBy === opt.value ? 'text-primary-700' : 'text-gray-700'}`}>{opt.label}</div>
|
||||
<div className="text-[11px] text-gray-400 mt-0.5">{opt.desc}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<ToggleRow
|
||||
label="Ομαδοποίηση κατά κατηγορία"
|
||||
desc="Αντικείμενα ομαδοποιούνται ανά κατηγορία."
|
||||
value={groupCat} onChange={setGroupCat}
|
||||
>
|
||||
<button type="button" onClick={() => setCatModal(true)}
|
||||
className="mt-1 inline-flex items-center gap-1.5 text-xs font-semibold text-primary-600 hover:text-primary-700 bg-white border border-primary-200 rounded-lg px-3 py-1.5 hover:bg-primary-50 transition-colors">
|
||||
<Layers size={12} />
|
||||
Σειρά κατηγοριών
|
||||
{catOrder.length > 0 && (
|
||||
<span className="bg-primary-100 text-primary-700 rounded px-1 text-[10px] font-bold">{catOrder.length}</span>
|
||||
)}
|
||||
</button>
|
||||
</ToggleRow>
|
||||
|
||||
<ToggleRow
|
||||
label="Checkboxes"
|
||||
desc="Προσθέτει [ ] πριν από κάθε αντικείμενο."
|
||||
value={checkboxes} onChange={setCheckboxes}
|
||||
/>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* KDS Behavior */}
|
||||
<Section icon={Zap} label="Συμπεριφορά KDS">
|
||||
<div className="grid grid-cols-1 gap-3">
|
||||
<ToggleRow
|
||||
label="Παράκαμψη Pending & Prep"
|
||||
desc="Αντικείμενα ξεκινούν απευθείας σε READY. Χρήσιμο για ποτά ή μπύρες."
|
||||
value={bypassPending} onChange={handleBypassPending}
|
||||
/>
|
||||
<ToggleRow
|
||||
label="Παράκαμψη KDS Status"
|
||||
desc="Αντικείμενα πηγαίνουν κατευθείαν σε SERVED. Ενεργοποιεί αυτόματα και την Παράκαμψη Pending."
|
||||
value={bypassKds} onChange={handleBypassKds} warning
|
||||
/>
|
||||
<ToggleRow
|
||||
label="Αυτόματο Ready → Served"
|
||||
desc="Όταν ο σεφ επισημαίνει READY στο KDS, αυτόματα αναβαθμίζεται και σε SERVED."
|
||||
value={autoReadyServed} onChange={setAutoReadyServed}
|
||||
/>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex gap-3 justify-end pt-3 border-t border-gray-100">
|
||||
<button type="button" onClick={onCancel} className="btn btn-secondary">
|
||||
Ακύρωση
|
||||
</button>
|
||||
<button type="submit" disabled={!valid || saving} className="btn btn-primary flex items-center gap-2">
|
||||
<Check size={15} />
|
||||
{saving ? 'Αποθήκευση…' : 'Αποθήκευση'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{catModal && (
|
||||
<CategoryOrderModal
|
||||
categories={categories} order={catOrder}
|
||||
onSave={setCatOrder} onClose={() => setCatModal(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Zone Card ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function Badge({ children, variant = 'default' }) {
|
||||
const cls = {
|
||||
default: 'bg-gray-100 text-gray-600',
|
||||
primary: 'bg-primary-100 text-primary-700',
|
||||
green: 'bg-green-100 text-green-700',
|
||||
amber: 'bg-amber-100 text-amber-700',
|
||||
red: 'bg-red-100 text-red-700',
|
||||
}[variant] || 'bg-gray-100 text-gray-600'
|
||||
return (
|
||||
<span className={`inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[11px] font-semibold ${cls}`}>
|
||||
{children}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function ZoneCard({ zone, printers, onEdit, onDelete }) {
|
||||
const [confirmDelete, setConfirmDelete] = useState(false)
|
||||
const printerMap = Object.fromEntries(printers.map(p => [p.id, p]))
|
||||
const masterPrinter = printerMap[zone.master_printer_id]
|
||||
const secondaryPrinters = (zone.secondary_printer_ids || []).map(id => printerMap[id]).filter(Boolean)
|
||||
|
||||
const printLabel = {
|
||||
none: { text: 'Χωρίς εκτύπωση', variant: 'default' },
|
||||
master: { text: 'Κύριος μόνο', variant: 'primary' },
|
||||
all: { text: 'Όλοι', variant: 'primary' },
|
||||
}[zone.auto_print] || { text: '—', variant: 'default' }
|
||||
|
||||
const sortLabel = {
|
||||
order_time: 'Σειρά παρ.',
|
||||
item_count: 'Κατά πλήθος',
|
||||
alpha: 'Αλφαβητικά',
|
||||
}[zone.sort_items_by] || zone.sort_items_by
|
||||
|
||||
return (
|
||||
<div className="bg-white border border-gray-200 rounded-2xl shadow-sm overflow-hidden hover:shadow-md hover:border-gray-300 transition-all group">
|
||||
<div className="px-4 pt-4 pb-3 flex items-start justify-between gap-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<h3 className="font-bold text-gray-900 text-sm leading-tight">{zone.name}</h3>
|
||||
{zone.bypass_kds && <Badge variant="red"><Zap size={10} />Bypass KDS</Badge>}
|
||||
{!zone.bypass_kds && zone.bypass_pending && <Badge variant="amber"><SkipForward size={10} />Bypass Pending</Badge>}
|
||||
{zone.auto_ready_to_served && <Badge variant="green"><Check size={10} />Auto Served</Badge>}
|
||||
</div>
|
||||
{zone.notification_name && (
|
||||
<p className="text-xs text-primary-600 font-medium mt-0.5">{zone.notification_name}</p>
|
||||
)}
|
||||
{zone.description && <p className="text-xs text-gray-400 mt-0.5">{zone.description}</p>}
|
||||
</div>
|
||||
<div className="flex gap-0.5 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<button onClick={() => onEdit(zone)}
|
||||
className="p-1.5 rounded-lg text-gray-400 hover:text-primary-600 hover:bg-primary-50 transition-colors">
|
||||
<Pencil size={13} />
|
||||
</button>
|
||||
{!confirmDelete ? (
|
||||
<button onClick={() => setConfirmDelete(true)}
|
||||
className="p-1.5 rounded-lg text-gray-400 hover:text-red-600 hover:bg-red-50 transition-colors">
|
||||
<Trash2 size={13} />
|
||||
</button>
|
||||
) : (
|
||||
<div className="flex gap-1 items-center">
|
||||
<button onClick={() => setConfirmDelete(false)}
|
||||
className="p-1.5 rounded-lg text-gray-400 hover:bg-gray-100 transition-colors">
|
||||
<X size={13} />
|
||||
</button>
|
||||
<button onClick={() => onDelete(zone.id)}
|
||||
className="px-2 py-1 rounded-lg text-xs font-bold bg-red-600 text-white hover:bg-red-700 transition-colors">
|
||||
Διαγραφή
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="px-4 pb-3 space-y-1.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-[10px] font-bold text-gray-400 uppercase tracking-wide w-14 shrink-0">Κύριος</span>
|
||||
{masterPrinter ? (
|
||||
<>
|
||||
<span className="inline-flex items-center gap-1 bg-primary-50 text-primary-700 rounded-md px-2 py-0.5 text-xs font-medium">
|
||||
<Printer size={10} />{masterPrinter.name}
|
||||
</span>
|
||||
{zone.auto_print !== 'none' && (
|
||||
<span className="text-xs text-gray-400 font-mono">{zone.master_copies}×</span>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<span className="text-xs text-gray-400 italic">Χωρίς</span>
|
||||
)}
|
||||
</div>
|
||||
{secondaryPrinters.length > 0 && (
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="text-[10px] font-bold text-gray-400 uppercase tracking-wide w-14 shrink-0">Δευτ.</span>
|
||||
{secondaryPrinters.map(p => (
|
||||
<span key={p.id} className="inline-flex items-center gap-1 bg-gray-100 text-gray-600 rounded-md px-2 py-0.5 text-xs font-medium">
|
||||
<Printer size={10} />{p.name}
|
||||
</span>
|
||||
))}
|
||||
{zone.auto_print === 'all' && (
|
||||
<span className="text-xs text-gray-400 font-mono">{zone.secondary_copies}×</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="px-4 py-2.5 border-t border-gray-100 bg-gray-50/60 flex flex-wrap gap-1.5 items-center">
|
||||
<Badge variant={zone.auto_print !== 'none' ? 'primary' : 'default'}>{printLabel.text}</Badge>
|
||||
<Badge>{sortLabel}</Badge>
|
||||
{zone.group_by_category && <Badge><Layers size={10} />Κατά κατηγορία</Badge>}
|
||||
{zone.print_checkboxes && <Badge><CheckSquare size={10} />Checkboxes</Badge>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Main Page ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function PrepZonesConfigPage() {
|
||||
const qc = useQueryClient()
|
||||
const [showForm, setShowForm] = useState(false)
|
||||
const [editing, setEditing] = useState(null)
|
||||
|
||||
const { data: zones = [], isLoading: lZ } = useQuery({ queryKey: ['prep-zones'], queryFn: fetchZones })
|
||||
const { data: printers = [], isLoading: lP } = useQuery({ queryKey: ['printers'], queryFn: fetchPrinters })
|
||||
const { data: categories = [], isLoading: lC } = useQuery({ queryKey: ['categories'], queryFn: fetchCategories })
|
||||
|
||||
const invalidate = () => qc.invalidateQueries({ queryKey: ['prep-zones'] })
|
||||
|
||||
const create = useMutation({
|
||||
mutationFn: body => client.post('/api/prep-zones', body).then(r => r.data),
|
||||
onSuccess: () => { invalidate(); setShowForm(false); toast.success('Ζώνη δημιουργήθηκε') },
|
||||
onError: () => toast.error('Σφάλμα κατά τη δημιουργία'),
|
||||
})
|
||||
const update = useMutation({
|
||||
mutationFn: ({ id, ...body }) => client.put(`/api/prep-zones/${id}`, body).then(r => r.data),
|
||||
onSuccess: () => { invalidate(); setEditing(null); toast.success('Ζώνη ενημερώθηκε') },
|
||||
onError: () => toast.error('Σφάλμα κατά την ενημέρωση'),
|
||||
})
|
||||
const remove = useMutation({
|
||||
mutationFn: id => client.delete(`/api/prep-zones/${id}`),
|
||||
onSuccess: () => { invalidate(); toast.success('Ζώνη διαγράφηκε') },
|
||||
onError: () => toast.error('Σφάλμα κατά τη διαγραφή'),
|
||||
})
|
||||
|
||||
if (lZ || lP || lC) {
|
||||
return (
|
||||
<div className="p-8 flex items-center gap-3 text-sm text-gray-400">
|
||||
<div className="w-4 h-4 rounded-full border-2 border-gray-300 border-t-primary-500 animate-spin" />
|
||||
Φόρτωση…
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const flatCategories = categories.flatMap(c => [c, ...(c.subcategories || [])])
|
||||
const formOpen = showForm || !!editing
|
||||
|
||||
return (
|
||||
// h-full + overflow-y-auto makes this page scroll within the fixed AppLayout <main>
|
||||
<div className="h-full overflow-y-auto">
|
||||
<div className="p-6">
|
||||
{/* Page header */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="w-8 h-8 rounded-xl bg-orange-100 flex items-center justify-center shrink-0">
|
||||
<FlameKindling size={16} className="text-orange-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-gray-900 leading-tight">Ζώνες Προετοιμασίας</h1>
|
||||
<p className="text-sm text-gray-500">Ζώνες, εκτυπωτές και συμπεριφορά KDS</p>
|
||||
</div>
|
||||
</div>
|
||||
{!formOpen && (
|
||||
<button onClick={() => setShowForm(true)} className="btn btn-primary flex items-center gap-2 shrink-0">
|
||||
<Plus size={15} />
|
||||
Νέα Ζώνη
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Two-column layout when form is open */}
|
||||
{formOpen ? (
|
||||
<div className="grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)] gap-6 items-start xl:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]">
|
||||
{/* Form panel */}
|
||||
<div className={`bg-white rounded-2xl p-6 shadow-sm border ${showForm ? 'border-primary-200' : 'border-amber-200'}`}>
|
||||
<div className="flex items-center gap-2 mb-5">
|
||||
<div className={`w-1 h-5 rounded-full ${showForm ? 'bg-primary-500' : 'bg-amber-400'}`} />
|
||||
<h2 className="text-sm font-bold text-gray-800">
|
||||
{showForm ? 'Νέα Ζώνη Προετοιμασίας' : `Επεξεργασία: ${editing?.name}`}
|
||||
</h2>
|
||||
</div>
|
||||
<ZoneForm
|
||||
initial={editing}
|
||||
printers={printers}
|
||||
categories={flatCategories}
|
||||
onSave={showForm
|
||||
? (body) => create.mutate(body)
|
||||
: (body) => update.mutate({ id: editing.id, ...body })}
|
||||
onCancel={() => { setShowForm(false); setEditing(null) }}
|
||||
saving={create.isPending || update.isPending}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Zone list sidebar */}
|
||||
<div className="space-y-3">
|
||||
{zones.length === 0 ? (
|
||||
<div className="text-center py-10 text-gray-400 bg-white rounded-2xl border border-gray-200">
|
||||
<FlameKindling size={24} className="mx-auto mb-2 text-gray-300" />
|
||||
<p className="text-sm">Δεν υπάρχουν ζώνες ακόμα</p>
|
||||
</div>
|
||||
) : zones.map(zone => (
|
||||
<ZoneCard
|
||||
key={zone.id}
|
||||
zone={zone}
|
||||
printers={printers}
|
||||
onEdit={z => { setShowForm(false); setEditing(z) }}
|
||||
onDelete={id => remove.mutate(id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
/* Full-width zone grid when no form open */
|
||||
zones.length === 0 ? (
|
||||
<div className="text-center py-20 text-gray-400">
|
||||
<div className="w-16 h-16 mx-auto mb-4 rounded-2xl bg-gray-100 flex items-center justify-center">
|
||||
<FlameKindling size={28} className="text-gray-300" />
|
||||
</div>
|
||||
<div className="font-semibold text-gray-600 mb-1">Δεν υπάρχουν ζώνες ακόμα</div>
|
||||
<p className="text-sm">Δημιουργήστε την πρώτη ζώνη για να αρχίσετε.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||
{zones.map(zone => (
|
||||
<ZoneCard
|
||||
key={zone.id}
|
||||
zone={zone}
|
||||
printers={printers}
|
||||
onEdit={z => { setShowForm(false); setEditing(z) }}
|
||||
onDelete={id => remove.mutate(id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { useState } from 'react'
|
||||
import { Percent, Tag, Gift, Users } from 'lucide-react'
|
||||
import { TabGroup, TabCard } from '../../ui/Tabs'
|
||||
import PriceGroupsTab from './pricing/PriceGroupsTab'
|
||||
import ModifiersTab from './pricing/ModifiersTab'
|
||||
import DealsTab from './pricing/DealsTab'
|
||||
import DiscountSettingsTab from './pricing/DiscountSettingsTab'
|
||||
|
||||
const TABS = [
|
||||
{ id: 'groups', label: 'Ομάδες Τιμών', icon: Tag },
|
||||
{ id: 'modifiers', label: 'Τροποποιητές Τιμής', icon: Percent },
|
||||
{ id: 'deals', label: 'Προσφορές', icon: Gift },
|
||||
{ id: 'discounts', label: 'Ρυθμίσεις Εκπτώσεων', icon: Users },
|
||||
]
|
||||
|
||||
export default function PricingPage() {
|
||||
const [tab, setTab] = useState('groups')
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0 p-6 gap-4">
|
||||
{/* Page header */}
|
||||
<div className="flex items-center gap-3 shrink-0">
|
||||
<div className="w-9 h-9 rounded-xl bg-sky-100 flex items-center justify-center shrink-0">
|
||||
<Percent className="w-5 h-5 text-sky-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-[15px] font-semibold text-slate-900">Προσφορές & Τιμές</h1>
|
||||
<p className="text-[12px] text-slate-500">Δυναμικές τιμές, τροποποιητές, προσφορές και εκπτώσεις</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<TabCard className="flex-1">
|
||||
<TabGroup tabs={TABS} active={tab} onChange={setTab} />
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
{tab === 'groups' && <PriceGroupsTab />}
|
||||
{tab === 'modifiers' && <ModifiersTab />}
|
||||
{tab === 'deals' && <DealsTab />}
|
||||
{tab === 'discounts' && <DiscountSettingsTab />}
|
||||
</div>
|
||||
</TabCard>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../api/client'
|
||||
|
||||
@@ -76,7 +76,7 @@ function PriceInput({ value, onChange, placeholder, className = '', allowNegativ
|
||||
)
|
||||
}
|
||||
|
||||
function SubChoiceRows({ subChoices, onMove, onToggleDefault, onChange, onRemove, onAdd, parentLabel }) {
|
||||
function SubChoiceRows({ subChoices, onMove, onToggleDefault, onChange, onRemove, onAdd, parentLabel, showMultiple = false }) {
|
||||
if (!subChoices || subChoices.length === 0) return null
|
||||
return (
|
||||
<div className="border-t border-gray-100 bg-indigo-50/40 px-3 py-2 space-y-2">
|
||||
@@ -84,14 +84,28 @@ function SubChoiceRows({ subChoices, onMove, onToggleDefault, onChange, onRemove
|
||||
Υπο-επιλογές του «{parentLabel || '…'}»
|
||||
</p>
|
||||
{subChoices.map((sc, sci) => (
|
||||
<div key={sci} className="flex items-center gap-2 ml-4">
|
||||
<div key={sci} className="flex items-center gap-2 ml-4 flex-wrap">
|
||||
<ReorderBtns onUp={() => onMove(sci, -1)} onDown={() => onMove(sci, 1)}
|
||||
disableUp={sci === 0} disableDown={sci === subChoices.length - 1} />
|
||||
<DefaultBtn isDefault={sc.is_default} onClick={() => onToggleDefault(sci)} />
|
||||
<input className="input flex-1 text-sm" placeholder="π.χ. Καραμέλα"
|
||||
<input className="input flex-1 min-w-28 text-sm" placeholder="π.χ. Καραμέλα"
|
||||
value={sc.name} onChange={e => onChange(sci, 'name', e.target.value)} />
|
||||
<PriceInput value={sc.extra_cost} onChange={v => onChange(sci, 'extra_cost', v)}
|
||||
allowNegative className="w-28 text-sm" />
|
||||
{showMultiple && (
|
||||
<label className="flex items-center gap-1 text-xs text-gray-600 cursor-pointer shrink-0 select-none">
|
||||
<input type="checkbox" checked={sc.allow_multiple ?? false}
|
||||
onChange={e => onChange(sci, 'allow_multiple', e.target.checked)}
|
||||
className="accent-primary-700 w-3.5 h-3.5" />
|
||||
Πολλαπλά
|
||||
</label>
|
||||
)}
|
||||
<label className="flex items-center gap-1 text-xs cursor-pointer shrink-0 select-none" style={{ color: sc.is_compact ? '#7c3aed' : '#6b7280' }}>
|
||||
<input type="checkbox" checked={sc.is_compact ?? false}
|
||||
onChange={e => onChange(sci, 'is_compact', e.target.checked)}
|
||||
className="w-3.5 h-3.5" style={{ accentColor: '#7c3aed' }} />
|
||||
Compact
|
||||
</label>
|
||||
<button onClick={() => onRemove(sci)} className="btn btn-danger px-2 min-h-0 h-9 text-sm shrink-0">✕</button>
|
||||
</div>
|
||||
))}
|
||||
@@ -102,6 +116,40 @@ function SubChoiceRows({ subChoices, onMove, onToggleDefault, onChange, onRemove
|
||||
)
|
||||
}
|
||||
|
||||
// ── Group helpers ─────────────────────────────────────────────────────────────
|
||||
function GroupHeader({ group, onRename, onDelete, collapsed, onToggle }) {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [val, setVal] = useState(group.name)
|
||||
return (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, marginTop: 8 }}>
|
||||
<button type="button" onClick={onToggle}
|
||||
className="flex items-center gap-2 flex-1 px-3 py-2 rounded-lg bg-indigo-50 border border-indigo-200 text-indigo-700 font-semibold text-sm text-left hover:bg-indigo-100 transition-colors">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"
|
||||
style={{ transform: collapsed ? 'rotate(-90deg)' : 'rotate(0deg)', transition: 'transform 180ms', flexShrink: 0 }}>
|
||||
<path d="M6 9L12 15L18 9" strokeLinecap="round"/>
|
||||
</svg>
|
||||
{editing ? (
|
||||
<input
|
||||
className="input flex-1 text-sm py-0 h-6 min-w-0"
|
||||
value={val}
|
||||
onChange={e => setVal(e.target.value)}
|
||||
onBlur={() => { onRename(val); setEditing(false) }}
|
||||
onKeyDown={e => { if (e.key === 'Enter') e.target.blur() }}
|
||||
onClick={e => e.stopPropagation()}
|
||||
autoFocus
|
||||
/>
|
||||
) : (
|
||||
<span className="flex-1 truncate">{group.name || '(αχρησιμοποίητη ομάδα)'}</span>
|
||||
)}
|
||||
</button>
|
||||
<button type="button" onClick={e => { e.stopPropagation(); setVal(group.name); setEditing(true) }}
|
||||
className="w-7 h-7 rounded text-gray-400 hover:text-indigo-600 hover:bg-indigo-50 flex items-center justify-center text-xs">✎</button>
|
||||
<button type="button" onClick={onDelete}
|
||||
className="w-7 h-7 rounded text-gray-400 hover:text-red-500 hover:bg-red-50 flex items-center justify-center text-xs">✕</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Form builder ──────────────────────────────────────────────────────────────
|
||||
function buildFormFromProduct(product) {
|
||||
return {
|
||||
@@ -109,9 +157,10 @@ function buildFormFromProduct(product) {
|
||||
description: product.description || '',
|
||||
category_id: product.category_id ?? '',
|
||||
base_price: product.base_price ?? '',
|
||||
unit_type: product.unit_type ?? 'piece',
|
||||
is_available: product.is_available ?? true,
|
||||
lifecycle_status: product.lifecycle_status ?? 'active',
|
||||
printer_zone_id: product.printer_zone_id ?? '',
|
||||
prep_zone_ids: product.prep_zone_ids ?? [],
|
||||
quick_options: product.quick_options?.map(q => ({
|
||||
name: q.name, price: q.price ?? 0, allow_multiple: q.allow_multiple ?? false,
|
||||
sort_order: q.sort_order ?? 0, is_favorite: q.is_favorite ?? false,
|
||||
@@ -119,25 +168,32 @@ function buildFormFromProduct(product) {
|
||||
})) ?? [],
|
||||
options: product.options?.map(o => ({
|
||||
name: o.name, extra_cost: o.extra_cost ?? 0, allow_multiple: o.allow_multiple ?? false,
|
||||
sub_choices: o.sub_choices?.map(s => ({ name: s.name, extra_cost: s.extra_cost ?? 0, is_default: s.is_default ?? false })) ?? [],
|
||||
multi_select: o.multi_select ?? false, is_compact: o.is_compact ?? false,
|
||||
sub_choices: o.sub_choices?.map(s => ({ name: s.name, extra_cost: s.extra_cost ?? 0, is_default: s.is_default ?? false, allow_multiple: s.allow_multiple ?? false, is_compact: s.is_compact ?? false })) ?? [],
|
||||
is_favorite: o.is_favorite ?? false, favorite_sort_order: o.favorite_sort_order ?? 0,
|
||||
group_id: o.group_id ?? null,
|
||||
})) ?? [],
|
||||
ingredients: product.ingredients?.map(i => ({
|
||||
name: i.name, extra_cost: i.extra_cost ?? 0,
|
||||
is_favorite: i.is_favorite ?? false, favorite_sort_order: i.favorite_sort_order ?? 0,
|
||||
is_compact: i.is_compact ?? false, group_id: i.group_id ?? null,
|
||||
})) ?? [],
|
||||
preference_sets: product.preference_sets?.map(ps => ({
|
||||
name: ps.name,
|
||||
default_choice_index: ps.choices ? ps.choices.findIndex(c => c.id === ps.default_choice_id) : -1,
|
||||
choices: ps.choices?.map(c => ({
|
||||
name: c.name, extra_cost: c.extra_cost ?? 0, disables_subset: c.disables_subset ?? false,
|
||||
sub_choices: c.sub_choices?.map(s => ({ name: s.name, extra_cost: s.extra_cost ?? 0, is_default: s.is_default ?? false })) ?? [],
|
||||
is_compact: c.is_compact ?? false,
|
||||
sub_choices: c.sub_choices?.map(s => ({ name: s.name, extra_cost: s.extra_cost ?? 0, is_default: s.is_default ?? false, is_compact: s.is_compact ?? false })) ?? [],
|
||||
})) ?? [],
|
||||
group_id: ps.group_id ?? null,
|
||||
shared_subset: ps.shared_subset ? {
|
||||
name: ps.shared_subset.name,
|
||||
choices: ps.shared_subset.choices?.map(s => ({ name: s.name, extra_cost: s.extra_cost ?? 0, is_default: s.is_default ?? false })) ?? [],
|
||||
} : null,
|
||||
is_favorite: ps.is_favorite ?? false, favorite_sort_order: ps.favorite_sort_order ?? 0,
|
||||
allow_multi_select: ps.allow_multi_select ?? false,
|
||||
allow_choice_quantity: ps.allow_choice_quantity ?? false,
|
||||
})) ?? [],
|
||||
digital_visible: product.digital_visible ?? true,
|
||||
digital_available: product.digital_available ?? true,
|
||||
@@ -152,6 +208,18 @@ function buildFormFromProduct(product) {
|
||||
cost_breakdown: product.cost_breakdown?.length
|
||||
? product.cost_breakdown.map(e => ({ label: e.label, amount: e.amount }))
|
||||
: [],
|
||||
// Quick Add
|
||||
quick_add_enabled: product.quick_add_enabled ?? true,
|
||||
// Tags
|
||||
tags: product.tags ?? [],
|
||||
tagsInput: '',
|
||||
// Service items
|
||||
is_service_item: product.is_service_item ?? false,
|
||||
// Fiscal printer (ΦΗΜ)
|
||||
fiscal_name: product.fiscal_name ?? '',
|
||||
fiscal_vat_group_id: product.fiscal_vat_group_id ?? null,
|
||||
// Modifier groups (folders) — keyed by _tempId in form, id from server
|
||||
modifier_groups: (product.modifier_groups || []).map(g => ({ _tempId: g.id, id: g.id, modifier_type: g.modifier_type, name: g.name, sort_order: g.sort_order })),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +257,7 @@ function getItemTypeLabel(type) {
|
||||
}
|
||||
|
||||
// ── Main modal ────────────────────────────────────────────────────────────────
|
||||
export default function ProductFormModal({ product, categories, printers, onSave, onCopy, onClose }) {
|
||||
export default function ProductFormModal({ product, categories, printers, prepZones = [], onSave, onCopy, onClose }) {
|
||||
const [form, setForm] = useState(() => buildFormFromProduct(product))
|
||||
const [activeTab, setActiveTab] = useState('favorites')
|
||||
const [leftTab, setLeftTab] = useState('info')
|
||||
@@ -197,6 +265,17 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
const [uploading, setUploading] = useState(false)
|
||||
const qc = useQueryClient()
|
||||
|
||||
// Fetch fiscal VAT groups from settings (needed for the Ταμειακή tab dropdown)
|
||||
const { data: settingsData } = useQuery({
|
||||
queryKey: ['pos-settings'],
|
||||
queryFn: () => client.get('/api/settings/').then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
const fiscalEnabled = settingsData?.['fiscal.enabled']?.value === 'true'
|
||||
const vatGroups = (() => {
|
||||
try { return JSON.parse(settingsData?.['fiscal.vat_groups']?.value || '[]') } catch { return [] }
|
||||
})()
|
||||
|
||||
useEffect(() => {
|
||||
function onKey(e) { if (e.key === 'Escape') onClose() }
|
||||
window.addEventListener('keydown', onKey)
|
||||
@@ -251,14 +330,14 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
function moveQuickOption(i, dir) { setForm(f => ({ ...f, quick_options: moveItem(f.quick_options, i, dir) })) }
|
||||
|
||||
// Options
|
||||
function addOption() { setForm(f => ({ ...f, options: [...f.options, { name: '', extra_cost: 0, allow_multiple: false, sub_choices: [], is_favorite: false, favorite_sort_order: 0 }] })) }
|
||||
function addOption() { setForm(f => ({ ...f, options: [...f.options, { name: '', extra_cost: 0, allow_multiple: false, multi_select: false, is_compact: false, sub_choices: [], is_favorite: false, favorite_sort_order: 0 }] })) }
|
||||
function removeOption(i) { setForm(f => ({ ...f, options: f.options.filter((_, idx) => idx !== i) })) }
|
||||
function setOption(i, k, v) { setForm(f => ({ ...f, options: f.options.map((o, idx) => idx === i ? { ...o, [k]: v } : o) })) }
|
||||
function moveOption(i, dir) { setForm(f => ({ ...f, options: moveItem(f.options, i, dir) })) }
|
||||
|
||||
function addOptionSubChoice(oi) {
|
||||
setForm(f => ({ ...f, options: f.options.map((o, idx) =>
|
||||
idx !== oi ? o : { ...o, sub_choices: [...(o.sub_choices || []), { name: '', extra_cost: 0, is_default: false }] }
|
||||
idx !== oi ? o : { ...o, sub_choices: [...(o.sub_choices || []), { name: '', extra_cost: 0, is_default: false, allow_multiple: false, is_compact: false }] }
|
||||
)}))
|
||||
}
|
||||
function removeOptionSubChoice(oi, sci) {
|
||||
@@ -287,14 +366,14 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
}
|
||||
|
||||
// Ingredients
|
||||
function addIngredient() { setForm(f => ({ ...f, ingredients: [...f.ingredients, { name: '', extra_cost: 0, is_favorite: false, favorite_sort_order: 0 }] })) }
|
||||
function addIngredient() { setForm(f => ({ ...f, ingredients: [...f.ingredients, { name: '', extra_cost: 0, is_favorite: false, favorite_sort_order: 0, is_compact: false }] })) }
|
||||
function removeIngredient(i) { setForm(f => ({ ...f, ingredients: f.ingredients.filter((_, idx) => idx !== i) })) }
|
||||
function setIngredient(i, k, v) { setForm(f => ({ ...f, ingredients: f.ingredients.map((ing, idx) => idx === i ? { ...ing, [k]: v } : ing) })) }
|
||||
function moveIngredient(i, dir) { setForm(f => ({ ...f, ingredients: moveItem(f.ingredients, i, dir) })) }
|
||||
|
||||
// Preference sets
|
||||
function addPrefSet() {
|
||||
setForm(f => ({ ...f, preference_sets: [...f.preference_sets, { name: '', default_choice_index: -1, choices: [], shared_subset: null, is_favorite: false, favorite_sort_order: 0 }] }))
|
||||
setForm(f => ({ ...f, preference_sets: [...f.preference_sets, { name: '', default_choice_index: -1, choices: [], shared_subset: null, is_favorite: false, favorite_sort_order: 0, allow_multi_select: false, allow_choice_quantity: false }] }))
|
||||
setActiveTab(form.preference_sets.length)
|
||||
}
|
||||
function removePrefSet(si) {
|
||||
@@ -306,7 +385,7 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
}
|
||||
function addChoice(si) {
|
||||
setForm(f => ({ ...f, preference_sets: f.preference_sets.map((ps, idx) =>
|
||||
idx === si ? { ...ps, choices: [...ps.choices, { name: '', extra_cost: 0, disables_subset: false, sub_choices: [] }] } : ps
|
||||
idx === si ? { ...ps, choices: [...ps.choices, { name: '', extra_cost: 0, disables_subset: false, is_compact: false, sub_choices: [] }] } : ps
|
||||
)}))
|
||||
}
|
||||
function removeChoice(si, ci) {
|
||||
@@ -341,7 +420,7 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
function addSubChoice(si, ci) {
|
||||
setForm(f => ({ ...f, preference_sets: f.preference_sets.map((ps, pidx) =>
|
||||
pidx !== si ? ps : { ...ps, choices: ps.choices.map((ch, cidx) =>
|
||||
cidx !== ci ? ch : { ...ch, sub_choices: [...(ch.sub_choices || []), { name: '', extra_cost: 0, is_default: false }] }
|
||||
cidx !== ci ? ch : { ...ch, sub_choices: [...(ch.sub_choices || []), { name: '', extra_cost: 0, is_default: false, is_compact: false }] }
|
||||
)}
|
||||
)}))
|
||||
}
|
||||
@@ -405,27 +484,60 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
)}))
|
||||
}
|
||||
|
||||
// Modifier groups
|
||||
const _nextTempId = useRef(-1)
|
||||
function addModifierGroup(modifier_type) {
|
||||
const _tempId = _nextTempId.current--
|
||||
setForm(f => ({ ...f, modifier_groups: [...f.modifier_groups, { _tempId, id: null, modifier_type, name: 'Νέα ομάδα', sort_order: f.modifier_groups.length }] }))
|
||||
}
|
||||
function renameModifierGroup(_tempId, name) {
|
||||
setForm(f => ({ ...f, modifier_groups: f.modifier_groups.map(g => g._tempId === _tempId ? { ...g, name } : g) }))
|
||||
}
|
||||
function deleteModifierGroup(_tempId) {
|
||||
setForm(f => {
|
||||
const next = { ...f, modifier_groups: f.modifier_groups.filter(g => g._tempId !== _tempId) }
|
||||
// Un-assign all items that belonged to this group
|
||||
next.options = f.options.map(o => o.group_id === _tempId ? { ...o, group_id: null } : o)
|
||||
next.ingredients = f.ingredients.map(i => i.group_id === _tempId ? { ...i, group_id: null } : i)
|
||||
next.preference_sets = f.preference_sets.map(ps => ps.group_id === _tempId ? { ...ps, group_id: null } : ps)
|
||||
return next
|
||||
})
|
||||
}
|
||||
function setItemGroup(listKey, idx, _tempId) {
|
||||
setForm(f => ({ ...f, [listKey]: f[listKey].map((item, i) => i === idx ? { ...item, group_id: _tempId } : item) }))
|
||||
}
|
||||
const [collapsedGroups, setCollapsedGroups] = useState({})
|
||||
function toggleGroupCollapsed(_tempId) {
|
||||
setCollapsedGroups(s => ({ ...s, [_tempId]: !s[_tempId] }))
|
||||
}
|
||||
|
||||
function buildBody() {
|
||||
return {
|
||||
name: form.name,
|
||||
description: form.description || null,
|
||||
category_id: form.category_id ? Number(form.category_id) : null,
|
||||
base_price: parseFloat(form.base_price),
|
||||
base_price: form.base_price !== '' && form.base_price !== null && form.base_price !== undefined ? parseFloat(form.base_price) : 0,
|
||||
unit_type: form.unit_type || 'piece',
|
||||
is_available: form.is_available,
|
||||
lifecycle_status: form.lifecycle_status,
|
||||
printer_zone_id: form.printer_zone_id ? Number(form.printer_zone_id) : null,
|
||||
prep_zone_ids: form.prep_zone_ids,
|
||||
quick_options: form.quick_options.map((q, i) => ({
|
||||
name: q.name, price: parseFloat(q.price) || 0, allow_multiple: q.allow_multiple ?? false,
|
||||
sort_order: i, is_favorite: q.is_favorite ?? false, favorite_sort_order: q.favorite_sort_order ?? 0, is_compact: q.is_compact ?? false,
|
||||
})),
|
||||
modifier_groups: form.modifier_groups.map((g, gi) => ({ modifier_type: g.modifier_type, name: g.name, sort_order: gi })),
|
||||
options: form.options.map(o => ({
|
||||
name: o.name, extra_cost: parseFloat(o.extra_cost) || 0, allow_multiple: o.allow_multiple ?? false,
|
||||
sub_choices: (o.sub_choices || []).map(s => ({ name: s.name, extra_cost: parseFloat(s.extra_cost) || 0, is_default: s.is_default ?? false })),
|
||||
multi_select: o.multi_select ?? false, is_compact: o.is_compact ?? false,
|
||||
sub_choices: (o.sub_choices || []).map(s => ({ name: s.name, extra_cost: parseFloat(s.extra_cost) || 0, is_default: s.is_default ?? false, allow_multiple: s.allow_multiple ?? false, is_compact: s.is_compact ?? false })),
|
||||
is_favorite: o.is_favorite ?? false, favorite_sort_order: o.favorite_sort_order ?? 0,
|
||||
group_id: o.group_id != null ? form.modifier_groups.findIndex(g => g._tempId === o.group_id) : null,
|
||||
})),
|
||||
ingredients: form.ingredients.map(i => ({
|
||||
name: i.name, extra_cost: parseFloat(i.extra_cost) || 0,
|
||||
is_favorite: i.is_favorite ?? false, favorite_sort_order: i.favorite_sort_order ?? 0,
|
||||
is_compact: i.is_compact ?? false,
|
||||
group_id: i.group_id != null ? form.modifier_groups.findIndex(g => g._tempId === i.group_id) : null,
|
||||
})),
|
||||
preference_sets: form.preference_sets.map(ps => ({
|
||||
name: ps.name,
|
||||
@@ -436,9 +548,13 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
} : null,
|
||||
choices: ps.choices.map(c => ({
|
||||
name: c.name, extra_cost: parseFloat(c.extra_cost) || 0, disables_subset: c.disables_subset ?? false,
|
||||
sub_choices: (c.sub_choices || []).map(s => ({ name: s.name, extra_cost: parseFloat(s.extra_cost) || 0, is_default: s.is_default ?? false })),
|
||||
is_compact: c.is_compact ?? false,
|
||||
sub_choices: (c.sub_choices || []).map(s => ({ name: s.name, extra_cost: parseFloat(s.extra_cost) || 0, is_default: s.is_default ?? false, is_compact: s.is_compact ?? false })),
|
||||
})),
|
||||
is_favorite: ps.is_favorite ?? false, favorite_sort_order: ps.favorite_sort_order ?? 0,
|
||||
group_id: ps.group_id != null ? form.modifier_groups.findIndex(g => g._tempId === ps.group_id) : null,
|
||||
allow_multi_select: ps.allow_multi_select ?? false,
|
||||
allow_choice_quantity: ps.allow_choice_quantity ?? false,
|
||||
})),
|
||||
digital_visible: form.digital_visible,
|
||||
digital_available: form.digital_available,
|
||||
@@ -452,6 +568,15 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
cost_breakdown: form.cost_mode === 'detailed' && form.cost_breakdown.length > 0
|
||||
? form.cost_breakdown.map(e => ({ label: e.label, amount: parseFloat(e.amount) || 0 }))
|
||||
: null,
|
||||
// Quick Add
|
||||
quick_add_enabled: form.quick_add_enabled,
|
||||
// Tags
|
||||
tags: form.tags || [],
|
||||
// Service items
|
||||
is_service_item: form.is_service_item ?? false,
|
||||
// Fiscal printer (ΦΗΜ)
|
||||
fiscal_name: form.fiscal_name?.trim() || null,
|
||||
fiscal_vat_group_id: form.fiscal_vat_group_id ? parseInt(form.fiscal_vat_group_id, 10) : null,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,8 +606,9 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
}
|
||||
|
||||
const isNew = !product.id
|
||||
const canSave = form.name.trim() && form.base_price
|
||||
const canSave = form.name.trim() && (form.is_service_item || (form.base_price !== '' && form.base_price !== null && form.base_price !== undefined))
|
||||
const favCount = buildFavoritesList(form).length
|
||||
const prefGroups = form.modifier_groups.filter(g => g.modifier_type === 'preference')
|
||||
const tabs = [
|
||||
{ key: 'favorites', label: 'Αγαπημένα', count: favCount, isFavTab: true },
|
||||
{ key: 'quick', label: 'Γρήγορες', count: form.quick_options.length },
|
||||
@@ -490,6 +616,7 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
{ key: 'options', label: 'Έξτρα', count: form.options.length },
|
||||
...form.preference_sets.map((ps, i) => ({ key: i, label: ps.name || `Προτ. ${i + 1}`, count: ps.choices.length })),
|
||||
{ key: '__add_pref__', label: '+ Προτίμηση', isAdd: true },
|
||||
{ key: '__add_pref_group__', label: '+ Ομάδα', isAddGroup: true },
|
||||
]
|
||||
const favList = buildFavoritesList(form)
|
||||
|
||||
@@ -508,14 +635,17 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
{/* Body */}
|
||||
<div className="flex-1 flex overflow-hidden">
|
||||
|
||||
{/* LEFT: tabbed product info — 30% width */}
|
||||
<div className="shrink-0 border-r border-gray-100 bg-gray-50/50 flex flex-col overflow-hidden" style={{ width: '25%' }}>
|
||||
{/* LEFT: tabbed product info — 25% normally, 100% for service items */}
|
||||
<div className="shrink-0 border-r border-gray-100 bg-gray-50/50 flex flex-col overflow-hidden" style={{ width: form.is_service_item ? '100%' : '25%' }}>
|
||||
{/* Left tab bar */}
|
||||
<div className="flex border-b border-gray-200 shrink-0 bg-white">
|
||||
{[
|
||||
{ key: 'info', label: 'Πληροφορίες' },
|
||||
{ key: 'digital', label: 'Digital Menu' },
|
||||
{ key: 'cost', label: 'Κόστος' },
|
||||
...(!form.is_service_item ? [
|
||||
{ key: 'digital', label: 'Digital Menu' },
|
||||
{ key: 'cost', label: 'Κόστος' },
|
||||
...(fiscalEnabled ? [{ key: 'fiscal', label: 'Ταμειακή' }] : []),
|
||||
] : []),
|
||||
].map(t => (
|
||||
<button key={t.key} onClick={() => setLeftTab(t.key)}
|
||||
className={`flex-1 px-4 py-3 text-sm font-medium whitespace-nowrap border-b-2 transition-colors ${
|
||||
@@ -533,12 +663,36 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
|
||||
{/* Tab 1: Main Info */}
|
||||
{leftTab === 'info' && (<>
|
||||
<div>
|
||||
<label className="label">Όνομα *</label>
|
||||
<input className="input" value={form.name} onChange={e => setField('name', e.target.value)} autoFocus placeholder="π.χ. Espresso" />
|
||||
</div>
|
||||
{/* Service Item toggle */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setField('is_service_item', !form.is_service_item)}
|
||||
className={`flex items-center gap-2 px-3 py-2 rounded-lg border text-sm font-medium transition-colors w-full ${
|
||||
form.is_service_item
|
||||
? 'bg-amber-50 border-amber-400 text-amber-800'
|
||||
: 'bg-gray-100 border-gray-300 text-gray-500 hover:bg-gray-200'
|
||||
}`}
|
||||
>
|
||||
<svg width="15" height="15" 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>
|
||||
{form.is_service_item ? 'Service Item' : 'Κανονικό προϊόν'}
|
||||
</button>
|
||||
|
||||
{form.is_service_item && (
|
||||
<p className="text-xs text-amber-700 -mt-1 px-1">
|
||||
{form.base_price && parseFloat(form.base_price) > 0
|
||||
? 'Τυπώνεται σε ξεχωριστή ενότητα SERVICE. Καταγράφεται στα έσοδα.'
|
||||
: 'Τυπώνεται μία φορά — δεν αποθηκεύεται στην παραγγελία, δεν καταγράφεται στα έσοδα.'}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="label">Όνομα *</label>
|
||||
<input className="input" value={form.name} onChange={e => setField('name', e.target.value)} autoFocus placeholder={form.is_service_item ? 'π.χ. Σερβίτσιο' : 'π.χ. Espresso'} />
|
||||
</div>
|
||||
|
||||
{!form.is_service_item && <div>
|
||||
<label className="label">Περιγραφή <span className="text-gray-400 font-normal normal-case">(προαιρετική)</span></label>
|
||||
<textarea
|
||||
className="input resize-none"
|
||||
@@ -549,15 +703,68 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
style={{ lineHeight: 1.5, fontSize: 13 }}
|
||||
/>
|
||||
<p className="text-xs text-gray-400 mt-1">Χρήσιμο για ψηφιακό μενού ή ενημέρωση σερβιτόρων.</p>
|
||||
</div>
|
||||
</div>}
|
||||
|
||||
{!form.is_service_item && <div>
|
||||
<label className="label">Tags <span className="text-gray-400 font-normal normal-case">(προαιρετικά)</span></label>
|
||||
<div className="flex flex-wrap gap-1.5 mb-1.5">
|
||||
{(form.tags || []).map((tag, ti) => (
|
||||
<span key={ti} className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-indigo-50 border border-indigo-200 text-xs font-medium text-indigo-700">
|
||||
{tag}
|
||||
<button type="button" onClick={() => setField('tags', form.tags.filter((_, i) => i !== ti))}
|
||||
className="hover:text-indigo-900 leading-none">×</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<input
|
||||
className="input text-sm"
|
||||
value={form.tagsInput || ''}
|
||||
onChange={e => setField('tagsInput', e.target.value)}
|
||||
onKeyDown={e => {
|
||||
if ((e.key === 'Enter' || e.key === ',') && form.tagsInput?.trim()) {
|
||||
e.preventDefault()
|
||||
const tag = form.tagsInput.trim().toLowerCase().replace(/,/g, '')
|
||||
if (tag && !(form.tags || []).includes(tag)) setField('tags', [...(form.tags || []), tag])
|
||||
setField('tagsInput', '')
|
||||
}
|
||||
}}
|
||||
onBlur={() => {
|
||||
if (form.tagsInput?.trim()) {
|
||||
const tag = form.tagsInput.trim().toLowerCase()
|
||||
if (!(form.tags || []).includes(tag)) setField('tags', [...(form.tags || []), tag])
|
||||
setField('tagsInput', '')
|
||||
}
|
||||
}}
|
||||
placeholder="π.χ. vegan, gluten-free — Enter ή κόμμα"
|
||||
/>
|
||||
<p className="text-xs text-gray-400 mt-1">Πάτα Enter ή κόμμα για να προσθέσεις tag.</p>
|
||||
</div>}
|
||||
|
||||
{!form.is_service_item && <div>
|
||||
<label className="label">Μονάδα μέτρησης</label>
|
||||
<select className="input" value={form.unit_type} onChange={e => setField('unit_type', e.target.value)}>
|
||||
<option value="piece">Τεμάχιο (pc)</option>
|
||||
<option value="portion">Μερίδα (portion)</option>
|
||||
<option value="kg">Κιλό (kg)</option>
|
||||
<option value="liter">Λίτρο (L)</option>
|
||||
<option value="gram">Γραμμάριο (g)</option>
|
||||
<option value="ml">Χιλιοστόλιτρο (mL)</option>
|
||||
</select>
|
||||
{(form.unit_type === 'kg' || form.unit_type === 'liter' || form.unit_type === 'gram' || form.unit_type === 'ml') && (
|
||||
<p className="text-xs text-indigo-600 mt-1">Η ποσότητα θα εισάγεται ως δεκαδικός αριθμός στην εφαρμογή σερβιτόρων.</p>
|
||||
)}
|
||||
</div>}
|
||||
|
||||
<div>
|
||||
<label className="label">Βασική Τιμή (€) *</label>
|
||||
<label className="label">{form.is_service_item ? 'Τιμή (€) — προαιρετική' : 'Βασική Τιμή (€) *'}</label>
|
||||
<PriceInput value={form.base_price} onChange={v => setField('base_price', v)} className="w-full" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="label">Κατηγορία</label>
|
||||
<label className="label">
|
||||
Κατηγορία
|
||||
{form.is_service_item && <span className="text-gray-400 font-normal normal-case ml-1">(προαιρετική — εμφανίζεται και εκεί)</span>}
|
||||
</label>
|
||||
<select className="input" value={form.category_id} onChange={e => setField('category_id', e.target.value)}>
|
||||
<option value="">— Χωρίς κατηγορία —</option>
|
||||
{categories.filter(c => !c.parent_id).sort((a, b) => a.sort_order - b.sort_order).flatMap(parent => {
|
||||
@@ -571,23 +778,56 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="label">Ζώνη εκτυπωτή</label>
|
||||
<select className="input" value={form.printer_zone_id} onChange={e => setField('printer_zone_id', e.target.value)}>
|
||||
<option value="">— Χωρίς εκτυπωτή —</option>
|
||||
{printers.map(p => <option key={p.id} value={p.id}>{p.name}</option>)}
|
||||
</select>
|
||||
<label className="label">Ζώνη Προετοιμασίας</label>
|
||||
<div className="flex flex-col gap-1.5 mt-1">
|
||||
{prepZones.length === 0 ? (
|
||||
<p className="text-xs text-gray-400 italic">Δεν υπάρχουν ζώνες. <a href="/management/prep-zones" className="underline text-primary-600">Δημιουργήστε μια ζώνη</a>.</p>
|
||||
) : (
|
||||
prepZones.map(z => {
|
||||
const selected = form.prep_zone_ids.includes(z.id)
|
||||
return (
|
||||
<label key={z.id} className={`flex items-center gap-2.5 px-3 py-2 rounded-lg border cursor-pointer transition-colors select-none text-sm ${selected ? 'border-primary-300 bg-primary-50 text-primary-700' : 'border-gray-200 bg-white text-gray-700 hover:border-gray-300'}`}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selected}
|
||||
onChange={() => {
|
||||
const ids = form.prep_zone_ids.includes(z.id)
|
||||
? form.prep_zone_ids.filter(id => id !== z.id)
|
||||
: [...form.prep_zone_ids, z.id]
|
||||
setField('prep_zone_ids', ids)
|
||||
}}
|
||||
className="w-3.5 h-3.5 accent-primary-600 shrink-0"
|
||||
/>
|
||||
<span className="font-medium">{z.name}</span>
|
||||
{z.description && <span className="text-xs text-gray-400 ml-1">— {z.description}</span>}
|
||||
</label>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="button" onClick={() => setField('is_available', !form.is_available)}
|
||||
className={`flex items-center gap-2 px-3 py-2 rounded-lg border text-sm font-medium transition-colors ${
|
||||
form.is_available ? 'bg-green-50 border-green-300 text-green-700 hover:bg-green-100'
|
||||
: 'bg-gray-100 border-gray-300 text-gray-500 hover:bg-gray-200'
|
||||
}`}>
|
||||
<span className={`w-2.5 h-2.5 rounded-full ${form.is_available ? 'bg-green-500' : 'bg-gray-400'}`} />
|
||||
{form.is_available ? 'Διαθέσιμο' : 'Μη διαθέσιμο'}
|
||||
</button>
|
||||
{!form.is_service_item && <div className="flex items-center gap-3 flex-wrap">
|
||||
<button type="button" onClick={() => setField('is_available', !form.is_available)}
|
||||
className={`flex items-center gap-2 px-3 py-2 rounded-lg border text-sm font-medium transition-colors ${
|
||||
form.is_available ? 'bg-green-50 border-green-300 text-green-700 hover:bg-green-100'
|
||||
: 'bg-gray-100 border-gray-300 text-gray-500 hover:bg-gray-200'
|
||||
}`}>
|
||||
<span className={`w-2.5 h-2.5 rounded-full ${form.is_available ? 'bg-green-500' : 'bg-gray-400'}`} />
|
||||
{form.is_available ? 'Διαθέσιμο' : 'Μη διαθέσιμο'}
|
||||
</button>
|
||||
|
||||
<div>
|
||||
<button type="button" onClick={() => setField('quick_add_enabled', !form.quick_add_enabled)}
|
||||
className={`flex items-center gap-2 px-3 py-2 rounded-lg border text-sm font-medium transition-colors ${
|
||||
form.quick_add_enabled ? 'bg-blue-50 border-blue-300 text-blue-700 hover:bg-blue-100'
|
||||
: 'bg-gray-100 border-gray-300 text-gray-500 hover:bg-gray-200'
|
||||
}`}>
|
||||
<span className={`w-2.5 h-2.5 rounded-full ${form.quick_add_enabled ? 'bg-blue-500' : 'bg-gray-400'}`} />
|
||||
{form.quick_add_enabled ? 'Quick Add: Ενεργό' : 'Quick Add: Ανενεργό'}
|
||||
</button>
|
||||
</div>}
|
||||
|
||||
{!form.is_service_item && <div>
|
||||
<label className="label">Εικόνα προϊόντος</label>
|
||||
{product.image_url && (
|
||||
<img src={product.image_url}
|
||||
@@ -599,7 +839,7 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
{imageFile ? 'Αλλαγή εικόνας' : 'Επιλογή εικόνας'}
|
||||
<input type="file" accept="image/*" className="sr-only" onChange={e => setImageFile(e.target.files[0] ?? null)} />
|
||||
</label>
|
||||
</div>
|
||||
</div>}
|
||||
</>)}
|
||||
|
||||
{/* Tab 2: Digital Menu */}
|
||||
@@ -761,13 +1001,69 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Tab 4: Fiscal (ΦΗΜ) — only shown when fiscal.enabled = true */}
|
||||
{leftTab === 'fiscal' && (
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-lg bg-blue-50 border border-blue-200 px-3 py-2 text-xs text-blue-800">
|
||||
Τα πεδία αυτά χρησιμοποιούνται κατά την αυτόματη αποστολή αποδείξεων στη ΦΗΜ.
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="label">Όνομα ΦΗΜ <span className="text-gray-400 font-normal normal-case">(προαιρετικό)</span></label>
|
||||
<input
|
||||
className="input font-mono uppercase"
|
||||
placeholder={form.name?.toUpperCase() || 'ΧΡΗΣΙΜΟΠΟΙΕΊ ΤΟ ΚΑΝΟΝΙΚΟ ΟΝΟΜΑ'}
|
||||
value={form.fiscal_name}
|
||||
maxLength={30}
|
||||
onChange={e => setField('fiscal_name', e.target.value.toUpperCase())}
|
||||
/>
|
||||
<p className="text-xs text-gray-400 mt-1">
|
||||
Σύντομο όνομα για την απόδειξη. Αν αφεθεί κενό, χρησιμοποιείται το κανονικό όνομα.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="label">Ομάδα ΦΠΑ ΦΗΜ *</label>
|
||||
{vatGroups.length === 0 ? (
|
||||
<p className="text-xs text-amber-600 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2">
|
||||
Δεν έχουν οριστεί ομάδες ΦΠΑ. Πηγαίνετε στις <strong>Ρυθμίσεις → Ταμειακή</strong> για να τις ρυθμίσετε.
|
||||
</p>
|
||||
) : (
|
||||
<select
|
||||
className="input"
|
||||
value={form.fiscal_vat_group_id ?? ''}
|
||||
onChange={e => setField('fiscal_vat_group_id', e.target.value ? parseInt(e.target.value, 10) : null)}
|
||||
>
|
||||
<option value="">— Χωρίς ανάθεση —</option>
|
||||
{vatGroups.map(g => (
|
||||
<option key={g.machine_id} value={g.machine_id}>
|
||||
{g.machine_id} — {g.friendly_name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
{!form.fiscal_vat_group_id && (
|
||||
<p className="text-xs text-red-500 mt-1">
|
||||
Απαιτείται για πληρωμή με ΦΗΜ ενεργή.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* RIGHT: ingredient/option tabs — 70% */}
|
||||
<div className="flex flex-col overflow-hidden" style={{ width: '75%' }}>
|
||||
{/* RIGHT: ingredient/option tabs — 70% (hidden for service items) */}
|
||||
<div className="flex flex-col overflow-hidden" style={{ width: '75%', display: form.is_service_item ? 'none' : undefined }}>
|
||||
<div className="flex border-b border-gray-200 overflow-x-auto shrink-0 bg-white">
|
||||
{tabs.map(tab => {
|
||||
if (tab.isAddGroup) return (
|
||||
<button key="__add_pref_group__" onClick={() => addModifierGroup('preference')}
|
||||
className="px-4 py-3 text-sm font-medium text-indigo-600 hover:bg-indigo-50 whitespace-nowrap border-b-2 border-transparent transition-colors">
|
||||
{tab.label}
|
||||
</button>
|
||||
)
|
||||
if (tab.isAdd) return (
|
||||
<button key="__add_pref__" onClick={addPrefSet}
|
||||
className="px-4 py-3 text-sm font-medium text-primary-600 hover:bg-primary-50 whitespace-nowrap border-b-2 border-transparent transition-colors">
|
||||
@@ -849,63 +1145,142 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
)}
|
||||
|
||||
{/* Ingredients */}
|
||||
{activeTab === 'ingredients' && (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<p className="text-sm text-gray-500">Υλικά που ο πελάτης μπορεί να αφαιρέσει.</p>
|
||||
<button onClick={addIngredient} className="btn btn-secondary text-sm px-3 py-1.5 min-h-0 h-9">+ Υλικό</button>
|
||||
{activeTab === 'ingredients' && (() => {
|
||||
const ingGroups = form.modifier_groups.filter(g => g.modifier_type === 'ingredient')
|
||||
const ungrouped = form.ingredients.map((ing, i) => ({ ing, i })).filter(({ ing }) => ing.group_id == null)
|
||||
const renderIngRow = (ing, i) => (
|
||||
<div key={i} className={`flex gap-2 items-center border rounded-xl p-3 bg-white flex-wrap ${ing.is_favorite ? 'border-rose-200' : 'border-gray-200'}`}>
|
||||
<ReorderBtns onUp={() => moveIngredient(i, -1)} onDown={() => moveIngredient(i, 1)}
|
||||
disableUp={i === 0} disableDown={i === form.ingredients.length - 1} />
|
||||
<FavoriteBtn isFavorite={ing.is_favorite} onClick={() => toggleFavorite('ingredient', i)} />
|
||||
<input className="input flex-1 min-w-40" placeholder="Όνομα υλικού" value={ing.name} onChange={e => setIngredient(i, 'name', e.target.value)} />
|
||||
<PriceInput value={ing.extra_cost} onChange={v => setIngredient(i, 'extra_cost', v)} allowNegative className="w-32" />
|
||||
<label className="flex items-center gap-1.5 text-sm cursor-pointer shrink-0 select-none" style={{ color: ing.is_compact ? '#7c3aed' : '#6b7280' }}>
|
||||
<input type="checkbox" checked={ing.is_compact ?? false} onChange={e => setIngredient(i, 'is_compact', e.target.checked)} className="w-4 h-4" style={{ accentColor: '#7c3aed' }} />
|
||||
Compact
|
||||
</label>
|
||||
{ingGroups.length > 0 && (
|
||||
<select className="input text-xs px-2 h-9 shrink-0" style={{ width: 120 }}
|
||||
value={form.ingredients[i].group_id ?? ''}
|
||||
onChange={e => setItemGroup('ingredients', i, e.target.value === '' ? null : Number(e.target.value))}>
|
||||
<option value="">— χωρίς ομάδα —</option>
|
||||
{ingGroups.map(g => <option key={g._tempId} value={g._tempId}>{g.name}</option>)}
|
||||
</select>
|
||||
)}
|
||||
<button onClick={() => removeIngredient(i)} className="btn btn-danger px-3 min-h-0 h-10">✕</button>
|
||||
</div>
|
||||
{!form.ingredients.length && <p className="text-sm text-gray-400 text-center py-8">Δεν υπάρχουν υλικά.</p>}
|
||||
<div className="space-y-2">
|
||||
{form.ingredients.map((ing, i) => (
|
||||
<div key={i} className={`flex gap-2 items-center border rounded-xl p-3 bg-white ${ing.is_favorite ? 'border-rose-200' : 'border-gray-200'}`}>
|
||||
<ReorderBtns onUp={() => moveIngredient(i, -1)} onDown={() => moveIngredient(i, 1)}
|
||||
disableUp={i === 0} disableDown={i === form.ingredients.length - 1} />
|
||||
<FavoriteBtn isFavorite={ing.is_favorite} onClick={() => toggleFavorite('ingredient', i)} />
|
||||
<input className="input flex-1" placeholder="Όνομα υλικού" value={ing.name} onChange={e => setIngredient(i, 'name', e.target.value)} />
|
||||
<PriceInput value={ing.extra_cost} onChange={v => setIngredient(i, 'extra_cost', v)} allowNegative className="w-32" />
|
||||
<button onClick={() => removeIngredient(i)} className="btn btn-danger px-3 min-h-0 h-10">✕</button>
|
||||
)
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-3 gap-2 flex-wrap">
|
||||
<p className="text-sm text-gray-500">Υλικά που ο πελάτης μπορεί να αφαιρέσει.</p>
|
||||
<div className="flex gap-2">
|
||||
<button onClick={() => addModifierGroup('ingredient')} className="btn btn-secondary text-sm px-3 py-1.5 min-h-0 h-9">+ Ομάδα</button>
|
||||
<button onClick={addIngredient} className="btn btn-secondary text-sm px-3 py-1.5 min-h-0 h-9">+ Υλικό</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{!form.ingredients.length && <p className="text-sm text-gray-400 text-center py-8">Δεν υπάρχουν υλικά.</p>}
|
||||
<div className="space-y-2">
|
||||
{ungrouped.map(({ ing, i }) => renderIngRow(ing, i))}
|
||||
{ingGroups.map(g => {
|
||||
const members = form.ingredients.map((ing, i) => ({ ing, i })).filter(({ ing }) => ing.group_id === g._tempId)
|
||||
const collapsed = collapsedGroups[g._tempId]
|
||||
return (
|
||||
<div key={g._tempId}>
|
||||
<GroupHeader group={g} collapsed={collapsed} onToggle={() => toggleGroupCollapsed(g._tempId)}
|
||||
onRename={name => renameModifierGroup(g._tempId, name)}
|
||||
onDelete={() => deleteModifierGroup(g._tempId)} />
|
||||
{!collapsed && (
|
||||
<div className="ml-4 border-l-2 border-indigo-100 pl-3 mt-1 space-y-2">
|
||||
{members.length === 0 && <p className="text-xs text-gray-400 py-2">Χωρίς υλικά — αλλάξτε ομάδα από κάθε υλικό.</p>}
|
||||
{members.map(({ ing, i }) => renderIngRow(ing, i))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
)
|
||||
})()}
|
||||
|
||||
{/* Options/Extras */}
|
||||
{activeTab === 'options' && (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<p className="text-sm text-gray-500">Έξτρα (checkbox). Κάθε extra μπορεί να έχει υπο-επιλογές.</p>
|
||||
<button onClick={addOption} className="btn btn-secondary text-sm px-3 py-1.5 min-h-0 h-9">+ Έξτρα</button>
|
||||
{activeTab === 'options' && (() => {
|
||||
const optGroups = form.modifier_groups.filter(g => g.modifier_type === 'option')
|
||||
const ungrouped = form.options.map((opt, i) => ({ opt, i })).filter(({ opt }) => opt.group_id == null)
|
||||
const renderOptRow = (opt, i) => (
|
||||
<div key={i} className={`border rounded-xl overflow-hidden ${opt.is_favorite ? 'border-rose-200' : 'border-gray-200'}`}>
|
||||
<div className="flex gap-2 items-center p-3 bg-white flex-wrap">
|
||||
<ReorderBtns onUp={() => moveOption(i, -1)} onDown={() => moveOption(i, 1)}
|
||||
disableUp={i === 0} disableDown={i === form.options.length - 1} />
|
||||
<FavoriteBtn isFavorite={opt.is_favorite} onClick={() => toggleFavorite('option', i)} />
|
||||
<input className="input flex-1 min-w-40" placeholder="π.χ. Κανέλα" value={opt.name} onChange={e => setOption(i, 'name', e.target.value)} />
|
||||
<PriceInput value={opt.extra_cost} onChange={v => setOption(i, 'extra_cost', v)} allowNegative className="w-32" />
|
||||
<label className="flex items-center gap-1.5 text-sm text-gray-600 cursor-pointer shrink-0 select-none">
|
||||
<input type="checkbox" checked={opt.allow_multiple} onChange={e => setOption(i, 'allow_multiple', e.target.checked)} className="accent-primary-700 w-4 h-4" />
|
||||
Πολλαπλά
|
||||
</label>
|
||||
<label className="flex items-center gap-1.5 text-sm cursor-pointer shrink-0 select-none" style={{ color: opt.multi_select ? '#0891b2' : '#6b7280' }}>
|
||||
<input type="checkbox" checked={opt.multi_select ?? false} onChange={e => setOption(i, 'multi_select', e.target.checked)} className="w-4 h-4" style={{ accentColor: '#0891b2' }} />
|
||||
Multi-select
|
||||
</label>
|
||||
<label className="flex items-center gap-1.5 text-sm cursor-pointer shrink-0 select-none" style={{ color: opt.is_compact ? '#7c3aed' : '#6b7280' }}>
|
||||
<input type="checkbox" checked={opt.is_compact ?? false} onChange={e => setOption(i, 'is_compact', e.target.checked)} className="w-4 h-4" style={{ accentColor: '#7c3aed' }} />
|
||||
Compact
|
||||
</label>
|
||||
{optGroups.length > 0 && (
|
||||
<select className="input text-xs px-2 h-9 shrink-0" style={{ width: 120 }}
|
||||
value={form.options[i].group_id ?? ''}
|
||||
onChange={e => setItemGroup('options', i, e.target.value === '' ? null : Number(e.target.value))}>
|
||||
<option value="">— χωρίς ομάδα —</option>
|
||||
{optGroups.map(g => <option key={g._tempId} value={g._tempId}>{g.name}</option>)}
|
||||
</select>
|
||||
)}
|
||||
<button onClick={() => addOptionSubChoice(i)} className="btn btn-secondary text-xs px-2 min-h-0 h-9 shrink-0 whitespace-nowrap">+ Υπο-επιλογές</button>
|
||||
<button onClick={() => removeOption(i)} className="btn btn-danger px-3 min-h-0 h-10">✕</button>
|
||||
</div>
|
||||
<SubChoiceRows subChoices={opt.sub_choices} parentLabel={opt.name}
|
||||
showMultiple={opt.multi_select}
|
||||
onMove={(sci, dir) => moveOptionSubChoice(i, sci, dir)}
|
||||
onToggleDefault={sci => toggleOptionSubDefault(i, sci)}
|
||||
onChange={(sci, k, v) => setOptionSubChoice(i, sci, k, v)}
|
||||
onRemove={sci => removeOptionSubChoice(i, sci)}
|
||||
onAdd={() => addOptionSubChoice(i)} />
|
||||
</div>
|
||||
{!form.options.length && <p className="text-sm text-gray-400 text-center py-8">Δεν υπάρχουν extras.</p>}
|
||||
<div className="space-y-3">
|
||||
{form.options.map((opt, i) => (
|
||||
<div key={i} className={`border rounded-xl overflow-hidden ${opt.is_favorite ? 'border-rose-200' : 'border-gray-200'}`}>
|
||||
<div className="flex gap-2 items-center p-3 bg-white flex-wrap">
|
||||
<ReorderBtns onUp={() => moveOption(i, -1)} onDown={() => moveOption(i, 1)}
|
||||
disableUp={i === 0} disableDown={i === form.options.length - 1} />
|
||||
<FavoriteBtn isFavorite={opt.is_favorite} onClick={() => toggleFavorite('option', i)} />
|
||||
<input className="input flex-1 min-w-40" placeholder="π.χ. Κανέλα" value={opt.name} onChange={e => setOption(i, 'name', e.target.value)} />
|
||||
<PriceInput value={opt.extra_cost} onChange={v => setOption(i, 'extra_cost', v)} allowNegative className="w-32" />
|
||||
<label className="flex items-center gap-1.5 text-sm text-gray-600 cursor-pointer shrink-0 select-none">
|
||||
<input type="checkbox" checked={opt.allow_multiple} onChange={e => setOption(i, 'allow_multiple', e.target.checked)} className="accent-primary-700 w-4 h-4" />
|
||||
Πολλαπλά
|
||||
</label>
|
||||
<button onClick={() => addOptionSubChoice(i)} className="btn btn-secondary text-xs px-2 min-h-0 h-9 shrink-0 whitespace-nowrap">+ Υπο-επιλογές</button>
|
||||
<button onClick={() => removeOption(i)} className="btn btn-danger px-3 min-h-0 h-10">✕</button>
|
||||
</div>
|
||||
<SubChoiceRows subChoices={opt.sub_choices} parentLabel={opt.name}
|
||||
onMove={(sci, dir) => moveOptionSubChoice(i, sci, dir)}
|
||||
onToggleDefault={sci => toggleOptionSubDefault(i, sci)}
|
||||
onChange={(sci, k, v) => setOptionSubChoice(i, sci, k, v)}
|
||||
onRemove={sci => removeOptionSubChoice(i, sci)}
|
||||
onAdd={() => addOptionSubChoice(i)} />
|
||||
)
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-3 gap-2 flex-wrap">
|
||||
<p className="text-sm text-gray-500">Έξτρα (checkbox). Κάθε extra μπορεί να έχει υπο-επιλογές.</p>
|
||||
<div className="flex gap-2">
|
||||
<button onClick={() => addModifierGroup('option')} className="btn btn-secondary text-sm px-3 py-1.5 min-h-0 h-9">+ Ομάδα</button>
|
||||
<button onClick={addOption} className="btn btn-secondary text-sm px-3 py-1.5 min-h-0 h-9">+ Έξτρα</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{!form.options.length && <p className="text-sm text-gray-400 text-center py-8">Δεν υπάρχουν extras.</p>}
|
||||
<div className="space-y-3">
|
||||
{ungrouped.map(({ opt, i }) => renderOptRow(opt, i))}
|
||||
{optGroups.map(g => {
|
||||
const members = form.options.map((opt, i) => ({ opt, i })).filter(({ opt }) => opt.group_id === g._tempId)
|
||||
const collapsed = collapsedGroups[g._tempId]
|
||||
return (
|
||||
<div key={g._tempId}>
|
||||
<GroupHeader group={g} collapsed={collapsed} onToggle={() => toggleGroupCollapsed(g._tempId)}
|
||||
onRename={name => renameModifierGroup(g._tempId, name)}
|
||||
onDelete={() => deleteModifierGroup(g._tempId)} />
|
||||
{!collapsed && (
|
||||
<div className="ml-4 border-l-2 border-indigo-100 pl-3 mt-1 space-y-3">
|
||||
{members.length === 0 && <p className="text-xs text-gray-400 py-2">Χωρίς extras — αλλάξτε ομάδα από κάθε extra.</p>}
|
||||
{members.map(({ opt, i }) => renderOptRow(opt, i))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
)
|
||||
})()}
|
||||
|
||||
{/* Preference set tab */}
|
||||
{typeof activeTab === 'number' && form.preference_sets[activeTab] && (() => {
|
||||
@@ -914,22 +1289,65 @@ export default function ProductFormModal({ product, categories, printers, onSave
|
||||
const hasSharedSubset = !!ps.shared_subset
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<input className="input flex-1 font-semibold text-base" placeholder="π.χ. Ζάχαρη" value={ps.name}
|
||||
<div className="flex items-center gap-3 mb-4 flex-wrap">
|
||||
<input className="input flex-1 font-semibold text-base min-w-32" placeholder="π.χ. Ζάχαρη" value={ps.name}
|
||||
onChange={e => setPrefSetField(si, 'name', e.target.value)} autoFocus />
|
||||
{prefGroups.length > 0 && (
|
||||
<select className="input text-xs px-2 h-9 shrink-0" style={{ width: 140 }}
|
||||
value={ps.group_id ?? ''}
|
||||
onChange={e => setPrefSetField(si, 'group_id', e.target.value === '' ? null : Number(e.target.value))}>
|
||||
<option value="">— χωρίς ομάδα —</option>
|
||||
{prefGroups.map(g => <option key={g._tempId} value={g._tempId}>{g.name}</option>)}
|
||||
</select>
|
||||
)}
|
||||
<FavoriteBtn isFavorite={ps.is_favorite} onClick={() => toggleFavorite('pref', si)} />
|
||||
<button onClick={() => removePrefSet(si)} className="btn btn-danger px-3 min-h-0 h-10 shrink-0">Διαγραφή</button>
|
||||
</div>
|
||||
{/* Pref groups management (only show if any exist) */}
|
||||
{prefGroups.length > 0 && (
|
||||
<div className="mb-4 p-3 bg-indigo-50/50 border border-indigo-100 rounded-xl space-y-1">
|
||||
<p className="text-xs font-semibold text-indigo-600 mb-2">Ομάδες προτιμήσεων</p>
|
||||
{prefGroups.map(g => (
|
||||
<GroupHeader key={g._tempId} group={g}
|
||||
collapsed={collapsedGroups[g._tempId]}
|
||||
onToggle={() => toggleGroupCollapsed(g._tempId)}
|
||||
onRename={name => renameModifierGroup(g._tempId, name)}
|
||||
onDelete={() => deleteModifierGroup(g._tempId)} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-5 mb-3 flex-wrap">
|
||||
<label className="flex items-center gap-2 cursor-pointer select-none">
|
||||
<input type="checkbox" checked={ps.allow_multi_select ?? false}
|
||||
onChange={e => setPrefSetField(si, 'allow_multi_select', e.target.checked)}
|
||||
className="w-4 h-4" style={{ accentColor: '#6366f1' }} />
|
||||
<span className="text-sm font-medium" style={{ color: ps.allow_multi_select ? '#6366f1' : '#6b7280' }}>
|
||||
Πολλαπλή επιλογή
|
||||
</span>
|
||||
</label>
|
||||
<label className="flex items-center gap-2 cursor-pointer select-none">
|
||||
<input type="checkbox" checked={ps.allow_choice_quantity ?? false}
|
||||
onChange={e => setPrefSetField(si, 'allow_choice_quantity', e.target.checked)}
|
||||
className="w-4 h-4" style={{ accentColor: '#6366f1' }} />
|
||||
<span className="text-sm font-medium" style={{ color: ps.allow_choice_quantity ? '#6366f1' : '#6b7280' }}>
|
||||
Ποσότητα ανά επιλογή
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400 mb-3">● = προεπιλογή · ⊘ = απενεργοποιεί κοινό υπο-σύνολο</p>
|
||||
<div className="space-y-3 mb-5">
|
||||
{ps.choices.map((ch, ci) => (
|
||||
<div key={ci} className="border border-gray-200 rounded-xl overflow-hidden">
|
||||
<div className="flex items-center gap-2 p-3 bg-white">
|
||||
<div className="flex items-center gap-2 p-3 bg-white flex-wrap">
|
||||
<ReorderBtns onUp={() => moveChoice(si, ci, -1)} onDown={() => moveChoice(si, ci, 1)}
|
||||
disableUp={ci === 0} disableDown={ci === ps.choices.length - 1} />
|
||||
<DefaultBtn isDefault={ps.default_choice_index === ci} onClick={() => toggleDefaultChoice(si, ci)} />
|
||||
<input className="input flex-1" placeholder="π.χ. Σκέτος" value={ch.name} onChange={e => setChoice(si, ci, 'name', e.target.value)} />
|
||||
<input className="input flex-1 min-w-32" placeholder="π.χ. Σκέτος" value={ch.name} onChange={e => setChoice(si, ci, 'name', e.target.value)} />
|
||||
<PriceInput value={ch.extra_cost} onChange={v => setChoice(si, ci, 'extra_cost', v)} allowNegative className="w-32" />
|
||||
<label className="flex items-center gap-1 text-xs cursor-pointer shrink-0 select-none" style={{ color: ch.is_compact ? '#7c3aed' : '#6b7280' }}>
|
||||
<input type="checkbox" checked={ch.is_compact ?? false} onChange={e => setChoice(si, ci, 'is_compact', e.target.checked)} className="w-3.5 h-3.5" style={{ accentColor: '#7c3aed' }} />
|
||||
Compact
|
||||
</label>
|
||||
{hasSharedSubset && (
|
||||
<button type="button" onClick={() => setChoice(si, ci, 'disables_subset', !ch.disables_subset)}
|
||||
className={`w-7 h-7 rounded-full flex items-center justify-center shrink-0 text-sm ${ch.disables_subset ? 'bg-red-100 text-red-500' : 'text-gray-300 hover:text-red-400'}`}>⊘</button>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import ProductsTab from '../Management/ProductsTab'
|
||||
|
||||
export default function ProductsPage() {
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<ProductsTab />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -40,7 +40,8 @@ function Icon({ name, size = 14, className = '' }) {
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
const EMPTY_PRODUCT = {
|
||||
name: '', category_id: '', base_price: '', is_available: true, lifecycle_status: 'active',
|
||||
printer_zone_id: '', description: '', quick_options: [], options: [], ingredients: [], preference_sets: [],
|
||||
description: '', quick_options: [], options: [], ingredients: [], preference_sets: [],
|
||||
is_service_item: false,
|
||||
}
|
||||
|
||||
function catColor(cat) { return cat?.color || '#94a3b8' }
|
||||
@@ -175,6 +176,15 @@ function CategoryPanel({ categories, products, selectedCat, onSelect, onEdit, on
|
||||
|
||||
{/* Tree */}
|
||||
<div style={{ flex: 1, overflowY: 'auto', padding: '4px 24px' }}>
|
||||
{/* Service items — permanent, always first */}
|
||||
<CatRow
|
||||
label="Service"
|
||||
count={products.filter(p => p.is_service_item && p.lifecycle_status !== 'archived').length}
|
||||
isSelected={selectedCat === '__service__'}
|
||||
onClick={() => onSelect('__service__')}
|
||||
dotColor="#f59e0b"
|
||||
isService
|
||||
/>
|
||||
{/* All */}
|
||||
<CatRow
|
||||
label="Όλα τα προϊόντα" count={totalActive}
|
||||
@@ -277,7 +287,7 @@ function CategoryPanel({ categories, products, selectedCat, onSelect, onEdit, on
|
||||
)
|
||||
}
|
||||
|
||||
function CatRow({ label, count, isSelected, onClick, dotColor, dotIsGradient, isParent, isOpen, onToggle, onEdit, onDelete, onAddChild, onReparent, depth = 0, showDrag }) {
|
||||
function CatRow({ label, count, isSelected, onClick, dotColor, dotIsGradient, isParent, isOpen, onToggle, onEdit, onDelete, onAddChild, onReparent, depth = 0, showDrag, isService }) {
|
||||
const bg = isSelected ? '#eff6ff' : 'transparent'
|
||||
const accent = isSelected ? '#3b82f6' : 'transparent'
|
||||
return (
|
||||
@@ -313,14 +323,20 @@ function CatRow({ label, count, isSelected, onClick, dotColor, dotIsGradient, is
|
||||
<span style={{ width: 15, flexShrink: 0 }} />
|
||||
)}
|
||||
|
||||
{/* Color dot */}
|
||||
<span style={{
|
||||
width: 8, height: 8, borderRadius: '50%', flexShrink: 0,
|
||||
...(dotIsGradient ? { background: dotColor } : { backgroundColor: dotColor }),
|
||||
}} />
|
||||
{/* Color dot or service icon */}
|
||||
{isService ? (
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#f59e0b" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" style={{ flexShrink: 0 }}>
|
||||
<path d="M3 11l19-9-9 19-2-8-8-2z"/>
|
||||
</svg>
|
||||
) : (
|
||||
<span style={{
|
||||
width: 8, height: 8, borderRadius: '50%', flexShrink: 0,
|
||||
...(dotIsGradient ? { background: dotColor } : { backgroundColor: dotColor }),
|
||||
}} />
|
||||
)}
|
||||
|
||||
{/* Name */}
|
||||
<span style={{ flex: 1, fontSize: 13.5, fontWeight: isSelected ? 600 : 500, color: '#111827', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 }}>
|
||||
<span style={{ flex: 1, fontSize: 13.5, fontWeight: isSelected ? 600 : 500, color: isService ? '#b45309' : '#111827', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 }}>
|
||||
{label}
|
||||
</span>
|
||||
|
||||
@@ -439,9 +455,9 @@ function CatFooterRow({ icon, label, count, isSelected, onClick }) {
|
||||
}
|
||||
|
||||
// ── Products Panel Header ─────────────────────────────────────────────────────
|
||||
function ProductsHeader({ title, visibleCount, totalCount, search, setSearch, view, setView, zoneFilter, setZoneFilter, priceMin, setPriceMin, priceMax, setPriceMax, dataQualityFilter, setDataQualityFilter, showUnavailable, setShowUnavailable, showArchived, setShowArchived, zones, onNew }) {
|
||||
function ProductsHeader({ title, visibleCount, totalCount, search, setSearch, view, setView, priceMin, setPriceMin, priceMax, setPriceMax, dataQualityFilter, setDataQualityFilter, showUnavailable, setShowUnavailable, showArchived, setShowArchived, onNew }) {
|
||||
const [filtersOpen, setFiltersOpen] = useState(false)
|
||||
const hasFilter = zoneFilter !== 'all' || priceMin !== '' || priceMax !== '' || dataQualityFilter !== 'all' || showUnavailable || showArchived
|
||||
const hasFilter = priceMin !== '' || priceMax !== '' || dataQualityFilter !== 'all' || showUnavailable || showArchived
|
||||
|
||||
function clearFilters() {
|
||||
setZoneFilter('all')
|
||||
@@ -526,10 +542,6 @@ function ProductsHeader({ title, visibleCount, totalCount, search, setSearch, vi
|
||||
borderRadius: 10, boxShadow: '0 4px 12px rgba(0,0,0,0.08)',
|
||||
display: 'flex', flexWrap: 'wrap', gap: 20, alignItems: 'flex-end',
|
||||
}}>
|
||||
<FilterGroup label="Ζώνη εκτύπωσης">
|
||||
<SegControl value={zoneFilter} onChange={setZoneFilter}
|
||||
options={[{ v: 'all', l: 'Όλες' }, ...zones.map(z => ({ v: z, l: z }))]} />
|
||||
</FilterGroup>
|
||||
<FilterGroup label="Τιμή €">
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<input type="number" placeholder="από" value={priceMin} onChange={e => setPriceMin(e.target.value)}
|
||||
@@ -636,7 +648,7 @@ function SubCatBar({ parentCat, subCats, products, subCatFilter, setSubCatFilter
|
||||
}
|
||||
|
||||
// ── Bulk bar ──────────────────────────────────────────────────────────────────
|
||||
function BulkBar({ count, onClear, onAvail, onUnavail, onArchive, onSetPrinterZone, onMoveToCategory }) {
|
||||
function BulkBar({ count, onClear, onAvail, onUnavail, onArchive, onSetPrepZone, onMoveToCategory }) {
|
||||
return (
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', margin: '12px 24px 0', padding: '10px 14px', background: '#111827', color: '#fff', borderRadius: 10, flexShrink: 0 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||
@@ -660,12 +672,12 @@ function BulkBar({ count, onClear, onAvail, onUnavail, onArchive, onSetPrinterZo
|
||||
</button>
|
||||
))}
|
||||
<div style={{ width: 1, background: 'rgba(255,255,255,0.15)', margin: '4px 2px' }} />
|
||||
<button onClick={onSetPrinterZone}
|
||||
<button onClick={onSetPrepZone}
|
||||
style={{ border: '1px solid rgba(255,255,255,0.2)', background: 'transparent', color: 'rgba(255,255,255,0.85)', padding: '6px 10px', borderRadius: 6, fontSize: 13, fontWeight: 500, cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 6 }}
|
||||
className="hover:bg-white/10"
|
||||
>
|
||||
<Icon name="folder" size={13} />
|
||||
Ζώνη εκτύπωσης
|
||||
Ζώνη Προετοιμασίας
|
||||
</button>
|
||||
<button onClick={onMoveToCategory}
|
||||
style={{ border: '1px solid rgba(255,255,255,0.2)', background: 'transparent', color: 'rgba(255,255,255,0.85)', padding: '6px 10px', borderRadius: 6, fontSize: 13, fontWeight: 500, cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 6 }}
|
||||
@@ -679,38 +691,43 @@ function BulkBar({ count, onClear, onAvail, onUnavail, onArchive, onSetPrinterZo
|
||||
)
|
||||
}
|
||||
|
||||
// ── Bulk: Set Printer Zone modal ───────────────────────────────────────────────
|
||||
function BulkSetPrinterZoneModal({ count, printers, onClose, onConfirm }) {
|
||||
const zones = [...new Map(printers.map(p => [p.id, p])).values()]
|
||||
const [selectedId, setSelectedId] = useState(zones[0]?.id ?? '')
|
||||
// ── Bulk: Set Prep Zone modal ───────────────────────────────────────────────
|
||||
function BulkSetPrepZoneModal({ count, prepZones, onClose, onConfirm }) {
|
||||
const [selectedIds, setSelectedIds] = useState([])
|
||||
const toggle = (id) => setSelectedIds(prev => prev.includes(id) ? prev.filter(x => x !== id) : [...prev, id])
|
||||
return (
|
||||
<div style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.45)', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 60, padding: 16 }}>
|
||||
<div style={{ background: '#fff', borderRadius: 16, boxShadow: '0 20px 60px rgba(0,0,0,0.18)', width: '100%', maxWidth: 380, padding: 24 }}>
|
||||
<h2 style={{ margin: '0 0 4px', fontWeight: 700, fontSize: 16, color: '#111827' }}>Ζώνη εκτύπωσης</h2>
|
||||
<div style={{ background: '#fff', borderRadius: 16, boxShadow: '0 20px 60px rgba(0,0,0,0.18)', width: '100%', maxWidth: 420, padding: 24 }}>
|
||||
<h2 style={{ margin: '0 0 4px', fontWeight: 700, fontSize: 16, color: '#111827' }}>Ζώνες Προετοιμασίας</h2>
|
||||
<p style={{ margin: '0 0 18px', fontSize: 13, color: '#6b7280' }}>
|
||||
Θα οριστεί σε <strong style={{ color: '#111827' }}>{count}</strong> προϊόντα.
|
||||
</p>
|
||||
{zones.length === 0 ? (
|
||||
<p style={{ fontSize: 13, color: '#ef4444', marginBottom: 18 }}>Δεν βρέθηκαν εκτυπωτές.</p>
|
||||
{prepZones.length === 0 ? (
|
||||
<p style={{ fontSize: 13, color: '#ef4444', marginBottom: 18 }}>Δεν βρέθηκαν ζώνες προετοιμασίας.</p>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, marginBottom: 20 }}>
|
||||
{zones.map(z => (
|
||||
<label key={z.id} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '10px 12px', border: `1.5px solid ${selectedId === z.id ? '#3b82f6' : '#e5e7eb'}`, borderRadius: 10, cursor: 'pointer', background: selectedId === z.id ? '#eff6ff' : '#fff' }}>
|
||||
<input type="radio" name="zone" value={z.id} checked={selectedId === z.id} onChange={() => setSelectedId(z.id)} style={{ display: 'none' }} />
|
||||
<span style={{ width: 16, height: 16, borderRadius: '50%', border: `2px solid ${selectedId === z.id ? '#3b82f6' : '#d1d5db'}`, background: selectedId === z.id ? '#3b82f6' : '#fff', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
|
||||
{selectedId === z.id && <span style={{ width: 6, height: 6, borderRadius: '50%', background: '#fff' }} />}
|
||||
</span>
|
||||
<span style={{ fontSize: 14, fontWeight: 500, color: '#111827' }}>{z.name}</span>
|
||||
</label>
|
||||
))}
|
||||
{prepZones.map(z => {
|
||||
const on = selectedIds.includes(z.id)
|
||||
return (
|
||||
<label key={z.id} onClick={() => toggle(z.id)} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '10px 12px', border: `1.5px solid ${on ? '#3b82f6' : '#e5e7eb'}`, borderRadius: 10, cursor: 'pointer', background: on ? '#eff6ff' : '#fff' }}>
|
||||
<span style={{ width: 16, height: 16, borderRadius: 4, border: `2px solid ${on ? '#3b82f6' : '#d1d5db'}`, background: on ? '#3b82f6' : '#fff', display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
|
||||
{on && <span style={{ width: 8, height: 8, background: '#fff', borderRadius: 2, display: 'block' }} />}
|
||||
</span>
|
||||
<div>
|
||||
<span style={{ fontSize: 14, fontWeight: 500, color: '#111827' }}>{z.name}</span>
|
||||
{z.description && <span style={{ fontSize: 12, color: '#6b7280', marginLeft: 8 }}>{z.description}</span>}
|
||||
</div>
|
||||
</label>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
<div style={{ display: 'flex', gap: 10 }}>
|
||||
<button onClick={onClose} style={{ flex: 1, padding: '9px 0', border: '1px solid #e5e7eb', background: '#fff', borderRadius: 8, fontSize: 14, cursor: 'pointer', color: '#374151' }}>Άκυρο</button>
|
||||
<button
|
||||
onClick={() => onConfirm(selectedId)}
|
||||
disabled={!selectedId}
|
||||
style={{ flex: 1, padding: '9px 0', border: 'none', background: selectedId ? '#111827' : '#d1d5db', color: '#fff', borderRadius: 8, fontSize: 14, fontWeight: 600, cursor: selectedId ? 'pointer' : 'not-allowed' }}
|
||||
onClick={() => onConfirm(selectedIds)}
|
||||
disabled={!selectedIds.length}
|
||||
style={{ flex: 1, padding: '9px 0', border: 'none', background: selectedIds.length ? '#111827' : '#d1d5db', color: '#fff', borderRadius: 8, fontSize: 14, fontWeight: 600, cursor: selectedIds.length ? 'pointer' : 'not-allowed' }}
|
||||
>
|
||||
Εφαρμογή
|
||||
</button>
|
||||
@@ -829,6 +846,11 @@ function ProductRow({ p, cat, parentCat, selected, onToggleSelect, onEdit, onArc
|
||||
Αρχείο
|
||||
</span>
|
||||
)}
|
||||
{p.is_service_item && !isArchived && (
|
||||
<span style={{ fontSize: 10.5, fontWeight: 600, textTransform: 'uppercase', background: '#fef3c7', color: '#b45309', padding: '1px 6px', borderRadius: 4, flexShrink: 0 }}>
|
||||
Service
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 12, color: '#6b7280' }}>
|
||||
{displayCat && (
|
||||
@@ -837,11 +859,11 @@ function ProductRow({ p, cat, parentCat, selected, onToggleSelect, onEdit, onArc
|
||||
{displayCat.name}
|
||||
</span>
|
||||
)}
|
||||
{p.printer_zone_name && (
|
||||
<span style={{ background: '#eff6ff', color: '#1d4ed8', padding: '1px 6px', borderRadius: 4, fontSize: 11 }}>
|
||||
{p.printer_zone_name}
|
||||
{p.prep_zone_names?.map(name => (
|
||||
<span key={name} style={{ background: '#eff6ff', color: '#1d4ed8', padding: '1px 6px', borderRadius: 4, fontSize: 11 }}>
|
||||
{name}
|
||||
</span>
|
||||
)}
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -997,11 +1019,13 @@ function ProductCard({ p, cat, parentCat, selected, onToggleSelect, onEdit, onAr
|
||||
<span style={{ fontVariantNumeric: 'tabular-nums', fontWeight: 700, fontSize: 15, color: '#111827' }}>
|
||||
€{parseFloat(p.base_price).toFixed(2)}
|
||||
</span>
|
||||
{p.printer_zone_name && (
|
||||
<span style={{ background: '#eff6ff', color: '#1d4ed8', padding: '1px 6px', borderRadius: 4, fontSize: 11 }}>
|
||||
{p.printer_zone_name}
|
||||
</span>
|
||||
)}
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
|
||||
{p.prep_zone_names?.map(name => (
|
||||
<span key={name} style={{ background: '#eff6ff', color: '#1d4ed8', padding: '1px 6px', borderRadius: 4, fontSize: 11 }}>
|
||||
{name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1052,7 +1076,6 @@ export default function ProductsTab() {
|
||||
const [confirmDelete, setConfirmDelete] = useState(null)
|
||||
const [search, setSearch] = useState('')
|
||||
const [view, setView] = useState('list')
|
||||
const [zoneFilter, setZoneFilter] = useState('all')
|
||||
const [priceMin, setPriceMin] = useState('')
|
||||
const [priceMax, setPriceMax] = useState('')
|
||||
const [dataQualityFilter, setDataQualityFilter] = useState('all')
|
||||
@@ -1062,7 +1085,7 @@ export default function ProductsTab() {
|
||||
const [collapsedGroups, setCollapsedGroups] = useState(new Set())
|
||||
// local override of group display order (array of group keys), reset when scope changes
|
||||
const [localGroupOrder, setLocalGroupOrder] = useState(null)
|
||||
const [bulkPrinterZoneModal, setBulkPrinterZoneModal] = useState(false)
|
||||
const [bulkPrepZoneModal, setBulkPrepZoneModal] = useState(false)
|
||||
const [bulkMoveCatModal, setBulkMoveCatModal] = useState(false)
|
||||
|
||||
// drag state for group headers
|
||||
@@ -1087,11 +1110,15 @@ export default function ProductsTab() {
|
||||
staleTime: 60_000,
|
||||
})
|
||||
const printers = statusData?.printers ?? []
|
||||
const zones = [...new Set(printers.map(p => p.name))]
|
||||
|
||||
const { data: prepZones = [] } = useQuery({
|
||||
queryKey: ['prep-zones'],
|
||||
queryFn: () => client.get('/api/prep-zones').then(r => r.data),
|
||||
})
|
||||
|
||||
const products = allProducts.map(p => ({
|
||||
...p,
|
||||
printer_zone_name: p.printer_zone_id ? printers.find(pr => pr.id === p.printer_zone_id)?.name : null,
|
||||
prep_zone_names: (p.prep_zone_ids || []).map(id => prepZones.find(z => z.id === id)?.name).filter(Boolean),
|
||||
}))
|
||||
|
||||
const invalidate = () => {
|
||||
@@ -1191,8 +1218,10 @@ export default function ProductsTab() {
|
||||
|
||||
if (selectedCat === '__archived__') {
|
||||
list = list.filter(p => p.lifecycle_status === 'archived')
|
||||
} else if (selectedCat === '__service__') {
|
||||
list = list.filter(p => p.is_service_item && p.lifecycle_status !== 'archived')
|
||||
} else if (selectedCat === '__uncategorized__') {
|
||||
list = list.filter(p => !p.category_id && p.lifecycle_status !== 'archived')
|
||||
list = list.filter(p => !p.category_id && !p.is_service_item && p.lifecycle_status !== 'archived')
|
||||
} else if (selectedCat) {
|
||||
if (isParentScope) {
|
||||
const ids = new Set([selectedCat, ...subCats.map(s => s.id)])
|
||||
@@ -1202,6 +1231,8 @@ export default function ProductsTab() {
|
||||
}
|
||||
if (!showArchived) list = list.filter(p => p.lifecycle_status !== 'archived')
|
||||
} else {
|
||||
// "All products" — exclude service items (they have their own section)
|
||||
list = list.filter(p => !p.is_service_item)
|
||||
if (!showArchived) list = list.filter(p => p.lifecycle_status !== 'archived')
|
||||
}
|
||||
|
||||
@@ -1215,8 +1246,6 @@ export default function ProductsTab() {
|
||||
list = list.filter(p => p.name.toLowerCase().includes(q))
|
||||
}
|
||||
|
||||
if (zoneFilter !== 'all') list = list.filter(p => p.printer_zone_name === zoneFilter)
|
||||
|
||||
const pmin = priceMin === '' ? -Infinity : Number(priceMin)
|
||||
const pmax = priceMax === '' ? Infinity : Number(priceMax)
|
||||
list = list.filter(p => p.base_price >= pmin && p.base_price <= pmax)
|
||||
@@ -1289,12 +1318,12 @@ export default function ProductsTab() {
|
||||
setConfirmDelete(null); invalidate(); clearSelect()
|
||||
}
|
||||
|
||||
async function handleBulkSetPrinterZone(printerId) {
|
||||
async function handleBulkSetPrepZone(prepZoneIds) {
|
||||
const ids = [...selected]
|
||||
setBulkPrinterZoneModal(false)
|
||||
setBulkPrepZoneModal(false)
|
||||
try {
|
||||
await Promise.all(ids.map(id => client.put(`/api/products/${id}`, { printer_zone_id: printerId })))
|
||||
toast.success(`Ζώνη εκτύπωσης ορίστηκε σε ${ids.length} προϊόντα`)
|
||||
await client.post('/api/products/bulk-prep-zones', { product_ids: ids, prep_zone_ids: prepZoneIds })
|
||||
toast.success(`Ζώνες προετοιμασίας ορίστηκαν σε ${ids.length} προϊόντα`)
|
||||
invalidate(); clearSelect()
|
||||
} catch { toast.error('Σφάλμα') }
|
||||
}
|
||||
@@ -1420,6 +1449,7 @@ export default function ProductsTab() {
|
||||
function getTitle() {
|
||||
if (selectedCat === null) return 'Όλα τα προϊόντα'
|
||||
if (selectedCat === '__archived__') return 'Αρχειοθετημένα'
|
||||
if (selectedCat === '__service__') return 'Service'
|
||||
if (selectedCat === '__uncategorized__') return 'Χωρίς κατηγορία'
|
||||
const cat = categories.find(c => c.id === selectedCat)
|
||||
if (!cat) return 'Προϊόντα'
|
||||
@@ -1456,15 +1486,17 @@ export default function ProductsTab() {
|
||||
totalCount={totalActive}
|
||||
search={search} setSearch={setSearch}
|
||||
view={view} setView={setView}
|
||||
zoneFilter={zoneFilter} setZoneFilter={setZoneFilter}
|
||||
priceMin={priceMin} setPriceMin={setPriceMin}
|
||||
priceMax={priceMax} setPriceMax={setPriceMax}
|
||||
dataQualityFilter={dataQualityFilter} setDataQualityFilter={setDataQualityFilter}
|
||||
showUnavailable={showUnavailable} setShowUnavailable={setShowUnavailable}
|
||||
showArchived={showArchived} setShowArchived={setShowArchived}
|
||||
zones={zones}
|
||||
onNew={() => {
|
||||
const SPECIAL = [null, '__uncategorized__', '__archived__']
|
||||
if (selectedCat === '__service__') {
|
||||
setEditProduct({ ...EMPTY_PRODUCT, is_service_item: true, base_price: 0 })
|
||||
return
|
||||
}
|
||||
const SPECIAL = [null, '__uncategorized__', '__archived__', '__service__']
|
||||
const presetCat = (!SPECIAL.includes(subCatFilter) && subCatFilter)
|
||||
|| (!SPECIAL.includes(selectedCat) && selectedCat)
|
||||
|| ''
|
||||
@@ -1491,7 +1523,7 @@ export default function ProductsTab() {
|
||||
onAvail={() => bulkAction('available')}
|
||||
onUnavail={() => bulkAction('unavailable')}
|
||||
onArchive={() => bulkAction('archive')}
|
||||
onSetPrinterZone={() => setBulkPrinterZoneModal(true)}
|
||||
onSetPrepZone={() => setBulkPrepZoneModal(true)}
|
||||
onMoveToCategory={() => setBulkMoveCatModal(true)}
|
||||
/>
|
||||
)}
|
||||
@@ -1626,6 +1658,7 @@ export default function ProductsTab() {
|
||||
product={editProduct}
|
||||
categories={categories}
|
||||
printers={printers}
|
||||
prepZones={prepZones}
|
||||
onSave={b => saveProduct.mutate(b)}
|
||||
onCopy={formData => setEditProduct({ ...EMPTY_PRODUCT, ...formData, id: undefined, image_url: undefined, name: formData.name + ' (αντίγραφο)' })}
|
||||
onClose={() => setEditProduct(null)}
|
||||
@@ -1649,13 +1682,13 @@ export default function ProductsTab() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Bulk: set printer zone modal */}
|
||||
{bulkPrinterZoneModal && (
|
||||
<BulkSetPrinterZoneModal
|
||||
{/* Bulk: set prep zone modal */}
|
||||
{bulkPrepZoneModal && (
|
||||
<BulkSetPrepZoneModal
|
||||
count={selected.size}
|
||||
printers={printers}
|
||||
onClose={() => setBulkPrinterZoneModal(false)}
|
||||
onConfirm={handleBulkSetPrinterZone}
|
||||
prepZones={prepZones}
|
||||
onClose={() => setBulkPrepZoneModal(false)}
|
||||
onConfirm={handleBulkSetPrepZone}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from '../SchedulePage'
|
||||
@@ -0,0 +1,9 @@
|
||||
import StaffTab from '../StaffTab'
|
||||
|
||||
export default function StaffPage() {
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<StaffTab />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import TablesConfigTab from '../TablesConfigTab'
|
||||
|
||||
export default function TablesConfigPage() {
|
||||
return (
|
||||
<div className="flex flex-col h-full min-h-0">
|
||||
<TablesConfigTab />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,687 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Plus, Gift, Power, Pencil, Trash2, X, Info } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../../api/client'
|
||||
import Button from '../../../ui/Button'
|
||||
import Modal from '../../../ui/Modal'
|
||||
import { ConfirmModal } from '../../../ui/Modal'
|
||||
|
||||
// ─── API ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
const api = {
|
||||
list: () => client.get('/api/pricing/deals').then(r => r.data),
|
||||
create: body => client.post('/api/pricing/deals', body).then(r => r.data),
|
||||
update: (id,b) => client.put(`/api/pricing/deals/${id}`, b).then(r => r.data),
|
||||
toggle: id => client.patch(`/api/pricing/deals/${id}/toggle`).then(r => r.data),
|
||||
remove: id => client.delete(`/api/pricing/deals/${id}`),
|
||||
modifiers: () => client.get('/api/pricing/modifiers').then(r => r.data),
|
||||
products: () => client.get('/api/products', { params: { all: true } }).then(r => r.data),
|
||||
categories:() => client.get('/api/products/categories').then(r => r.data),
|
||||
}
|
||||
|
||||
const COLORS = [
|
||||
'#6366f1','#8b5cf6','#ec4899','#f43f5e','#f97316',
|
||||
'#eab308','#22c55e','#14b8a6','#0ea5e9','#64748b',
|
||||
]
|
||||
|
||||
const CONDITION_TYPES = [
|
||||
{ value: 'min_item_quantity', label: 'Ελάχιστη ποσότητα αντικειμένου' },
|
||||
{ value: 'min_order_value', label: 'Ελάχιστη αξία παραγγελίας' },
|
||||
{ value: 'time_range', label: 'Ώρα ημέρας' },
|
||||
{ value: 'day_of_week', label: 'Ημέρα εβδομάδας' },
|
||||
{ value: 'date_range', label: 'Εύρος ημερομηνιών' },
|
||||
{ value: 'order_channel', label: 'Κανάλι παραγγελίας' },
|
||||
{ value: 'price_group_active',label: 'Ομάδα τιμής ενεργή' },
|
||||
]
|
||||
|
||||
const DAYS = ['Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο','Κυριακή']
|
||||
const CHANNELS = ['pos','online','qr','takeaway']
|
||||
|
||||
const ACTION_TYPES = [
|
||||
{ value: 'apply_modifier', label: 'Εφαρμογή τροποποιητή' },
|
||||
{ value: 'set_price', label: 'Ορισμός τιμής' },
|
||||
{ value: 'add_amount', label: '± Ποσό €' },
|
||||
{ value: 'add_percent', label: '± Ποσοστό %' },
|
||||
{ value: 'free_item', label: 'Δωρεάν προϊόν' },
|
||||
{ value: 'free_choice', label: 'Επιλογή δωρεάν προϊόντος' },
|
||||
]
|
||||
|
||||
// ─── Reuse condition editor (simplified for deals) ────────────────────────────
|
||||
|
||||
function ConditionRow({ cond, onChange, onRemove, groups }) {
|
||||
const set = (k, v) => onChange({ ...cond, params: { ...cond.params, [k]: v } })
|
||||
const setType = t => onChange({ condition_type: t, params: {} })
|
||||
|
||||
return (
|
||||
<div className="border border-slate-200 rounded-lg p-3 space-y-2 bg-slate-50">
|
||||
<div className="flex items-center gap-2">
|
||||
<select className="input flex-1 text-[12px]" value={cond.condition_type}
|
||||
onChange={e => setType(e.target.value)}>
|
||||
{CONDITION_TYPES.map(ct => <option key={ct.value} value={ct.value}>{ct.label}</option>)}
|
||||
</select>
|
||||
<button type="button" onClick={onRemove}
|
||||
className="p-1.5 rounded text-slate-400 hover:text-rose-500 hover:bg-rose-50 transition-colors">
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{cond.condition_type === 'min_item_quantity' && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Ελάχιστη ποσότητα</label>
|
||||
<input type="number" min={1} className="input w-28 text-[12px]"
|
||||
value={cond.params.min ?? 1} onChange={e => set('min', Number(e.target.value))} />
|
||||
</div>
|
||||
)}
|
||||
{cond.condition_type === 'min_order_value' && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Ελάχιστη αξία (€)</label>
|
||||
<input type="number" min={0} step={0.5} className="input w-28 text-[12px]"
|
||||
value={cond.params.min ?? 0} onChange={e => set('min', Number(e.target.value))} />
|
||||
</div>
|
||||
)}
|
||||
{cond.condition_type === 'time_range' && (
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Από</label>
|
||||
<input type="time" className="input w-full text-[12px]" value={cond.params.from ?? ''}
|
||||
onChange={e => set('from', e.target.value)} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Έως</label>
|
||||
<input type="time" className="input w-full text-[12px]" value={cond.params.to ?? ''}
|
||||
onChange={e => set('to', e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{cond.condition_type === 'day_of_week' && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{DAYS.map((d, i) => (
|
||||
<button type="button" key={i}
|
||||
onClick={() => { const days = cond.params.days ?? []; set('days', days.includes(i) ? days.filter(x => x !== i) : [...days, i]) }}
|
||||
className={`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${
|
||||
(cond.params.days ?? []).includes(i) ? 'bg-sky-100 text-sky-700' : 'bg-white border border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{d.slice(0, 3)}</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{cond.condition_type === 'date_range' && (
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Από</label>
|
||||
<input type="date" className="input w-full text-[12px]" value={cond.params.from ?? ''}
|
||||
onChange={e => set('from', e.target.value)} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Έως</label>
|
||||
<input type="date" className="input w-full text-[12px]" value={cond.params.to ?? ''}
|
||||
onChange={e => set('to', e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{cond.condition_type === 'order_channel' && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{CHANNELS.map(ch => (
|
||||
<button type="button" key={ch}
|
||||
onClick={() => { const channels = cond.params.channels ?? []; set('channels', channels.includes(ch) ? channels.filter(x => x !== ch) : [...channels, ch]) }}
|
||||
className={`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${
|
||||
(cond.params.channels ?? []).includes(ch) ? 'bg-sky-100 text-sky-700' : 'bg-white border border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{ch}</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{cond.condition_type === 'price_group_active' && (
|
||||
<div>
|
||||
<select className="input w-full text-[12px]" value={cond.params.price_group_id ?? ''}
|
||||
onChange={e => set('price_group_id', Number(e.target.value))}>
|
||||
<option value="">— Επιλογή ομάδας —</option>
|
||||
{(groups ?? []).map(g => <option key={g.id} value={g.id}>{g.name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Shared multi-picker (same logic as ModifiersTab) ─────────────────────────
|
||||
|
||||
function MultiPicker({ items, selected, onToggle, labelKey = 'name', valueKey = 'id' }) {
|
||||
return (
|
||||
<div className="border border-slate-200 rounded-lg overflow-hidden">
|
||||
{items.length === 0 && (
|
||||
<p className="text-[11px] text-slate-400 px-3 py-2">Δεν βρέθηκαν αποτελέσματα</p>
|
||||
)}
|
||||
{items.map(item => {
|
||||
const val = item[valueKey]
|
||||
const checked = selected.includes(val)
|
||||
return (
|
||||
<div key={val} onClick={() => onToggle(val)}
|
||||
className={`flex items-center gap-2.5 px-3 py-1.5 cursor-pointer transition-colors text-[12px] border-b border-slate-100 last:border-0 ${
|
||||
checked ? 'bg-sky-50 text-sky-700' : 'hover:bg-slate-50 text-slate-700'
|
||||
}`}>
|
||||
<div className={`w-4 h-4 rounded border flex items-center justify-center shrink-0 transition-colors ${
|
||||
checked ? 'bg-sky-500 border-sky-500' : 'border-slate-300 bg-white'
|
||||
}`}>
|
||||
{checked && <svg width="10" height="8" viewBox="0 0 10 8" fill="none"><path d="M1 4l3 3 5-6" stroke="white" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/></svg>}
|
||||
</div>
|
||||
{item[labelKey]}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function TagPicker({ selected, onToggle, onAdd, allTags }) {
|
||||
const [draft, setDraft] = useState('')
|
||||
const handleAdd = () => {
|
||||
const tag = draft.trim()
|
||||
if (tag && !selected.includes(tag)) onAdd(tag)
|
||||
setDraft('')
|
||||
}
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{allTags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{allTags.map(tag => {
|
||||
const active = selected.includes(tag)
|
||||
return (
|
||||
<button type="button" key={tag} onClick={() => onToggle(tag)}
|
||||
className={`px-2 py-0.5 rounded-full text-[11px] font-medium border transition-colors ${
|
||||
active ? 'bg-sky-500 border-sky-500 text-white' : 'border-slate-300 text-slate-600 hover:border-sky-400 hover:text-sky-600'
|
||||
}`}>{tag}</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{selected.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{selected.map(tag => (
|
||||
<span key={tag} className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-sky-100 text-sky-700 text-[11px] font-medium">
|
||||
{tag}
|
||||
<button type="button" onClick={() => onToggle(tag)} className="hover:text-sky-900">
|
||||
<X className="w-3 h-3" />
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-2">
|
||||
<input className="input flex-1 text-[12px]" placeholder="Νέο tag..." value={draft}
|
||||
onChange={e => setDraft(e.target.value)}
|
||||
onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); handleAdd() } }} />
|
||||
<button type="button" onClick={handleAdd}
|
||||
className="px-3 py-1.5 rounded-lg bg-slate-100 text-slate-600 text-[12px] hover:bg-slate-200 transition-colors">
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Deal target row ──────────────────────────────────────────────────────────
|
||||
|
||||
function DealTargetRow({ target, onChange, onRemove, products, categories, allTags }) {
|
||||
const ids = target.target_ids ?? []
|
||||
const tags = target.target_tags ?? []
|
||||
const setIds = v => onChange({ ...target, target_ids: v, target_id: v[0] ?? null })
|
||||
const setTags = v => onChange({ ...target, target_tags: v, target_tag: v[0] ?? null })
|
||||
const toggleId = id => setIds(ids.includes(id) ? ids.filter(x => x !== id) : [...ids, id])
|
||||
const toggleTag = tag => setTags(tags.includes(tag) ? tags.filter(x => x !== tag) : [...tags, tag])
|
||||
|
||||
return (
|
||||
<div className="border border-slate-200 rounded-lg p-3 space-y-2 bg-slate-50">
|
||||
<div className="flex items-center gap-2">
|
||||
<select className="input flex-1 text-[12px]" value={target.target_type}
|
||||
onChange={e => onChange({ target_type: e.target.value, target_id: null, target_tag: null, target_ids: [], target_tags: [] })}>
|
||||
<option value="any">Οποιοδήποτε προϊόν</option>
|
||||
<option value="item">Προϊόντα</option>
|
||||
<option value="category">Κατηγορίες</option>
|
||||
<option value="tag">Ετικέτες (tags)</option>
|
||||
</select>
|
||||
<button type="button" onClick={onRemove}
|
||||
className="p-1.5 rounded text-slate-400 hover:text-rose-500 hover:bg-rose-50 transition-colors">
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
{target.target_type === 'item' && (
|
||||
<MultiPicker items={products} selected={ids} onToggle={toggleId} />
|
||||
)}
|
||||
{target.target_type === 'category' && (
|
||||
<MultiPicker items={categories} selected={ids} onToggle={toggleId} />
|
||||
)}
|
||||
{target.target_type === 'tag' && (
|
||||
<TagPicker selected={tags} onToggle={toggleTag} onAdd={tag => setTags([...tags, tag])} allTags={allTags} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Deal form ────────────────────────────────────────────────────────────────
|
||||
|
||||
const DEAL_TABS = [
|
||||
{ key: 'info', label: 'Πληροφορίες' },
|
||||
{ key: 'trigger', label: 'Trigger & Συνθήκες' },
|
||||
{ key: 'action', label: 'Ενέργεια' },
|
||||
]
|
||||
|
||||
function DealForm({ initial, onSave, onCancel, saving, modifiers, groups, activeTab, onTabChange }) {
|
||||
const { data: products = [] } = useQuery({
|
||||
queryKey: ['products-all-pricing'],
|
||||
queryFn: () => client.get('/api/products/', { params: { all: true } }).then(r => r.data),
|
||||
})
|
||||
const { data: categories = [] } = useQuery({
|
||||
queryKey: ['categories'],
|
||||
queryFn: () => client.get('/api/products/categories').then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
const { data: allTags = [] } = useQuery({
|
||||
queryKey: ['product-tags'],
|
||||
queryFn: () => client.get('/api/products/tags').then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
|
||||
const normalizeTarget = t => ({
|
||||
...t,
|
||||
target_ids: t.target_ids ?? (t.target_id != null ? [t.target_id] : []),
|
||||
target_tags: t.target_tags ?? (t.target_tag ? [t.target_tag] : []),
|
||||
})
|
||||
|
||||
const blank = {
|
||||
name: '', description: '', color: COLORS[6], is_active: true, sort_order: 0,
|
||||
action_type: 'free_item',
|
||||
action_modifier_id: null, action_value: null,
|
||||
action_free_item_id: null,
|
||||
action_free_target_type: 'item', action_free_target_ids: [],
|
||||
action_free_quantity: 1,
|
||||
conditions: [], targets: [{ target_type: 'any', target_id: null, target_tag: null, target_ids: [], target_tags: [] }],
|
||||
}
|
||||
const [f, setF] = useState(initial ? {
|
||||
...blank, ...initial,
|
||||
conditions: initial.conditions ?? [],
|
||||
targets: (initial.targets ?? [{ target_type: 'any', target_id: null, target_tag: null, target_ids: [], target_tags: [] }]).map(normalizeTarget),
|
||||
action_free_target_ids: initial.action_free_target_ids ?? [],
|
||||
} : blank)
|
||||
|
||||
const set = (k, v) => setF(p => ({ ...p, [k]: v }))
|
||||
|
||||
const addCond = () => set('conditions', [...f.conditions, { condition_type: 'min_item_quantity', params: { min: 1 } }])
|
||||
const updCond = (i, c) => set('conditions', f.conditions.map((x, j) => j === i ? c : x))
|
||||
const remCond = i => set('conditions', f.conditions.filter((_, j) => j !== i))
|
||||
|
||||
const addTarget = () => set('targets', [...f.targets, { target_type: 'any', target_id: null, target_tag: null, target_ids: [], target_tags: [] }])
|
||||
const updTarget = (i, t) => set('targets', f.targets.map((x, j) => j === i ? t : x))
|
||||
const remTarget = i => set('targets', f.targets.filter((_, j) => j !== i))
|
||||
|
||||
const toggleFreeId = id => {
|
||||
const ids = f.action_free_target_ids ?? []
|
||||
set('action_free_target_ids', ids.includes(id) ? ids.filter(x => x !== id) : [...ids, id])
|
||||
}
|
||||
|
||||
function submit(e) {
|
||||
e.preventDefault()
|
||||
if (!f.name.trim()) return toast.error('Απαιτείται όνομα')
|
||||
onSave({
|
||||
...f,
|
||||
action_free_target_ids: f.action_free_target_ids?.length ? f.action_free_target_ids : null,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<form id="deal-form" onSubmit={submit} className="space-y-5">
|
||||
|
||||
{/* ── Info tab ── */}
|
||||
{activeTab === 'info' && (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="col-span-2">
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1">Όνομα προσφοράς</label>
|
||||
<input className="input w-full" value={f.name} onChange={e => set('name', e.target.value)}
|
||||
placeholder="π.χ. 3+1 Μπύρες" autoFocus />
|
||||
</div>
|
||||
<div className="col-span-2">
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1">Περιγραφή</label>
|
||||
<input className="input w-full" value={f.description ?? ''}
|
||||
onChange={e => set('description', e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1.5">Χρώμα</label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{COLORS.map(c => (
|
||||
<button type="button" key={c} onClick={() => set('color', c)}
|
||||
className={`w-6 h-6 rounded-full transition-transform ${f.color === c ? 'ring-2 ring-offset-1 ring-slate-400 scale-110' : 'hover:scale-105'}`}
|
||||
style={{ background: c }} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<label className="flex items-center gap-2 cursor-pointer select-none">
|
||||
<div onClick={() => set('is_active', !f.is_active)}
|
||||
className={`relative rounded-full transition-colors ${f.is_active ? 'bg-sky-500' : 'bg-slate-200'}`}
|
||||
style={{ width: 32, height: 18 }}>
|
||||
<span className={`absolute top-0.5 left-0.5 w-3.5 h-3.5 rounded-full bg-white shadow transition-transform ${f.is_active ? 'translate-x-3.5' : ''}`} />
|
||||
</div>
|
||||
<span className="text-[12px] text-slate-700">Ενεργή</span>
|
||||
</label>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ── Trigger & Conditions tab ── */}
|
||||
{activeTab === 'trigger' && (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<span className="text-[12px] font-semibold text-slate-600 uppercase tracking-wide">Trigger</span>
|
||||
<span className="text-[11px] text-slate-400 ml-1.5">Αγορά αυτών</span>
|
||||
</div>
|
||||
<button type="button" onClick={addTarget}
|
||||
className="text-[12px] text-sky-600 hover:text-sky-700 flex items-center gap-1">
|
||||
<Plus className="w-3.5 h-3.5" />Προσθήκη
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-[11px] text-slate-400">
|
||||
Ποια προϊόντα πρέπει να υπάρχουν στην παραγγελία για να ενεργοποιηθεί η προσφορά;
|
||||
</p>
|
||||
{f.targets.map((t, i) => (
|
||||
<DealTargetRow key={i} target={t} onChange={v => updTarget(i, v)} onRemove={() => remTarget(i)}
|
||||
products={products} categories={categories} allTags={allTags} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<span className="text-[12px] font-semibold text-slate-600 uppercase tracking-wide">Επιπλέον Συνθήκες</span>
|
||||
<span className="text-[11px] text-slate-400 ml-1.5">(προαιρετικά)</span>
|
||||
</div>
|
||||
<button type="button" onClick={addCond}
|
||||
className="text-[12px] text-sky-600 hover:text-sky-700 flex items-center gap-1">
|
||||
<Plus className="w-3.5 h-3.5" />Προσθήκη
|
||||
</button>
|
||||
</div>
|
||||
{f.conditions.length === 0 && (
|
||||
<p className="text-[12px] text-slate-400 bg-slate-50 rounded-lg px-3 py-2.5">
|
||||
Χωρίς επιπλέον συνθήκες — αρκεί μόνο το trigger.
|
||||
</p>
|
||||
)}
|
||||
{f.conditions.map((c, i) => (
|
||||
<ConditionRow key={i} cond={c} onChange={v => updCond(i, v)} onRemove={() => remCond(i)} groups={groups} />
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ── Action tab ── */}
|
||||
{activeTab === 'action' && (
|
||||
<div className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-2 sm:grid-cols-3">
|
||||
{ACTION_TYPES.map(({ value, label }) => (
|
||||
<button type="button" key={value} onClick={() => set('action_type', value)}
|
||||
className={`py-2 rounded-lg border text-[12px] font-medium transition-colors text-center ${
|
||||
f.action_type === value ? 'border-sky-500 bg-sky-50 text-sky-700' : 'border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{label}</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{f.action_type === 'apply_modifier' && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-1">Τροποποιητής (χωρίς συνθήκες)</label>
|
||||
<select className="input w-full text-[12px]" value={f.action_modifier_id ?? ''}
|
||||
onChange={e => set('action_modifier_id', Number(e.target.value))}>
|
||||
<option value="">— Επιλογή —</option>
|
||||
{(modifiers ?? []).filter(m => !m.conditions?.length).map(m => (
|
||||
<option key={m.id} value={m.id}>{m.name}</option>
|
||||
))}
|
||||
</select>
|
||||
<p className="text-[11px] text-slate-400 mt-1">Εμφανίζονται μόνο τροποποιητές χωρίς συνθήκες (χειροκίνητοι).</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(f.action_type === 'set_price' || f.action_type === 'add_amount' || f.action_type === 'add_percent') && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-1">
|
||||
{f.action_type === 'set_price' ? 'Νέα τιμή (€)' :
|
||||
f.action_type === 'add_amount' ? 'Ποσό (€, αρνητικό = έκπτωση)' :
|
||||
'Ποσοστό (%, αρνητικό = έκπτωση)'}
|
||||
</label>
|
||||
<input type="number" step={0.1} className="input w-36 text-[12px]"
|
||||
value={f.action_value ?? 0} onChange={e => set('action_value', Number(e.target.value))} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{f.action_type === 'free_item' && (
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-1">Δωρεάν προϊόν</label>
|
||||
<select className="input w-full text-[12px]" value={f.action_free_item_id ?? ''}
|
||||
onChange={e => set('action_free_item_id', Number(e.target.value))}>
|
||||
<option value="">— Επιλογή —</option>
|
||||
{products.map(p => <option key={p.id} value={p.id}>{p.name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-1">Ποσότητα</label>
|
||||
<input type="number" min={1} className="input w-20 text-[12px]"
|
||||
value={f.action_free_quantity} onChange={e => set('action_free_quantity', Number(e.target.value))} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{f.action_type === 'free_choice' && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-2">
|
||||
{[['item','Προϊόντα'],['category','Κατηγορία'],['tag','Ετικέτα']].map(([v,l]) => (
|
||||
<button type="button" key={v} onClick={() => { set('action_free_target_type', v); set('action_free_target_ids', []) }}
|
||||
className={`px-3 py-1 rounded text-[12px] font-medium border transition-colors ${
|
||||
f.action_free_target_type === v ? 'border-sky-500 bg-sky-50 text-sky-700' : 'border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{l}</button>
|
||||
))}
|
||||
</div>
|
||||
{f.action_free_target_type === 'item' && (
|
||||
<div className="max-h-40 overflow-y-auto border border-slate-200 rounded-lg p-2 space-y-1">
|
||||
{products.map(p => (
|
||||
<label key={p.id} className="flex items-center gap-2 cursor-pointer py-0.5">
|
||||
<input type="checkbox" className="rounded"
|
||||
checked={(f.action_free_target_ids ?? []).includes(p.id)}
|
||||
onChange={() => toggleFreeId(p.id)} />
|
||||
<span className="text-[12px] text-slate-700">{p.name}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{f.action_free_target_type === 'category' && (
|
||||
<div className="max-h-40 overflow-y-auto border border-slate-200 rounded-lg p-2 space-y-1">
|
||||
{categories.map(c => (
|
||||
<label key={c.id} className="flex items-center gap-2 cursor-pointer py-0.5">
|
||||
<input type="checkbox" className="rounded"
|
||||
checked={(f.action_free_target_ids ?? []).includes(c.id)}
|
||||
onChange={() => toggleFreeId(c.id)} />
|
||||
<span className="text-[12px] text-slate-700">{c.name}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{f.action_free_target_type === 'tag' && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-1">Ετικέτες (μία ανά γραμμή)</label>
|
||||
<textarea className="input w-full text-[12px] font-mono" rows={3}
|
||||
value={(f.action_free_target_ids ?? []).join('\n')}
|
||||
onChange={e => set('action_free_target_ids', e.target.value.split('\n').map(s => s.trim()).filter(Boolean))} />
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-1">Ποσότητα δωρεάν</label>
|
||||
<input type="number" min={1} className="input w-20 text-[12px]"
|
||||
value={f.action_free_quantity} onChange={e => set('action_free_quantity', Number(e.target.value))} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Deal card ────────────────────────────────────────────────────────────────
|
||||
|
||||
function DealCard({ deal, onEdit, onDelete }) {
|
||||
const qc = useQueryClient()
|
||||
const toggle = useMutation({
|
||||
mutationFn: () => api.toggle(deal.id),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['pricing-deals'] }),
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
|
||||
const actionLabel = ACTION_TYPES.find(a => a.value === deal.action_type)?.label ?? deal.action_type
|
||||
|
||||
return (
|
||||
<div className={`bg-white rounded-xl border shadow-sm p-4 flex items-start gap-3 transition-opacity ${deal.is_active ? 'border-slate-200' : 'border-slate-100 opacity-60'}`}>
|
||||
<div className="w-3 h-3 rounded-full mt-1 shrink-0" style={{ background: deal.color ?? '#22c55e' }} />
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="text-[14px] font-semibold text-slate-800">{deal.name}</span>
|
||||
<span className={`text-[11px] font-medium px-1.5 py-0.5 rounded-full ${
|
||||
deal.is_active ? 'bg-emerald-100 text-emerald-700' : 'bg-slate-100 text-slate-500'
|
||||
}`}>{deal.is_active ? 'Ενεργή' : 'Ανενεργή'}</span>
|
||||
<span className="text-[11px] text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded-full">{actionLabel}</span>
|
||||
</div>
|
||||
{deal.description && <p className="text-[12px] text-slate-500 mt-0.5">{deal.description}</p>}
|
||||
<p className="text-[11px] text-slate-400 mt-1">
|
||||
{deal.conditions?.length ?? 0} συνθήκες · {deal.targets?.length ?? 0} targets
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<button onClick={() => toggle.mutate()}
|
||||
className={`p-1.5 rounded-lg transition-colors ${
|
||||
deal.is_active ? 'text-emerald-600 hover:bg-emerald-50' : 'text-slate-400 hover:bg-slate-100'
|
||||
}`}>
|
||||
<Power className="w-4 h-4" />
|
||||
</button>
|
||||
<button onClick={() => onEdit(deal)}
|
||||
className="p-1.5 rounded-lg text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-colors">
|
||||
<Pencil className="w-4 h-4" />
|
||||
</button>
|
||||
<button onClick={() => onDelete(deal)}
|
||||
className="p-1.5 rounded-lg text-slate-400 hover:bg-rose-50 hover:text-rose-500 transition-colors">
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main tab ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function DealsTab() {
|
||||
const qc = useQueryClient()
|
||||
const [showForm, setShowForm] = useState(false)
|
||||
const [editing, setEditing] = useState(null)
|
||||
const [deleting, setDeleting] = useState(null)
|
||||
const [formTab, setFormTab] = useState('info')
|
||||
|
||||
const { data: deals = [], isLoading } = useQuery({ queryKey: ['pricing-deals'], queryFn: api.list })
|
||||
const { data: modifiers = [] } = useQuery({ queryKey: ['pricing-modifiers'], queryFn: api.modifiers })
|
||||
const { data: groups = [] } = useQuery({ queryKey: ['pricing-groups'], queryFn: () => client.get('/api/pricing/groups').then(r => r.data) })
|
||||
|
||||
const create = useMutation({
|
||||
mutationFn: api.create,
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-deals'] }); setShowForm(false); toast.success('Δημιουργήθηκε') },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
const update = useMutation({
|
||||
mutationFn: ({ id, body }) => api.update(id, body),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-deals'] }); setEditing(null); toast.success('Αποθηκεύτηκε') },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
const remove = useMutation({
|
||||
mutationFn: api.remove,
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-deals'] }); setDeleting(null); toast.success('Διαγράφηκε') },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
|
||||
const formProps = { modifiers, groups }
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-[14px] font-semibold text-slate-800">Προσφορές</h2>
|
||||
<p className="text-[12px] text-slate-500 mt-0.5">
|
||||
Αυτόματες δράσεις που ενεργοποιούνται όταν ο σερβιτόρος προσθέτει συγκεκριμένα προϊόντα στην παραγγελία.
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="primary" onClick={() => setShowForm(true)}>
|
||||
<Plus className="w-4 h-4 mr-1.5" />Νέα Προσφορά
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-3 bg-sky-50 border border-sky-200 rounded-lg px-4 py-3">
|
||||
<Info className="w-4 h-4 text-sky-500 shrink-0 mt-0.5" />
|
||||
<p className="text-[12px] text-sky-700">
|
||||
Όταν μια προσφορά ενεργοποιηθεί, ο σερβιτόρος λαμβάνει prompt στην εφαρμογή και επιλέγει αν θα την εφαρμόσει.
|
||||
Τίποτα δεν εφαρμόζεται αυτόματα χωρίς επιβεβαίωση.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center py-12">
|
||||
<div className="w-5 h-5 rounded-full border-2 border-sky-500 border-t-transparent animate-spin" />
|
||||
</div>
|
||||
) : deals.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-16 text-slate-400">
|
||||
<Gift className="w-10 h-10 mb-3 opacity-30" />
|
||||
<p className="text-[13px]">Δεν υπάρχουν προσφορές</p>
|
||||
<p className="text-[12px] mt-1">π.χ. «Αγόρασε 3 μπύρες, πάρε 1 δωρεάν»</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{deals.map(d => (
|
||||
<DealCard key={d.id} deal={d} onEdit={d => { setEditing(d); setFormTab('info') }} onDelete={setDeleting} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showForm && (
|
||||
<Modal title="Νέα Προσφορά" onClose={() => { setShowForm(false); setFormTab('info') }}
|
||||
maxWidth="max-w-xl" tabs={DEAL_TABS} activeTab={formTab} onTabChange={setFormTab}
|
||||
footer={<>
|
||||
<Button type="button" variant="secondary" onClick={() => { setShowForm(false); setFormTab('info') }}>Ακύρωση</Button>
|
||||
<Button type="submit" form="deal-form" variant="primary" disabled={create.isPending}>
|
||||
{create.isPending ? 'Αποθήκευση...' : 'Αποθήκευση'}
|
||||
</Button>
|
||||
</>}>
|
||||
<DealForm onSave={body => create.mutate(body)} onCancel={() => { setShowForm(false); setFormTab('info') }}
|
||||
saving={create.isPending} {...formProps} activeTab={formTab} onTabChange={setFormTab} />
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{editing && (
|
||||
<Modal title="Επεξεργασία Προσφοράς" onClose={() => { setEditing(null); setFormTab('info') }}
|
||||
maxWidth="max-w-xl" tabs={DEAL_TABS} activeTab={formTab} onTabChange={setFormTab}
|
||||
footer={<>
|
||||
<Button type="button" variant="secondary" onClick={() => { setEditing(null); setFormTab('info') }}>Ακύρωση</Button>
|
||||
<Button type="submit" form="deal-form" variant="primary" disabled={update.isPending}>
|
||||
{update.isPending ? 'Αποθήκευση...' : 'Αποθήκευση'}
|
||||
</Button>
|
||||
</>}>
|
||||
<DealForm initial={editing} onSave={body => update.mutate({ id: editing.id, body })}
|
||||
onCancel={() => { setEditing(null); setFormTab('info') }} saving={update.isPending}
|
||||
{...formProps} activeTab={formTab} onTabChange={setFormTab} />
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{deleting && (
|
||||
<ConfirmModal title="Διαγραφή Προσφοράς"
|
||||
message={`Θέλετε να διαγράψετε την προσφορά "${deleting.name}";`}
|
||||
confirmLabel="Διαγραφή"
|
||||
onConfirm={() => remove.mutate(deleting.id)}
|
||||
onCancel={() => setDeleting(null)} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Users, ShieldCheck, Save } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../../api/client'
|
||||
import Button from '../../../ui/Button'
|
||||
|
||||
// ─── API ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
const api = {
|
||||
globalGet: () => client.get('/api/pricing/discount-settings/global').then(r => r.data),
|
||||
globalPut: body => client.put('/api/pricing/discount-settings/global', body).then(r => r.data),
|
||||
waiterGet: id => client.get(`/api/pricing/discount-settings/${id}`).then(r => r.data),
|
||||
waiterPut: (id,b) => client.put(`/api/pricing/discount-settings/${id}`, b).then(r => r.data),
|
||||
staff: () => client.get('/api/waiters/').then(r => r.data),
|
||||
}
|
||||
|
||||
// ─── Toggle helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
function Toggle({ value, onChange }) {
|
||||
return (
|
||||
<div onClick={() => onChange(!value)}
|
||||
className={`relative rounded-full cursor-pointer transition-colors shrink-0 ${value ? 'bg-sky-500' : 'bg-slate-200'}`}
|
||||
style={{ width: 36, height: 20 }}>
|
||||
<span className={`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform ${value ? 'translate-x-4' : ''}`} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Numeric field ────────────────────────────────────────────────────────────
|
||||
|
||||
function NumField({ label, hint, value, onChange, step = 1, min = 0, unit = '' }) {
|
||||
return (
|
||||
<div className="space-y-1">
|
||||
<label className="block text-[12px] font-medium text-slate-600">{label}</label>
|
||||
{hint && <p className="text-[11px] text-slate-400">{hint}</p>}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<input
|
||||
type="number" min={min} step={step}
|
||||
className="input w-28 text-[12px]"
|
||||
placeholder="—"
|
||||
value={value ?? ''}
|
||||
onChange={e => onChange(e.target.value === '' ? null : Number(e.target.value))}
|
||||
/>
|
||||
{unit && <span className="text-[12px] text-slate-500">{unit}</span>}
|
||||
{value !== null && value !== undefined && (
|
||||
<button type="button" onClick={() => onChange(null)}
|
||||
className="text-[11px] text-slate-400 hover:text-slate-600 underline ml-1">
|
||||
Αφαίρεση
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Global settings panel ────────────────────────────────────────────────────
|
||||
|
||||
function GlobalPanel() {
|
||||
const qc = useQueryClient()
|
||||
const { data, isLoading } = useQuery({ queryKey: ['discount-global'], queryFn: api.globalGet })
|
||||
|
||||
const blankGlobal = {
|
||||
enabled: false,
|
||||
max_total_value_workday: null,
|
||||
max_total_value_shift: null,
|
||||
max_items_per_shift: null,
|
||||
}
|
||||
const [f, setF] = useState(null)
|
||||
const current = f ?? (data ? { ...blankGlobal, ...data } : blankGlobal)
|
||||
const set = (k, v) => setF(p => ({ ...(p ?? current), [k]: v }))
|
||||
|
||||
const save = useMutation({
|
||||
mutationFn: () => api.globalPut(current),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['discount-global'] }); setF(null); toast.success('Αποθηκεύτηκε') },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
|
||||
if (isLoading) return <div className="h-24 flex items-center justify-center"><div className="w-4 h-4 rounded-full border-2 border-sky-500 border-t-transparent animate-spin" /></div>
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-xl border border-slate-200 shadow-sm p-5 space-y-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-8 h-8 rounded-lg bg-sky-100 flex items-center justify-center shrink-0">
|
||||
<ShieldCheck className="w-4 h-4 text-sky-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-[13px] font-semibold text-slate-800">Καθολικές Ρυθμίσεις</h3>
|
||||
<p className="text-[11px] text-slate-500">Εφαρμόζονται σε όλους τους σερβιτόρους ανεξαρτήτως ατομικών ρυθμίσεων</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Master enable */}
|
||||
<div className="flex items-center justify-between py-2 border-b border-slate-100">
|
||||
<div>
|
||||
<span className="text-[13px] font-medium text-slate-700">Εκπτώσεις Ενεργές</span>
|
||||
<p className="text-[11px] text-slate-400 mt-0.5">Αν είναι ανενεργό, κανένας σερβιτόρος δεν μπορεί να εφαρμόσει εκπτώσεις</p>
|
||||
</div>
|
||||
<Toggle value={current.enabled ?? false} onChange={v => set('enabled', v)} />
|
||||
</div>
|
||||
|
||||
{/* Limits */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<NumField label="Μέγιστο ανά εργάσιμη ημέρα" hint="Ολόκληρο το κατάστημα"
|
||||
value={current.max_total_value_workday} onChange={v => set('max_total_value_workday', v)} step={0.5} unit="€" />
|
||||
<NumField label="Μέγιστο ανά βάρδια" hint="Όλες οι βάρδιες μαζί"
|
||||
value={current.max_total_value_shift} onChange={v => set('max_total_value_shift', v)} step={0.5} unit="€" />
|
||||
<NumField label="Μέγιστα αντικείμενα/βάρδια" hint="Σύνολο αντικειμένων με έκπτωση"
|
||||
value={current.max_items_per_shift} onChange={v => set('max_items_per_shift', v)} unit="τεμ." />
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button variant="primary" onClick={() => save.mutate()} disabled={save.isPending}>
|
||||
<Save className="w-3.5 h-3.5 mr-1.5" />{save.isPending ? 'Αποθήκευση...' : 'Αποθήκευση'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Per-waiter settings panel ────────────────────────────────────────────────
|
||||
|
||||
const WAITER_BLANK = {
|
||||
can_apply_discounts: false,
|
||||
max_discount_percent: null,
|
||||
max_discount_amount: null,
|
||||
max_total_value_shift: null,
|
||||
max_total_value_workday: null,
|
||||
max_items_per_shift: null,
|
||||
max_items_per_workday: null,
|
||||
max_items_per_order: null,
|
||||
}
|
||||
|
||||
function WaiterPanel({ waiters }) {
|
||||
const qc = useQueryClient()
|
||||
const [selectedId, setSelectedId] = useState(waiters[0]?.id ?? null)
|
||||
const [dirty, setDirty] = useState(null)
|
||||
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ['discount-waiter', selectedId],
|
||||
queryFn: () => api.waiterGet(selectedId),
|
||||
enabled: !!selectedId,
|
||||
})
|
||||
|
||||
const current = dirty ?? (data ? { ...WAITER_BLANK, ...data } : WAITER_BLANK)
|
||||
const set = (k, v) => setDirty(p => ({ ...(p ?? current), [k]: v }))
|
||||
|
||||
const save = useMutation({
|
||||
mutationFn: () => api.waiterPut(selectedId, current),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['discount-waiter', selectedId] }); setDirty(null); toast.success('Αποθηκεύτηκε') },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
|
||||
const selectedWaiter = waiters.find(w => w.id === selectedId)
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-xl border border-slate-200 shadow-sm p-5 space-y-5">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-8 h-8 rounded-lg bg-indigo-100 flex items-center justify-center shrink-0">
|
||||
<Users className="w-4 h-4 text-indigo-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-[13px] font-semibold text-slate-800">Ανά Σερβιτόρο</h3>
|
||||
<p className="text-[11px] text-slate-500">Ατομικά όρια — ισχύουν παράλληλα με τα καθολικά</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Waiter picker */}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{waiters.map(w => (
|
||||
<button key={w.id} type="button"
|
||||
onClick={() => { setSelectedId(w.id); setDirty(null) }}
|
||||
className={`px-3 py-1.5 rounded-lg text-[12px] font-medium border transition-colors ${
|
||||
w.id === selectedId ? 'border-indigo-500 bg-indigo-50 text-indigo-700' : 'border-slate-200 text-slate-600 hover:bg-slate-50'
|
||||
}`}>
|
||||
{w.nickname || w.full_name || w.username}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{!selectedId ? (
|
||||
<p className="text-[12px] text-slate-400 text-center py-8">Επιλέξτε σερβιτόρο</p>
|
||||
) : isLoading ? (
|
||||
<div className="h-24 flex items-center justify-center"><div className="w-4 h-4 rounded-full border-2 border-indigo-400 border-t-transparent animate-spin" /></div>
|
||||
) : (
|
||||
<div className="space-y-5">
|
||||
{/* Can apply toggle */}
|
||||
<div className="flex items-center justify-between py-2 border-b border-slate-100">
|
||||
<div>
|
||||
<span className="text-[13px] font-medium text-slate-700">
|
||||
{selectedWaiter?.nickname || selectedWaiter?.full_name || selectedWaiter?.username} — Δικαίωμα εκπτώσεων
|
||||
</span>
|
||||
<p className="text-[11px] text-slate-400 mt-0.5">Απενεργοποίηση κλειδώνει τον σερβιτόρο εντελώς</p>
|
||||
</div>
|
||||
<Toggle value={current.can_apply_discounts} onChange={v => set('can_apply_discounts', v)} />
|
||||
</div>
|
||||
|
||||
{/* Per-discount limits */}
|
||||
<div>
|
||||
<p className="text-[11px] font-semibold text-slate-500 uppercase tracking-wide mb-3">Ανά Έκπτωση</p>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<NumField label="Μέγιστο ποσοστό %" hint="Μέγιστη έκπτωση σε % ανά εφαρμογή"
|
||||
value={current.max_discount_percent} onChange={v => set('max_discount_percent', v)} step={5} unit="%" />
|
||||
<NumField label="Μέγιστο ποσό €" hint="Μέγιστο € που αφαιρείται ανά εφαρμογή"
|
||||
value={current.max_discount_amount} onChange={v => set('max_discount_amount', v)} step={0.5} unit="€" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Scope limits */}
|
||||
<div>
|
||||
<p className="text-[11px] font-semibold text-slate-500 uppercase tracking-wide mb-3">Συνολικά Όρια</p>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<NumField label="Αξία/Βάρδια" hint="Συνολική αξία εκπτώσεων ανά βάρδια"
|
||||
value={current.max_total_value_shift} onChange={v => set('max_total_value_shift', v)} step={0.5} unit="€" />
|
||||
<NumField label="Αξία/Εργάσιμη ημέρα" hint="Συνολική αξία εκπτώσεων ανά ημέρα"
|
||||
value={current.max_total_value_workday} onChange={v => set('max_total_value_workday', v)} step={0.5} unit="€" />
|
||||
<NumField label="Αντικείμενα/Βάρδια"
|
||||
value={current.max_items_per_shift} onChange={v => set('max_items_per_shift', v)} unit="τεμ." />
|
||||
<NumField label="Αντικείμενα/Εργάσιμη ημέρα"
|
||||
value={current.max_items_per_workday} onChange={v => set('max_items_per_workday', v)} unit="τεμ." />
|
||||
<NumField label="Αντικείμενα/Παραγγελία" hint="Μέγιστος αριθμός αντικειμένων με έκπτωση ανά παραγγελία"
|
||||
value={current.max_items_per_order} onChange={v => set('max_items_per_order', v)} unit="τεμ." />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button variant="primary" onClick={() => save.mutate()} disabled={save.isPending}>
|
||||
<Save className="w-3.5 h-3.5 mr-1.5" />{save.isPending ? 'Αποθήκευση...' : 'Αποθήκευση'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main tab ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function DiscountSettingsTab() {
|
||||
const { data: staff = [] } = useQuery({ queryKey: ['waiters'], queryFn: api.staff })
|
||||
const waiters = staff.filter(u => u.is_active !== false)
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-5">
|
||||
<div>
|
||||
<h2 className="text-[14px] font-semibold text-slate-800">Ρυθμίσεις Εκπτώσεων</h2>
|
||||
<p className="text-[12px] text-slate-500 mt-0.5">
|
||||
Ελέγξτε ποιοι σερβιτόροι μπορούν να εφαρμόζουν εκπτώσεις και ποια είναι τα όρια ανά βάρδια ή εργάσιμη ημέρα.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<GlobalPanel />
|
||||
|
||||
{waiters.length > 0
|
||||
? <WaiterPanel waiters={waiters} />
|
||||
: (
|
||||
<div className="bg-white rounded-xl border border-slate-200 p-8 text-center text-slate-400">
|
||||
<Users className="w-8 h-8 mx-auto mb-2 opacity-30" />
|
||||
<p className="text-[13px]">Δεν βρέθηκαν ενεργοί σερβιτόροι</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,810 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
Plus, Percent, Power, Pencil, Trash2, Star, Layers,
|
||||
GripVertical, ChevronDown, ChevronUp, X, Info,
|
||||
} from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../../api/client'
|
||||
import Button from '../../../ui/Button'
|
||||
import Modal from '../../../ui/Modal'
|
||||
import { ConfirmModal } from '../../../ui/Modal'
|
||||
|
||||
// ─── API ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
const api = {
|
||||
list: (params) => client.get('/api/pricing/modifiers', { params }).then(r => r.data),
|
||||
create: body => client.post('/api/pricing/modifiers', body).then(r => r.data),
|
||||
update: (id, b) => client.put(`/api/pricing/modifiers/${id}`, b).then(r => r.data),
|
||||
toggle: id => client.patch(`/api/pricing/modifiers/${id}/toggle`).then(r => r.data),
|
||||
reorder: items => client.patch('/api/pricing/modifiers/reorder', { items }),
|
||||
remove: id => client.delete(`/api/pricing/modifiers/${id}`),
|
||||
groups: () => client.get('/api/pricing/groups').then(r => r.data),
|
||||
products: () => client.get('/api/products', { params: { all: true } }).then(r => r.data),
|
||||
categories: () => client.get('/api/products/categories').then(r => r.data),
|
||||
prepZones: () => client.get('/api/prep-zones').then(r => r.data),
|
||||
}
|
||||
|
||||
// ─── Constants ───────────────────────────────────────────────────────────────
|
||||
|
||||
const COLORS = [
|
||||
'#6366f1','#8b5cf6','#ec4899','#f43f5e','#f97316',
|
||||
'#eab308','#22c55e','#14b8a6','#0ea5e9','#64748b',
|
||||
]
|
||||
|
||||
const CONDITION_TYPES = [
|
||||
{ value: 'time_range', label: 'Ώρα ημέρας (εύρος)' },
|
||||
{ value: 'date_range', label: 'Εύρος ημερομηνιών' },
|
||||
{ value: 'specific_date', label: 'Συγκεκριμένη ημερομηνία' },
|
||||
{ value: 'day_of_week', label: 'Ημέρα εβδομάδας' },
|
||||
{ value: 'min_item_quantity', label: 'Ελάχιστη ποσότητα προϊόντος' },
|
||||
{ value: 'min_category_qty', label: 'Ελάχιστη ποσότητα κατηγορίας' },
|
||||
{ value: 'min_order_value', label: 'Ελάχιστη αξία παραγγελίας' },
|
||||
{ value: 'order_channel', label: 'Κανάλι παραγγελίας' },
|
||||
{ value: 'price_group_active', label: 'Ομάδα τιμής ενεργή' },
|
||||
{ value: 'user_tier', label: 'Επίπεδο πελάτη (placeholder)' },
|
||||
{ value: 'low_stock', label: 'Χαμηλό απόθεμα (placeholder)' },
|
||||
]
|
||||
|
||||
const DAYS = ['Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο','Κυριακή']
|
||||
const CHANNELS = ['pos','online','qr','takeaway']
|
||||
|
||||
const ROUND_OPTIONS = [
|
||||
{ value: '', label: 'Χωρίς στρογγυλοποίηση' },
|
||||
{ value: '0.05', label: 'Στο κοντινότερο €0,05' },
|
||||
{ value: '0.10', label: 'Στο κοντινότερο €0,10' },
|
||||
{ value: '0.20', label: 'Στο κοντινότερο €0,20' },
|
||||
{ value: '0.50', label: 'Στο κοντινότερο €0,50' },
|
||||
{ value: 'x.99', label: 'Σε x,99 (π.χ. 4,99)' },
|
||||
{ value: 'x.00', label: 'Σε x,00 (στρογγυλό)' },
|
||||
]
|
||||
|
||||
// ─── Condition editor ─────────────────────────────────────────────────────────
|
||||
|
||||
function ConditionEditor({ cond, onChange, onRemove, groups, categories, prepZones }) {
|
||||
const set = (k, v) => onChange({ ...cond, params: { ...cond.params, [k]: v } })
|
||||
const setType = t => onChange({ condition_type: t, params: {} })
|
||||
|
||||
return (
|
||||
<div className="border border-slate-200 rounded-lg p-3 space-y-2 bg-slate-50">
|
||||
<div className="flex items-center gap-2">
|
||||
<select className="input flex-1 text-[12px]" value={cond.condition_type}
|
||||
onChange={e => setType(e.target.value)}>
|
||||
{CONDITION_TYPES.map(ct => (
|
||||
<option key={ct.value} value={ct.value}>{ct.label}</option>
|
||||
))}
|
||||
</select>
|
||||
<button type="button" onClick={onRemove}
|
||||
className="p-1.5 rounded text-slate-400 hover:text-rose-500 hover:bg-rose-50 transition-colors">
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Params per type */}
|
||||
{cond.condition_type === 'time_range' && (
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Από</label>
|
||||
<input type="time" className="input w-full text-[12px]" value={cond.params.from ?? ''}
|
||||
onChange={e => set('from', e.target.value)} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Έως</label>
|
||||
<input type="time" className="input w-full text-[12px]" value={cond.params.to ?? ''}
|
||||
onChange={e => set('to', e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cond.condition_type === 'date_range' && (
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Από</label>
|
||||
<input type="date" className="input w-full text-[12px]" value={cond.params.from ?? ''}
|
||||
onChange={e => set('from', e.target.value)} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Έως</label>
|
||||
<input type="date" className="input w-full text-[12px]" value={cond.params.to ?? ''}
|
||||
onChange={e => set('to', e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cond.condition_type === 'specific_date' && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Ημερομηνίες (μία ανά γραμμή)</label>
|
||||
<textarea className="input w-full text-[12px] font-mono" rows={3}
|
||||
placeholder="YYYY-MM-DD"
|
||||
value={(cond.params.dates ?? []).join('\n')}
|
||||
onChange={e => set('dates', e.target.value.split('\n').map(s => s.trim()).filter(Boolean))} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cond.condition_type === 'day_of_week' && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{DAYS.map((d, i) => (
|
||||
<button type="button" key={i}
|
||||
onClick={() => {
|
||||
const days = cond.params.days ?? []
|
||||
set('days', days.includes(i) ? days.filter(x => x !== i) : [...days, i])
|
||||
}}
|
||||
className={`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${
|
||||
(cond.params.days ?? []).includes(i) ? 'bg-sky-100 text-sky-700' : 'bg-white border border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{d.slice(0, 3)}</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cond.condition_type === 'min_item_quantity' && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Ελάχιστη ποσότητα</label>
|
||||
<input type="number" min={1} className="input w-32 text-[12px]"
|
||||
value={cond.params.min ?? 1} onChange={e => set('min', Number(e.target.value))} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cond.condition_type === 'min_category_qty' && (
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Κατηγορία</label>
|
||||
<select className="input w-full text-[12px]" value={cond.params.category_id ?? ''}
|
||||
onChange={e => set('category_id', Number(e.target.value))}>
|
||||
<option value="">— Επιλογή —</option>
|
||||
{(categories ?? []).map(c => <option key={c.id} value={c.id}>{c.name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div className="w-24">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Ελάχ.</label>
|
||||
<input type="number" min={1} className="input w-full text-[12px]"
|
||||
value={cond.params.min ?? 1} onChange={e => set('min', Number(e.target.value))} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cond.condition_type === 'min_order_value' && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Ελάχιστη αξία παραγγελίας (€)</label>
|
||||
<input type="number" min={0} step={0.5} className="input w-32 text-[12px]"
|
||||
value={cond.params.min ?? 0} onChange={e => set('min', Number(e.target.value))} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cond.condition_type === 'order_channel' && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{CHANNELS.map(ch => (
|
||||
<button type="button" key={ch}
|
||||
onClick={() => {
|
||||
const channels = cond.params.channels ?? []
|
||||
set('channels', channels.includes(ch) ? channels.filter(x => x !== ch) : [...channels, ch])
|
||||
}}
|
||||
className={`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${
|
||||
(cond.params.channels ?? []).includes(ch) ? 'bg-sky-100 text-sky-700' : 'bg-white border border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{ch}</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{cond.condition_type === 'price_group_active' && (
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Ομάδα τιμής</label>
|
||||
<select className="input w-full text-[12px]" value={cond.params.price_group_id ?? ''}
|
||||
onChange={e => set('price_group_id', Number(e.target.value))}>
|
||||
<option value="">— Επιλογή —</option>
|
||||
{(groups ?? []).map(g => <option key={g.id} value={g.id}>{g.name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(cond.condition_type === 'user_tier' || cond.condition_type === 'low_stock') && (
|
||||
<p className="text-[11px] text-amber-600 bg-amber-50 rounded px-2 py-1 flex items-center gap-1.5">
|
||||
<Info className="w-3.5 h-3.5 shrink-0" />
|
||||
Placeholder — θα ενεργοποιηθεί σε μελλοντική έκδοση
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Shared multi-picker ──────────────────────────────────────────────────────
|
||||
|
||||
function MultiPicker({ items, selected, onToggle, labelKey = 'name', valueKey = 'id', placeholder = 'Επιλέξτε...' }) {
|
||||
return (
|
||||
<div className="border border-slate-200 rounded-lg overflow-hidden">
|
||||
{items.length === 0 && (
|
||||
<p className="text-[11px] text-slate-400 px-3 py-2">{placeholder}</p>
|
||||
)}
|
||||
{items.map(item => {
|
||||
const val = item[valueKey]
|
||||
const checked = selected.includes(val)
|
||||
return (
|
||||
<div key={val} onClick={() => onToggle(val)}
|
||||
className={`flex items-center gap-2.5 px-3 py-1.5 cursor-pointer transition-colors text-[12px] border-b border-slate-100 last:border-0 ${
|
||||
checked ? 'bg-sky-50 text-sky-700' : 'hover:bg-slate-50 text-slate-700'
|
||||
}`}>
|
||||
<div className={`w-4 h-4 rounded border flex items-center justify-center shrink-0 transition-colors ${
|
||||
checked ? 'bg-sky-500 border-sky-500' : 'border-slate-300 bg-white'
|
||||
}`}>
|
||||
{checked && <svg width="10" height="8" viewBox="0 0 10 8" fill="none"><path d="M1 4l3 3 5-6" stroke="white" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/></svg>}
|
||||
</div>
|
||||
{item[labelKey]}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function TagPicker({ selected, onToggle, onAdd, allTags }) {
|
||||
const [draft, setDraft] = useState('')
|
||||
const handleAdd = () => {
|
||||
const tag = draft.trim()
|
||||
if (tag && !selected.includes(tag)) onAdd(tag)
|
||||
setDraft('')
|
||||
}
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{/* Quick-select existing tags */}
|
||||
{allTags.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{allTags.map(tag => {
|
||||
const active = selected.includes(tag)
|
||||
return (
|
||||
<button type="button" key={tag} onClick={() => onToggle(tag)}
|
||||
className={`px-2 py-0.5 rounded-full text-[11px] font-medium border transition-colors ${
|
||||
active ? 'bg-sky-500 border-sky-500 text-white' : 'border-slate-300 text-slate-600 hover:border-sky-400 hover:text-sky-600'
|
||||
}`}>{tag}</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{/* Selected chips */}
|
||||
{selected.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{selected.map(tag => (
|
||||
<span key={tag} className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-sky-100 text-sky-700 text-[11px] font-medium">
|
||||
{tag}
|
||||
<button type="button" onClick={() => onToggle(tag)} className="hover:text-sky-900">
|
||||
<X className="w-3 h-3" />
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{/* Manual entry */}
|
||||
<div className="flex gap-2">
|
||||
<input className="input flex-1 text-[12px]" placeholder="Νέο tag..." value={draft}
|
||||
onChange={e => setDraft(e.target.value)}
|
||||
onKeyDown={e => { if (e.key === 'Enter') { e.preventDefault(); handleAdd() } }} />
|
||||
<button type="button" onClick={handleAdd}
|
||||
className="px-3 py-1.5 rounded-lg bg-slate-100 text-slate-600 text-[12px] hover:bg-slate-200 transition-colors">
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Target editor ────────────────────────────────────────────────────────────
|
||||
|
||||
function TargetEditor({ target, onChange, onRemove, products, categories, prepZones, allTags }) {
|
||||
const ids = target.target_ids ?? []
|
||||
const tags = target.target_tags ?? []
|
||||
const setIds = v => onChange({ ...target, target_ids: v, target_id: v[0] ?? null })
|
||||
const setTags = v => onChange({ ...target, target_tags: v, target_tag: v[0] ?? null })
|
||||
const toggleId = id => setIds(ids.includes(id) ? ids.filter(x => x !== id) : [...ids, id])
|
||||
const toggleTag = tag => setTags(tags.includes(tag) ? tags.filter(x => x !== tag) : [...tags, tag])
|
||||
|
||||
return (
|
||||
<div className="border border-slate-200 rounded-lg p-3 space-y-2 bg-slate-50">
|
||||
<div className="flex items-center gap-2">
|
||||
<select className="input flex-1 text-[12px]" value={target.target_type}
|
||||
onChange={e => onChange({ target_type: e.target.value, target_id: null, target_tag: null, target_ids: [], target_tags: [] })}>
|
||||
<option value="all">Όλα τα προϊόντα</option>
|
||||
<option value="item">Προϊόντα</option>
|
||||
<option value="category">Κατηγορίες</option>
|
||||
<option value="prep_zone">Ζώνες ετοιμασίας</option>
|
||||
<option value="tag">Ετικέτες (tags)</option>
|
||||
</select>
|
||||
<button type="button" onClick={onRemove}
|
||||
className="p-1.5 rounded text-slate-400 hover:text-rose-500 hover:bg-rose-50 transition-colors">
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{target.target_type === 'item' && (
|
||||
<MultiPicker items={products} selected={ids} onToggle={toggleId} />
|
||||
)}
|
||||
{target.target_type === 'category' && (
|
||||
<MultiPicker items={categories} selected={ids} onToggle={toggleId} />
|
||||
)}
|
||||
{target.target_type === 'prep_zone' && (
|
||||
<MultiPicker items={prepZones} selected={ids} onToggle={toggleId} />
|
||||
)}
|
||||
{target.target_type === 'tag' && (
|
||||
<TagPicker selected={tags} onToggle={toggleTag} onAdd={tag => setTags([...tags, tag])} allTags={allTags} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Modifier form ────────────────────────────────────────────────────────────
|
||||
|
||||
const MODIFIER_TABS = [
|
||||
{ key: 'info', label: 'Πληροφορίες' },
|
||||
{ key: 'target', label: 'Στόχος' },
|
||||
{ key: 'conditions', label: 'Συνθήκες' },
|
||||
{ key: 'price', label: 'Τιμή' },
|
||||
]
|
||||
|
||||
function ModifierForm({ initial, onSave, onCancel, saving, groups, activeTab, onTabChange }) {
|
||||
const { data: products = [] } = useQuery({
|
||||
queryKey: ['products-all-pricing'],
|
||||
queryFn: () => client.get('/api/products/', { params: { all: true } }).then(r => r.data),
|
||||
})
|
||||
const { data: categories = [] } = useQuery({
|
||||
queryKey: ['categories'],
|
||||
queryFn: () => client.get('/api/products/categories').then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
const { data: prepZones = [] } = useQuery({
|
||||
queryKey: ['prep-zones'],
|
||||
queryFn: () => client.get('/api/prep-zones').then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
const { data: allTags = [] } = useQuery({
|
||||
queryKey: ['product-tags'],
|
||||
queryFn: () => client.get('/api/products/tags').then(r => r.data),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
|
||||
const normalizeTarget = t => ({
|
||||
...t,
|
||||
target_ids: t.target_ids ?? (t.target_id != null ? [t.target_id] : []),
|
||||
target_tags: t.target_tags ?? (t.target_tag ? [t.target_tag] : []),
|
||||
})
|
||||
|
||||
const blank = {
|
||||
name: '', description: '', color: COLORS[0], is_active: true, is_favorite: false,
|
||||
allow_stack: false, sort_order: 0, scope: 'global', item_id: null,
|
||||
action_type: 'add_percent', action_value: -10, round_to: '',
|
||||
conditions: [], targets: [{ target_type: 'all', target_id: null, target_tag: null, target_ids: [], target_tags: [] }],
|
||||
}
|
||||
const [f, setF] = useState(initial ? {
|
||||
...initial,
|
||||
action_value: initial.action_value ?? 0,
|
||||
round_to: initial.round_to ?? '',
|
||||
conditions: initial.conditions ?? [],
|
||||
targets: (initial.targets ?? []).map(normalizeTarget),
|
||||
} : blank)
|
||||
|
||||
const set = (k, v) => setF(p => ({ ...p, [k]: v }))
|
||||
|
||||
const addCondition = () => set('conditions', [...f.conditions, { condition_type: 'time_range', params: {} }])
|
||||
const updateCondition = (i, c) => set('conditions', f.conditions.map((x, j) => j === i ? c : x))
|
||||
const removeCondition = i => set('conditions', f.conditions.filter((_, j) => j !== i))
|
||||
|
||||
const addTarget = () => set('targets', [...f.targets, { target_type: 'all', target_id: null, target_tag: null, target_ids: [], target_tags: [] }])
|
||||
const updateTarget = (i, t) => set('targets', f.targets.map((x, j) => j === i ? t : x))
|
||||
const removeTarget = i => set('targets', f.targets.filter((_, j) => j !== i))
|
||||
|
||||
function submit(e) {
|
||||
e.preventDefault()
|
||||
if (!f.name.trim()) return toast.error('Απαιτείται όνομα')
|
||||
if (f.scope === 'item' && !f.item_id) return toast.error('Επιλέξτε προϊόν για item-scope')
|
||||
onSave({ ...f, round_to: f.round_to || null })
|
||||
}
|
||||
|
||||
const actionLabel = f.action_type === 'set' ? 'Νέα τιμή (€)' :
|
||||
f.action_type === 'add_amount' ? 'Ποσό (€, αρνητικό = έκπτωση)' :
|
||||
'Ποσοστό (%, αρνητικό = έκπτωση)'
|
||||
|
||||
return (
|
||||
<form id="modifier-form" onSubmit={submit} className="space-y-5">
|
||||
|
||||
{/* ── Info tab ── */}
|
||||
{activeTab === 'info' && (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="col-span-2">
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1">Όνομα</label>
|
||||
<input className="input w-full" value={f.name} onChange={e => set('name', e.target.value)}
|
||||
placeholder="π.χ. Happy Hour -10%" autoFocus />
|
||||
</div>
|
||||
<div className="col-span-2">
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1">Περιγραφή (προαιρετική)</label>
|
||||
<input className="input w-full" value={f.description ?? ''} onChange={e => set('description', e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1.5">Χρώμα</label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{COLORS.map(c => (
|
||||
<button type="button" key={c} onClick={() => set('color', c)}
|
||||
className={`w-6 h-6 rounded-full transition-transform ${f.color === c ? 'ring-2 ring-offset-1 ring-slate-400 scale-110' : 'hover:scale-105'}`}
|
||||
style={{ background: c }} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-4">
|
||||
{[
|
||||
{ key: 'is_active', label: 'Ενεργός' },
|
||||
{ key: 'is_favorite', label: 'Αγαπημένος (dashboard)' },
|
||||
{ key: 'allow_stack', label: 'Επιτρέπει συσσώρευση' },
|
||||
].map(({ key, label }) => (
|
||||
<label key={key} className="flex items-center gap-2 cursor-pointer select-none">
|
||||
<div onClick={() => set(key, !f[key])}
|
||||
className={`relative rounded-full transition-colors ${f[key] ? 'bg-sky-500' : 'bg-slate-200'}`}
|
||||
style={{ height: '18px', width: '32px' }}>
|
||||
<span className={`absolute top-0.5 left-0.5 w-3.5 h-3.5 rounded-full bg-white shadow transition-transform ${f[key] ? 'translate-x-3.5' : ''}`} />
|
||||
</div>
|
||||
<span className="text-[12px] text-slate-700">{label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ── Target tab ── */}
|
||||
{activeTab === 'target' && (
|
||||
<>
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1">Εμβέλεια</label>
|
||||
<div className="flex gap-2">
|
||||
{[['global','Καθολικός (με στόχους)'],['item','Συγκεκριμένο προϊόν']].map(([v, l]) => (
|
||||
<button type="button" key={v} onClick={() => set('scope', v)}
|
||||
className={`flex-1 py-2 rounded-lg border text-[12px] font-medium transition-colors ${
|
||||
f.scope === v ? 'border-sky-500 bg-sky-50 text-sky-700' : 'border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{l}</button>
|
||||
))}
|
||||
</div>
|
||||
{f.scope === 'item' && (
|
||||
<select className="input w-full mt-2 text-[13px]" value={f.item_id ?? ''}
|
||||
onChange={e => set('item_id', Number(e.target.value))}>
|
||||
<option value="">— Επιλογή προϊόντος —</option>
|
||||
{products.map(p => <option key={p.id} value={p.id}>{p.name}</option>)}
|
||||
</select>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{f.scope === 'global' && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[12px] font-semibold text-slate-600 uppercase tracking-wide">
|
||||
Στόχοι <span className="font-normal text-slate-400 normal-case ml-1">(OR — αρκεί ένας)</span>
|
||||
</span>
|
||||
<button type="button" onClick={addTarget}
|
||||
className="text-[12px] text-sky-600 hover:text-sky-700 flex items-center gap-1">
|
||||
<Plus className="w-3.5 h-3.5" />Προσθήκη
|
||||
</button>
|
||||
</div>
|
||||
{f.targets.length === 0 && (
|
||||
<p className="text-[12px] text-amber-600 bg-amber-50 rounded-lg px-3 py-2.5">
|
||||
Χωρίς στόχο — ο τροποποιητής δεν θα εφαρμοστεί σε κανένα προϊόν.
|
||||
</p>
|
||||
)}
|
||||
{f.targets.map((t, i) => (
|
||||
<TargetEditor key={i} target={t}
|
||||
onChange={v => updateTarget(i, v)}
|
||||
onRemove={() => removeTarget(i)}
|
||||
products={products} categories={categories} prepZones={prepZones} allTags={allTags} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* ── Conditions tab ── */}
|
||||
{activeTab === 'conditions' && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<span className="text-[12px] font-semibold text-slate-600 uppercase tracking-wide">Συνθήκες</span>
|
||||
<span className="text-[11px] text-slate-400 ml-1.5">AND — όλες πρέπει να ισχύουν</span>
|
||||
</div>
|
||||
<button type="button" onClick={addCondition}
|
||||
className="text-[12px] text-sky-600 hover:text-sky-700 flex items-center gap-1">
|
||||
<Plus className="w-3.5 h-3.5" />Προσθήκη
|
||||
</button>
|
||||
</div>
|
||||
{f.conditions.length === 0 && (
|
||||
<p className="text-[12px] text-slate-400 bg-slate-50 rounded-lg px-3 py-2.5">
|
||||
Χωρίς συνθήκες — ο τροποποιητής εφαρμόζεται χειροκίνητα μέσω ενεργοποίησης.
|
||||
</p>
|
||||
)}
|
||||
{f.conditions.map((c, i) => (
|
||||
<ConditionEditor key={i} cond={c}
|
||||
onChange={v => updateCondition(i, v)}
|
||||
onRemove={() => removeCondition(i)}
|
||||
groups={groups} categories={categories} prepZones={prepZones} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Price Modifier tab ── */}
|
||||
{activeTab === 'price' && (
|
||||
<div className="space-y-3">
|
||||
<div className="flex gap-2">
|
||||
{[['set','Ορισμός τιμής'],['add_amount','± Ποσό €'],['add_percent','± Ποσοστό %']].map(([v,l]) => (
|
||||
<button type="button" key={v} onClick={() => set('action_type', v)}
|
||||
className={`flex-1 py-1.5 rounded-lg border text-[12px] font-medium transition-colors ${
|
||||
f.action_type === v ? 'border-sky-500 bg-sky-50 text-sky-700' : 'border-slate-200 text-slate-500 hover:bg-slate-50'
|
||||
}`}>{l}</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex gap-3 items-end">
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">{actionLabel}</label>
|
||||
<input type="number" step={f.action_type === 'set' ? 0.01 : f.action_type === 'add_amount' ? 0.1 : 1}
|
||||
className="input w-full" value={f.action_value}
|
||||
onChange={e => set('action_value', Number(e.target.value))} />
|
||||
</div>
|
||||
{f.action_type === 'add_percent' && (
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-0.5">Στρογγυλοποίηση (προαιρ.)</label>
|
||||
<select className="input w-full text-[12px]" value={f.round_to ?? ''}
|
||||
onChange={e => set('round_to', e.target.value)}>
|
||||
{ROUND_OPTIONS.map(o => <option key={o.value} value={o.value}>{o.label}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[11px] text-slate-400">
|
||||
Το σύστημα στρογγυλοποιεί πάντα την τελική τιμή στο κοντινότερο €0,10 ανεξάρτητα από την παραπάνω επιλογή.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Modifier card ────────────────────────────────────────────────────────────
|
||||
|
||||
function ModifierCard({ modifier, onEdit, onDelete, dragHandleProps }) {
|
||||
const qc = useQueryClient()
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
|
||||
const toggle = useMutation({
|
||||
mutationFn: () => api.toggle(modifier.id),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['pricing-modifiers'] }),
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
|
||||
const actionText = modifier.action_type === 'set'
|
||||
? `= €${modifier.action_value}`
|
||||
: modifier.action_type === 'add_amount'
|
||||
? `${modifier.action_value >= 0 ? '+' : ''}€${modifier.action_value}`
|
||||
: `${modifier.action_value >= 0 ? '+' : ''}${modifier.action_value}%`
|
||||
|
||||
const condCount = modifier.conditions?.length ?? 0
|
||||
const targetSummary = modifier.scope === 'item'
|
||||
? 'item-scope'
|
||||
: modifier.targets?.length === 1 && modifier.targets[0]?.target_type === 'all'
|
||||
? 'Όλα τα προϊόντα'
|
||||
: `${modifier.targets?.length ?? 0} στόχοι`
|
||||
|
||||
return (
|
||||
<div className={`bg-white rounded-xl border shadow-sm transition-opacity ${modifier.is_active ? 'border-slate-200' : 'border-slate-100 opacity-60'}`}>
|
||||
<div className="flex items-center gap-2 px-3 py-3">
|
||||
{/* Drag handle */}
|
||||
<div {...dragHandleProps} className="cursor-grab text-slate-300 hover:text-slate-400 shrink-0">
|
||||
<GripVertical className="w-4 h-4" />
|
||||
</div>
|
||||
|
||||
{/* Color bar */}
|
||||
<div className="w-1 h-8 rounded-full shrink-0" style={{ background: modifier.color ?? '#64748b' }} />
|
||||
|
||||
{/* Name + badges */}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-1.5 flex-wrap">
|
||||
<span className="text-[13px] font-semibold text-slate-800 truncate">{modifier.name}</span>
|
||||
{modifier.is_favorite && <Star className="w-3 h-3 text-amber-400 fill-amber-400 shrink-0" />}
|
||||
{modifier.allow_stack && <Layers className="w-3 h-3 text-sky-400 shrink-0" title="Stackable" />}
|
||||
<span className={`text-[10px] font-bold px-1.5 py-0.5 rounded-full ${
|
||||
modifier.action_value < 0 ? 'bg-emerald-100 text-emerald-700' : 'bg-sky-100 text-sky-700'
|
||||
}`}>{actionText}</span>
|
||||
<span className="text-[10px] text-slate-400">{condCount === 0 ? 'χειροκίνητος' : `${condCount} συνθ.`} · {targetSummary}</span>
|
||||
</div>
|
||||
{modifier.description && <p className="text-[11px] text-slate-400 truncate mt-0.5">{modifier.description}</p>}
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex items-center gap-0.5 shrink-0">
|
||||
<button onClick={() => setExpanded(e => !e)}
|
||||
className="p-1.5 rounded text-slate-400 hover:bg-slate-100 transition-colors">
|
||||
{expanded ? <ChevronUp className="w-3.5 h-3.5" /> : <ChevronDown className="w-3.5 h-3.5" />}
|
||||
</button>
|
||||
<button onClick={() => toggle.mutate()}
|
||||
className={`p-1.5 rounded transition-colors ${
|
||||
modifier.is_active ? 'text-emerald-600 hover:bg-emerald-50' : 'text-slate-400 hover:bg-slate-100'
|
||||
}`} title={modifier.is_active ? 'Απενεργοποίηση' : 'Ενεργοποίηση'}>
|
||||
<Power className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button onClick={() => onEdit(modifier)}
|
||||
className="p-1.5 rounded text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-colors">
|
||||
<Pencil className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button onClick={() => onDelete(modifier)}
|
||||
className="p-1.5 rounded text-slate-400 hover:bg-rose-50 hover:text-rose-500 transition-colors">
|
||||
<Trash2 className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Expanded detail */}
|
||||
{expanded && (
|
||||
<div className="border-t border-slate-100 px-4 py-3 text-[12px] text-slate-500 space-y-1.5">
|
||||
{modifier.conditions?.length === 0 && <p className="italic">Χωρίς αυτόματες συνθήκες — μόνο χειροκίνητη ενεργοποίηση</p>}
|
||||
{modifier.conditions?.map((c, i) => (
|
||||
<div key={i} className="flex items-center gap-1.5">
|
||||
<span className="w-1.5 h-1.5 rounded-full bg-sky-400 shrink-0" />
|
||||
<span>{CONDITION_TYPES.find(x => x.value === c.condition_type)?.label ?? c.condition_type}</span>
|
||||
<span className="text-slate-400 font-mono text-[11px]">{JSON.stringify(c.params)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Main tab ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function ModifiersTab() {
|
||||
const qc = useQueryClient()
|
||||
const [showForm, setShowForm] = useState(false)
|
||||
const [editing, setEditing] = useState(null)
|
||||
const [deleting, setDeleting] = useState(null)
|
||||
const [formTab, setFormTab] = useState('info')
|
||||
const [scopeFilter, setScopeFilter] = useState('all')
|
||||
const [items, setItems] = useState(null)
|
||||
const [dragging, setDragging] = useState(null)
|
||||
|
||||
const { data: rawModifiers = [], isLoading } = useQuery({
|
||||
queryKey: ['pricing-modifiers'],
|
||||
queryFn: () => api.list(),
|
||||
})
|
||||
const modifiers = items ?? rawModifiers
|
||||
|
||||
const { data: groups = [] } = useQuery({ queryKey: ['pricing-groups'], queryFn: api.groups, staleTime: 30_000 })
|
||||
|
||||
const create = useMutation({
|
||||
mutationFn: api.create,
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-modifiers'] }); setItems(null); setShowForm(false); toast.success('Δημιουργήθηκε') },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
const update = useMutation({
|
||||
mutationFn: ({ id, body }) => api.update(id, body),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-modifiers'] }); setItems(null); setEditing(null); toast.success('Αποθηκεύτηκε') },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
const remove = useMutation({
|
||||
mutationFn: api.remove,
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-modifiers'] }); setItems(null); setDeleting(null); toast.success('Διαγράφηκε') },
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
const reorder = useMutation({
|
||||
mutationFn: api.reorder,
|
||||
onError: () => { setItems(null); toast.error('Σφάλμα αναδιάταξης') },
|
||||
})
|
||||
|
||||
// Simple drag-to-reorder (no extra library — HTML5 DnD)
|
||||
function handleDragStart(e, id) {
|
||||
setDragging(id)
|
||||
e.dataTransfer.effectAllowed = 'move'
|
||||
}
|
||||
function handleDragOver(e, id) {
|
||||
e.preventDefault()
|
||||
if (dragging == null || dragging === id) return
|
||||
const from = modifiers.findIndex(m => m.id === dragging)
|
||||
const to = modifiers.findIndex(m => m.id === id)
|
||||
if (from === -1 || to === -1) return
|
||||
const reordered = [...modifiers]
|
||||
const [moved] = reordered.splice(from, 1)
|
||||
reordered.splice(to, 0, moved)
|
||||
setItems(reordered)
|
||||
}
|
||||
function handleDrop() {
|
||||
setDragging(null)
|
||||
const payload = (items ?? modifiers).map((m, i) => ({ id: m.id, sort_order: i }))
|
||||
reorder.mutate(payload)
|
||||
}
|
||||
|
||||
const filtered = scopeFilter === 'all' ? modifiers : modifiers.filter(m => m.scope === scopeFilter)
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-[14px] font-semibold text-slate-800">Τροποποιητές Τιμής</h2>
|
||||
<p className="text-[12px] text-slate-500 mt-0.5">
|
||||
Κανόνες που αλλάζουν τιμές αυτόματα ή χειροκίνητα. Η σειρά καθορίζει προτεραιότητα.
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="primary" onClick={() => setShowForm(true)}>
|
||||
<Plus className="w-4 h-4 mr-1.5" />Νέος Τροποποιητής
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Filter pills */}
|
||||
<div className="flex gap-2">
|
||||
{[['all','Όλοι'],['global','Καθολικοί'],['item','Item-scope']].map(([v,l]) => (
|
||||
<button key={v} onClick={() => setScopeFilter(v)}
|
||||
className={`px-3 py-1 rounded-full text-[12px] font-medium transition-colors ${
|
||||
scopeFilter === v ? 'bg-sky-100 text-sky-700' : 'bg-slate-100 text-slate-500 hover:bg-slate-200'
|
||||
}`}>{l}</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center py-12">
|
||||
<div className="w-5 h-5 rounded-full border-2 border-sky-500 border-t-transparent animate-spin" />
|
||||
</div>
|
||||
) : filtered.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-16 text-slate-400">
|
||||
<Percent className="w-10 h-10 mb-3 opacity-30" />
|
||||
<p className="text-[13px]">Δεν υπάρχουν τροποποιητές</p>
|
||||
<p className="text-[12px] mt-1">Δημιουργήστε έναν για Happy Hour, εποχιακές τιμές κ.λπ.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2" onDragOver={e => e.preventDefault()} onDrop={handleDrop}>
|
||||
{filtered.map(m => (
|
||||
<div key={m.id} draggable
|
||||
onDragStart={e => handleDragStart(e, m.id)}
|
||||
onDragOver={e => handleDragOver(e, m.id)}
|
||||
className={dragging === m.id ? 'opacity-50' : ''}>
|
||||
<ModifierCard modifier={m} onEdit={m => { setEditing(m); setFormTab('info') }} onDelete={setDeleting}
|
||||
dragHandleProps={{
|
||||
onMouseDown: () => {},
|
||||
title: 'Σύρετε για αναδιάταξη',
|
||||
}} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Create */}
|
||||
{showForm && (
|
||||
<Modal title="Νέος Τροποποιητής Τιμής" onClose={() => { setShowForm(false); setFormTab('info') }}
|
||||
maxWidth="max-w-xl" tabs={MODIFIER_TABS} activeTab={formTab} onTabChange={setFormTab}
|
||||
footer={<>
|
||||
<Button type="button" variant="secondary" onClick={() => { setShowForm(false); setFormTab('info') }}>Ακύρωση</Button>
|
||||
<Button type="submit" form="modifier-form" variant="primary" disabled={create.isPending}>
|
||||
{create.isPending ? 'Αποθήκευση...' : 'Αποθήκευση'}
|
||||
</Button>
|
||||
</>}>
|
||||
<ModifierForm onSave={body => create.mutate(body)} onCancel={() => { setShowForm(false); setFormTab('info') }}
|
||||
saving={create.isPending} groups={groups} activeTab={formTab} onTabChange={setFormTab} />
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{/* Edit */}
|
||||
{editing && (
|
||||
<Modal title="Επεξεργασία Τροποποιητή" onClose={() => { setEditing(null); setFormTab('info') }}
|
||||
maxWidth="max-w-xl" tabs={MODIFIER_TABS} activeTab={formTab} onTabChange={setFormTab}
|
||||
footer={<>
|
||||
<Button type="button" variant="secondary" onClick={() => { setEditing(null); setFormTab('info') }}>Ακύρωση</Button>
|
||||
<Button type="submit" form="modifier-form" variant="primary" disabled={update.isPending}>
|
||||
{update.isPending ? 'Αποθήκευση...' : 'Αποθήκευση'}
|
||||
</Button>
|
||||
</>}>
|
||||
<ModifierForm initial={editing} onSave={body => update.mutate({ id: editing.id, body })}
|
||||
onCancel={() => { setEditing(null); setFormTab('info') }} saving={update.isPending}
|
||||
groups={groups} activeTab={formTab} onTabChange={setFormTab} />
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{/* Delete */}
|
||||
{deleting && (
|
||||
<ConfirmModal title="Διαγραφή Τροποποιητή"
|
||||
message={`Θέλετε να διαγράψετε τον τροποποιητή "${deleting.name}";`}
|
||||
confirmLabel="Διαγραφή"
|
||||
onConfirm={() => remove.mutate(deleting.id)}
|
||||
onCancel={() => setDeleting(null)} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Plus, Tag, Power, Pencil, Trash2, Clock } from 'lucide-react'
|
||||
import toast from 'react-hot-toast'
|
||||
import client from '../../../api/client'
|
||||
import Button from '../../../ui/Button'
|
||||
import Modal from '../../../ui/Modal'
|
||||
import { ConfirmModal } from '../../../ui/Modal'
|
||||
|
||||
const DAYS = ['Δευ', 'Τρι', 'Τετ', 'Πεμ', 'Παρ', 'Σαβ', 'Κυρ']
|
||||
|
||||
const api = {
|
||||
list: () => client.get('/api/pricing/groups').then(r => r.data),
|
||||
create: body => client.post('/api/pricing/groups', body).then(r => r.data),
|
||||
update: (id,b) => client.put(`/api/pricing/groups/${id}`, b).then(r => r.data),
|
||||
toggle: id => client.patch(`/api/pricing/groups/${id}/toggle`).then(r => r.data),
|
||||
remove: id => client.delete(`/api/pricing/groups/${id}`),
|
||||
}
|
||||
|
||||
const COLORS = [
|
||||
'#6366f1','#8b5cf6','#ec4899','#f43f5e','#f97316',
|
||||
'#eab308','#22c55e','#14b8a6','#0ea5e9','#64748b',
|
||||
]
|
||||
|
||||
function GroupForm({ initial, onSave, onCancel, saving }) {
|
||||
const blank = { name: '', description: '', color: COLORS[0], is_active: false,
|
||||
auto_enable_time: '', auto_disable_time: '', auto_days: [] }
|
||||
const [f, setF] = useState(initial ? {
|
||||
...initial,
|
||||
auto_days: initial.auto_days ?? [],
|
||||
} : blank)
|
||||
|
||||
const set = (k, v) => setF(p => ({ ...p, [k]: v }))
|
||||
const toggleDay = d => set('auto_days', f.auto_days.includes(d)
|
||||
? f.auto_days.filter(x => x !== d)
|
||||
: [...f.auto_days, d])
|
||||
|
||||
const hasSchedule = f.auto_enable_time || f.auto_disable_time || f.auto_days.length > 0
|
||||
|
||||
function submit(e) {
|
||||
e.preventDefault()
|
||||
if (!f.name.trim()) return toast.error('Απαιτείται όνομα')
|
||||
onSave({
|
||||
...f,
|
||||
auto_days: f.auto_days.length ? f.auto_days : null,
|
||||
auto_enable_time: f.auto_enable_time || null,
|
||||
auto_disable_time: f.auto_disable_time || null,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={submit} className="space-y-4">
|
||||
{/* Name */}
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1">Όνομα</label>
|
||||
<input className="input w-full" value={f.name} onChange={e => set('name', e.target.value)}
|
||||
placeholder="π.χ. Happy Hour" autoFocus />
|
||||
</div>
|
||||
|
||||
{/* Description */}
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-1">Περιγραφή (προαιρετική)</label>
|
||||
<input className="input w-full" value={f.description ?? ''} onChange={e => set('description', e.target.value)}
|
||||
placeholder="Σύντομη περιγραφή..." />
|
||||
</div>
|
||||
|
||||
{/* Color */}
|
||||
<div>
|
||||
<label className="block text-[12px] font-medium text-slate-600 mb-2">Χρώμα</label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{COLORS.map(c => (
|
||||
<button type="button" key={c} onClick={() => set('color', c)}
|
||||
className={`w-7 h-7 rounded-full transition-transform ${f.color === c ? 'ring-2 ring-offset-2 ring-slate-400 scale-110' : 'hover:scale-105'}`}
|
||||
style={{ background: c }} />
|
||||
))}
|
||||
<input type="color" value={f.color ?? '#6366f1'} onChange={e => set('color', e.target.value)}
|
||||
className="w-7 h-7 rounded-full border-0 cursor-pointer p-0.5 bg-transparent" title="Προσαρμοσμένο χρώμα" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Active toggle */}
|
||||
<label className="flex items-center gap-3 cursor-pointer select-none">
|
||||
<div onClick={() => set('is_active', !f.is_active)}
|
||||
className={`relative w-9 h-5 rounded-full transition-colors ${f.is_active ? 'bg-sky-500' : 'bg-slate-200'}`}>
|
||||
<span className={`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform ${f.is_active ? 'translate-x-4' : ''}`} />
|
||||
</div>
|
||||
<span className="text-[13px] font-medium text-slate-700">Ενεργή τώρα</span>
|
||||
</label>
|
||||
|
||||
{/* Auto-schedule */}
|
||||
<div className="rounded-lg border border-slate-200 p-3 space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Clock className="w-3.5 h-3.5 text-slate-400" />
|
||||
<span className="text-[12px] font-semibold text-slate-600 uppercase tracking-wide">Αυτόματο Χρονοδιάγραμμα</span>
|
||||
<span className="text-[11px] text-slate-400">(προαιρετικό)</span>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-1">Ενεργοποίηση</label>
|
||||
<input type="time" className="input w-full text-[13px]"
|
||||
value={f.auto_enable_time ?? ''} onChange={e => set('auto_enable_time', e.target.value)} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<label className="block text-[11px] text-slate-500 mb-1">Απενεργοποίηση</label>
|
||||
<input type="time" className="input w-full text-[13px]"
|
||||
value={f.auto_disable_time ?? ''} onChange={e => set('auto_disable_time', e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-[11px] text-slate-500 mb-1.5">Ημέρες</label>
|
||||
<div className="flex gap-1.5 flex-wrap">
|
||||
{DAYS.map((d, i) => (
|
||||
<button type="button" key={i} onClick={() => toggleDay(i)}
|
||||
className={`px-2.5 py-1 rounded text-[12px] font-medium transition-colors ${
|
||||
f.auto_days.includes(i) ? 'bg-sky-100 text-sky-700' : 'bg-slate-100 text-slate-500 hover:bg-slate-200'
|
||||
}`}>{d}</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{hasSchedule && (!f.auto_enable_time || !f.auto_disable_time || !f.auto_days.length) && (
|
||||
<p className="text-[11px] text-amber-600 bg-amber-50 rounded px-2 py-1">
|
||||
Για πλήρες χρονοδιάγραμμα ορίστε ώρα ενεργοποίησης, ώρα απενεργοποίησης και τουλάχιστον μία ημέρα.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Modal.Footer>
|
||||
<Button type="button" variant="secondary" onClick={onCancel}>Ακύρωση</Button>
|
||||
<Button type="submit" variant="primary" disabled={saving}>
|
||||
{saving ? 'Αποθήκευση...' : 'Αποθήκευση'}
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
function GroupCard({ group, onEdit, onDelete }) {
|
||||
const qc = useQueryClient()
|
||||
const toggle = useMutation({
|
||||
mutationFn: () => api.toggle(group.id),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['pricing-groups'] }),
|
||||
onError: () => toast.error('Σφάλμα'),
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-xl border border-slate-200 shadow-sm p-4 flex items-start gap-3">
|
||||
{/* Color dot */}
|
||||
<div className="w-3 h-3 rounded-full mt-1 shrink-0" style={{ background: group.color ?? '#6366f1' }} />
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="text-[14px] font-semibold text-slate-800 truncate">{group.name}</span>
|
||||
<span className={`text-[11px] font-medium px-1.5 py-0.5 rounded-full ${
|
||||
group.is_active ? 'bg-emerald-100 text-emerald-700' : 'bg-slate-100 text-slate-500'
|
||||
}`}>{group.is_active ? 'Ενεργή' : 'Ανενεργή'}</span>
|
||||
</div>
|
||||
{group.description && <p className="text-[12px] text-slate-500 mt-0.5 truncate">{group.description}</p>}
|
||||
{group.auto_enable_time && group.auto_disable_time && (
|
||||
<p className="text-[11px] text-slate-400 mt-1 flex items-center gap-1">
|
||||
<Clock className="w-3 h-3" />
|
||||
{group.auto_enable_time}–{group.auto_disable_time}
|
||||
{group.auto_days?.length > 0 && (
|
||||
<span className="ml-1">{group.auto_days.map(d => DAYS[d]).join(', ')}</span>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
{/* Quick toggle */}
|
||||
<button onClick={() => toggle.mutate()}
|
||||
className={`p-1.5 rounded-lg transition-colors ${
|
||||
group.is_active ? 'text-emerald-600 hover:bg-emerald-50' : 'text-slate-400 hover:bg-slate-100'
|
||||
}`} title={group.is_active ? 'Απενεργοποίηση' : 'Ενεργοποίηση'}>
|
||||
<Power className="w-4 h-4" />
|
||||
</button>
|
||||
<button onClick={() => onEdit(group)}
|
||||
className="p-1.5 rounded-lg text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-colors">
|
||||
<Pencil className="w-4 h-4" />
|
||||
</button>
|
||||
<button onClick={() => onDelete(group)}
|
||||
className="p-1.5 rounded-lg text-slate-400 hover:bg-rose-50 hover:text-rose-500 transition-colors">
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function PriceGroupsTab() {
|
||||
const qc = useQueryClient()
|
||||
const [showForm, setShowForm] = useState(false)
|
||||
const [editing, setEditing] = useState(null)
|
||||
const [deleting, setDeleting] = useState(null)
|
||||
|
||||
const { data: groups = [], isLoading } = useQuery({ queryKey: ['pricing-groups'], queryFn: api.list })
|
||||
|
||||
const create = useMutation({
|
||||
mutationFn: api.create,
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-groups'] }); setShowForm(false); toast.success('Ομάδα δημιουργήθηκε') },
|
||||
onError: () => toast.error('Σφάλμα δημιουργίας'),
|
||||
})
|
||||
const update = useMutation({
|
||||
mutationFn: ({ id, body }) => api.update(id, body),
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-groups'] }); setEditing(null); toast.success('Αποθηκεύτηκε') },
|
||||
onError: () => toast.error('Σφάλμα αποθήκευσης'),
|
||||
})
|
||||
const remove = useMutation({
|
||||
mutationFn: api.remove,
|
||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['pricing-groups'] }); setDeleting(null); toast.success('Διαγράφηκε') },
|
||||
onError: () => toast.error('Σφάλμα διαγραφής'),
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
{/* Header row */}
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-[14px] font-semibold text-slate-800">Ομάδες Τιμών</h2>
|
||||
<p className="text-[12px] text-slate-500 mt-0.5">
|
||||
Ονομαστές ομάδες που ενεργοποιούνται χειροκίνητα ή αυτόματα. Χρησιμοποιούνται ως συνθήκη σε τροποποιητές τιμής.
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="primary" onClick={() => setShowForm(true)}>
|
||||
<Plus className="w-4 h-4 mr-1.5" />Νέα Ομάδα
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* List */}
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center py-12">
|
||||
<div className="w-5 h-5 rounded-full border-2 border-sky-500 border-t-transparent animate-spin" />
|
||||
</div>
|
||||
) : groups.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-16 text-slate-400">
|
||||
<Tag className="w-10 h-10 mb-3 opacity-30" />
|
||||
<p className="text-[13px]">Δεν υπάρχουν ομάδες τιμών</p>
|
||||
<p className="text-[12px] mt-1">Δημιουργήστε μια ομάδα για Happy Hour, Εποχή κ.λπ.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{groups.map(g => (
|
||||
<GroupCard key={g.id} group={g}
|
||||
onEdit={setEditing}
|
||||
onDelete={setDeleting} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Create modal */}
|
||||
{showForm && (
|
||||
<Modal title="Νέα Ομάδα Τιμών" onClose={() => setShowForm(false)} maxWidth="max-w-md">
|
||||
<GroupForm onSave={body => create.mutate(body)} onCancel={() => setShowForm(false)} saving={create.isPending} />
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{/* Edit modal */}
|
||||
{editing && (
|
||||
<Modal title="Επεξεργασία Ομάδας" onClose={() => setEditing(null)} maxWidth="max-w-md">
|
||||
<GroupForm initial={editing} onSave={body => update.mutate({ id: editing.id, body })}
|
||||
onCancel={() => setEditing(null)} saving={update.isPending} />
|
||||
</Modal>
|
||||
)}
|
||||
|
||||
{/* Delete confirm */}
|
||||
{deleting && (
|
||||
<ConfirmModal
|
||||
title="Διαγραφή Ομάδας"
|
||||
message={`Θέλετε σίγουρα να διαγράψετε την ομάδα "${deleting.name}"; Τυχόν τροποποιητές που τη χρησιμοποιούν δεν θα επηρεαστούν αλλά η συνθήκη δεν θα εκπληρώνεται πλέον.`}
|
||||
confirmLabel="Διαγραφή"
|
||||
onConfirm={() => remove.mutate(deleting.id)}
|
||||
onCancel={() => setDeleting(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user