-
-
+ {/* Info selezione corrente */}
+ {selectedStabilimento && (
+
+ Filtro: {selectedMagazzino
+ ? `${selectedStabilimento.descrizione} → ${selectedMagazzino.descrizione}`
+ : `${selectedStabilimento.descrizione} (tutti i magazzini)`
+ }
+
+ )}
{/* Ricerca */}
diff --git a/src/components/GlobalStabilimentoSelector.tsx b/src/components/GlobalStabilimentoSelector.tsx
new file mode 100644
index 0000000..1d5c327
--- /dev/null
+++ b/src/components/GlobalStabilimentoSelector.tsx
@@ -0,0 +1,105 @@
+"use client";
+
+import { useStabilimento } from "@/src/contexts/StabilimentoContext";
+
+export default function GlobalStabilimentoSelector() {
+ const {
+ stabilimenti,
+ selectedStabilimento,
+ selectedMagazzino,
+ filteredMagazzini,
+ loading,
+ setSelectedStabilimento,
+ setSelectedMagazzino,
+ resetSelection,
+ } = useStabilimento();
+
+ if (loading) {
+ return (
+ ([]);
- const [stabilimenti, setStabilimenti] = useState([]);
const [articlesByMacchina, setArticlesByMacchina] = useState({});
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
- const [selectedStabilimento, setSelectedStabilimento] = useState(null);
+ const { selectedStabilimento, stabilimenti } = useStabilimento();
const [copiedNodeId, setCopiedNodeId] = useState(null);
const [isCloning, setIsCloning] = useState(false);
@@ -38,23 +37,12 @@ export default function MacchineTree() {
}
}, []);
- const fetchStabilimenti = useCallback(async () => {
- try {
- const res = await fetch("/api/stabilimenti");
- if (!res.ok) throw new Error("Errore nel caricamento stabilimenti");
- const data = await res.json();
- setStabilimenti(data.stabilimenti || []);
- } catch (err) {
- console.error("Errore stabilimenti:", err);
- }
- }, []);
-
const loadInitialData = useCallback(async () => {
setLoading(true);
setError(null);
- await Promise.all([fetchNodes(), fetchStabilimenti()]);
+ await fetchNodes();
setLoading(false);
- }, [fetchNodes, fetchStabilimenti]);
+ }, [fetchNodes]);
useEffect(() => {
loadInitialData();
@@ -238,39 +226,12 @@ export default function MacchineTree() {
- {/* Filtro Stabilimento */}
-
+
+
+ );
+ }
+
+ return (
+
+ {/* Stabilimenti */}
+
+ );
+}
diff --git a/src/components/MacchineTree.tsx b/src/components/MacchineTree.tsx
index 773df16..13d4401 100644
--- a/src/components/MacchineTree.tsx
+++ b/src/components/MacchineTree.tsx
@@ -2,18 +2,17 @@
import { useState, useEffect, useCallback, useMemo } from "react";
import type { MacchinaWithDetails, ArticoliPerMacchina } from "@/src/types/macchina";
-import type { Stabilimento } from "@/src/types/stabilimento";
import TreeNode from "./TreeNode";
import MacchinaModal from "./MacchinaModal";
+import { useStabilimento } from "@/src/contexts/StabilimentoContext";
export default function MacchineTree() {
const [nodes, setNodes] = useState
+
+ {stabilimenti.map((stab) => (
+
+ ))}
+
+
+ {/* Separatore */}
+ {selectedStabilimento && filteredMagazzini.length > 0 && (
+
+ )}
+
+ {/* Magazzini */}
+ {selectedStabilimento && filteredMagazzini.length > 0 && (
+
+ Mag:
+
+ {filteredMagazzini.map((mag) => (
+
+ ))}
+
+ )}
+
-
- (false);
-
- const toggleServices = ( e: MouseEvent) => {
- e.preventDefault();
- setIsServicesOpen(!isServicesOpen);
- }
- return (
-
-
- {stabilimenti.map((stab) => (
-
- ))}
+ {/* Info selezione corrente */}
+ {selectedStabilimento && (
+
+ )}
{/* Indicatore clonazione */}
{isCloning && (
diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx
index 789adfb..3cfe1aa 100644
--- a/src/components/Navbar.tsx
+++ b/src/components/Navbar.tsx
@@ -7,46 +7,26 @@
"use client"
import { useState , MouseEvent, ReactNode} from "react";
import Link from "next/link";
+import GlobalStabilimentoSelector from "./GlobalStabilimentoSelector";
interface NavLink {
href: string;
label: string;
}
-interface ServiceLink {
- href: string;
- label: string;
-}
-
const navLinks: NavLink[] = [
{ href: "/", label: "Home"},
{ href: "/movimenti", label: "Movimenti"},
{ href: "/articoli", label: "Articoli"},
{ href: "/macchine", label: "Macchine"},
{ href: "/utenti", label: "Utenti"},
-
];
-const serviceLinks: ServiceLink[] = [
- { href: "/services/web", label: "Web Development"},
- { href: "/services/mobile", label: "Mobile Development"},
- { href: "/services/consulting", label: "Consulting"},
-
-]
-
export default function Navbar({ actions }: { actions?: ReactNode }) {
-
- const [ isServicesOpen, setIsServicesOpen] = useState
+ Filtro attivo: {selectedStabilimento.descrizione}
-