From 0fc027eb5fa226a022c01b37c24635bdf2f43d7e Mon Sep 17 00:00:00 2001 From: bonamin Date: Mon, 8 Jun 2026 04:01:54 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20Phase=202=20feature=20flags=20=E2=80=94?= =?UTF-8?q?=20hide/show=20sidebar=20entries=20per=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- manager_dashboard/src/components/Sidebar.jsx | 37 +++++++-- .../src/hooks/usePhase2Features.js | 60 ++++++++++++++ .../src/pages/Settings/SettingsPage.jsx | 6 ++ .../pages/Settings/tabs/Phase2FeaturesTab.jsx | 83 +++++++++++++++++++ 4 files changed, 177 insertions(+), 9 deletions(-) create mode 100644 manager_dashboard/src/hooks/usePhase2Features.js create mode 100644 manager_dashboard/src/pages/Settings/tabs/Phase2FeaturesTab.jsx diff --git a/manager_dashboard/src/components/Sidebar.jsx b/manager_dashboard/src/components/Sidebar.jsx index 4096429..9a5ef0b 100644 --- a/manager_dashboard/src/components/Sidebar.jsx +++ b/manager_dashboard/src/components/Sidebar.jsx @@ -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 (