diff --git a/src/components/ArticlesList.tsx b/src/components/ArticlesList.tsx index 16cd846..95db5b2 100644 --- a/src/components/ArticlesList.tsx +++ b/src/components/ArticlesList.tsx @@ -119,6 +119,7 @@ export default function ArticlesList() { setMovimentoArticle(null); fetchArticles(); fetchGiacenze(); + window.dispatchEvent(new CustomEvent("articoli-updated")); }; const filteredArticles = articles.filter((article) => { diff --git a/src/components/MacchineTree.tsx b/src/components/MacchineTree.tsx index 1e2dd25..264ea86 100644 --- a/src/components/MacchineTree.tsx +++ b/src/components/MacchineTree.tsx @@ -95,6 +95,17 @@ export default function MacchineTree() { loadInitialData(); }, [loadInitialData]); + useEffect(() => { + const handleArticoliUpdated = () => { + fetchArticoliPerMacchina(); + }; + + window.addEventListener("articoli-updated", handleArticoliUpdated); + return () => { + window.removeEventListener("articoli-updated", handleArticoliUpdated); + }; + }, [fetchArticoliPerMacchina]); + const getParentStabilimento = (parentId: number | null): number | null => { if (!parentId) return null; const parent = nodes.find((n) => n.id === parentId);