feat: Phase 2 feature flags — hide/show sidebar entries per client

- usePhase2Features.js hook: manages localStorage-based feature flags for all 8 Phase 2
  sidebar entries (notes, expenses, contacts, customers, tabs, waste, kds, schedule)
  All default to enabled=true. setFeatureEnabled() writes to localStorage and dispatches
  a 'phase2features' event so all subscribers re-render immediately without page reload
- Phase2FeaturesTab.jsx: new Settings tab 'Λειτουργίες' — toggle each Phase 2 page on/off
  with master 'Ενεργοποίηση όλων' / 'Απενεργοποίηση όλων' buttons
  Note shown: changes are localStorage-only, instant, no reload needed, no data deleted
- SettingsPage.jsx: adds 'Λειτουργίες' and reinstates 'Developer' tab (was missing import)
- Sidebar.jsx: subscribes to phase2features + storage events; filters ALL_NAV to remove
  disabled Phase 2 entries; each phase2 item has a phase2 id that isFeatureEnabled() checks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 04:01:54 +03:00
co-authored by Claude Sonnet 4.6
parent 49f19ed65c
commit 0fc027eb5f
4 changed files with 177 additions and 9 deletions
+28 -9
View File
@@ -2,10 +2,15 @@ import { NavLink } from 'react-router-dom'
import { useState, useEffect, useRef } from 'react'
import { BarChart2, LayoutGrid, ClipboardList, Package, Settings, ChevronRight, ChevronLeft, ShoppingBag, NotebookPen, Receipt, BookUser, Users, CreditCard, Trash2, ChefHat, CalendarDays } from 'lucide-react'
import { getIncomingOrders } from '../api/client'
import { isFeatureEnabled } from '../hooks/usePhase2Features'
// Phase 2 feature IDs mapped to their sidebar routes (must match usePhase2Features defs)
const PHASE2_ROUTES = new Set(['/notes', '/expenses', '/contacts', '/customers', '/tabs', '/waste', '/kds', '/schedule'])
export default function Sidebar() {
const [collapsed, setCollapsed] = useState(false)
const [pendingCount, setPendingCount] = useState(0)
const [, featTick] = useState(0)
const pollRef = useRef(null)
useEffect(() => {
@@ -20,23 +25,37 @@ export default function Sidebar() {
return () => clearInterval(pollRef.current)
}, [])
const NAV = [
// Re-render when feature flags change
useEffect(() => {
const handler = () => featTick(n => n + 1)
window.addEventListener('phase2features', handler)
window.addEventListener('storage', handler)
return () => {
window.removeEventListener('phase2features', handler)
window.removeEventListener('storage', handler)
}
}, [])
const ALL_NAV = [
{ to: '/dashboard', icon: BarChart2, label: 'Dashboard' },
{ to: '/tables', icon: LayoutGrid, label: 'Τραπέζια' },
{ to: '/online-orders', icon: ShoppingBag, label: 'Online Orders', badge: pendingCount },
{ to: '/reports', icon: ClipboardList, label: 'Αναφορές' },
{ to: '/management', icon: Package, label: 'Διαχείριση' },
{ to: '/notes', icon: NotebookPen, label: 'Σημειώσεις' },
{ to: '/expenses', icon: Receipt, label: 'Έξοδα' },
{ to: '/contacts', icon: BookUser, label: 'Επαφές' },
{ to: '/customers', icon: Users, label: 'Πελάτες' },
{ to: '/tabs', icon: CreditCard, label: 'Καρτέλες' },
{ to: '/waste', icon: Trash2, label: 'Αποβλήτα' },
{ to: '/kds', icon: ChefHat, label: 'KDS' },
{ to: '/schedule', icon: CalendarDays, label: 'Πρόγραμμα' },
{ to: '/notes', icon: NotebookPen, label: 'Σημειώσεις', phase2: 'notes' },
{ to: '/expenses', icon: Receipt, label: 'Έξοδα', phase2: 'expenses' },
{ to: '/contacts', icon: BookUser, label: 'Επαφές', phase2: 'contacts' },
{ to: '/customers', icon: Users, label: 'Πελάτες', phase2: 'customers' },
{ to: '/tabs', icon: CreditCard, label: 'Καρτέλες', phase2: 'tabs' },
{ to: '/waste', icon: Trash2, label: 'Αποβλήτα', phase2: 'waste' },
{ to: '/kds', icon: ChefHat, label: 'KDS', phase2: 'kds' },
{ to: '/schedule', icon: CalendarDays, label: 'Πρόγραμμα', phase2: 'schedule' },
{ to: '/settings', icon: Settings, label: 'Ρυθμίσεις' },
]
// Filter out disabled Phase 2 entries
const NAV = ALL_NAV.filter(item => !item.phase2 || isFeatureEnabled(item.phase2))
return (
<aside className={`flex flex-col bg-primary-800 text-white shrink-0 transition-all duration-200 ${collapsed ? 'w-16' : 'w-56'}`}>
{/* Logo / collapse toggle */}