From fb99b5f73819b9a20cf0641f9dc3ac6c5f15e3c3 Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Thu, 23 Oct 2025 07:40:31 +0000 Subject: [PATCH] Update planning dialog to show fresh data and improve guard assignment display Refactors the general planning dialog to use a computed property `currentCellData` for fetching the latest site data, ensuring real-time updates. Updates the display of assigned guards and site statistics (shifts, hours, missing guards) to reflect this fresh data. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/2w7P7NW --- .replit | 4 ++ client/src/pages/general-planning.tsx | 53 ++++++++++++--------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/.replit b/.replit index 90b1d94..1577d4d 100644 --- a/.replit +++ b/.replit @@ -19,6 +19,10 @@ externalPort = 80 localPort = 33035 externalPort = 3001 +[[ports]] +localPort = 40311 +externalPort = 5173 + [[ports]] localPort = 41343 externalPort = 3000 diff --git a/client/src/pages/general-planning.tsx b/client/src/pages/general-planning.tsx index a251823..0abf7e3 100644 --- a/client/src/pages/general-planning.tsx +++ b/client/src/pages/general-planning.tsx @@ -161,24 +161,17 @@ export default function GeneralPlanning() { staleTime: 0, }); - // Effect per aggiornare selectedCell quando planningData cambia (per real-time update del dialog) - useEffect(() => { - if (selectedCell && planningData) { - // Trova la cella aggiornata nei nuovi dati - const day = planningData.days.find(d => d.date === selectedCell.date); - if (day) { - const updatedSite = day.sites.find(s => s.siteId === selectedCell.siteId); - if (updatedSite) { - setSelectedCell({ - siteId: selectedCell.siteId, - siteName: selectedCell.siteName, - date: selectedCell.date, - data: updatedSite, - }); - } - } - } - }, [planningData]); + // Calcola dati aggiornati della cella selezionata (per auto-refresh dialog) + const currentCellData = (() => { + if (!selectedCell || !planningData) return selectedCell?.data; + + // Trova i dati freschi da planningData + const day = planningData.days.find(d => d.date === selectedCell.date); + if (!day) return selectedCell.data; + + const updatedSite = day.sites.find(s => s.siteId === selectedCell.siteId); + return updatedSite || selectedCell.data; + })(); // Mutation per eliminare assegnazione guardia const deleteAssignmentMutation = useMutation({ @@ -796,14 +789,14 @@ export default function GeneralPlanning() { {/* Guardie già assegnate - fuori dal form box per evitare di nascondere il form */} - {selectedCell.data.guards.length > 0 && ( + {currentCellData && currentCellData.guards.length > 0 && (

- Guardie Già Assegnate ({selectedCell.data.guards.length}) + Guardie Già Assegnate ({currentCellData.guards.length})

- {selectedCell.data.guards.map((guard, idx) => ( + {currentCellData.guards.map((guard, idx) => (
@@ -846,38 +839,38 @@ export default function GeneralPlanning() {

Turni Pianificati

-

{selectedCell.data.shiftsCount}

+

{currentCellData?.shiftsCount || 0}

Ore Totali

-

{selectedCell.data.totalShiftHours}h

+

{currentCellData?.totalShiftHours || 0}h

{/* Guardie mancanti */} - {selectedCell.data.missingGuards > 0 && ( + {currentCellData && currentCellData.missingGuards > 0 && (
Attenzione: Guardie Mancanti

- Servono ancora {selectedCell.data.missingGuards}{" "} - {selectedCell.data.missingGuards === 1 ? "guardia" : "guardie"} per coprire completamente il servizio - (calcolato su {selectedCell.data.totalShiftHours}h con max 9h per guardia e {selectedCell.data.minGuards} {selectedCell.data.minGuards === 1 ? "guardia minima" : "guardie minime"} contemporanee) + Servono ancora {currentCellData.missingGuards}{" "} + {currentCellData.missingGuards === 1 ? "guardia" : "guardie"} per coprire completamente il servizio + (calcolato su {currentCellData.totalShiftHours}h con max 9h per guardia e {currentCellData.minGuards} {currentCellData.minGuards === 1 ? "guardia minima" : "guardie minime"} contemporanee)

)} {/* Veicoli */} - {selectedCell.data.vehicles.length > 0 && ( + {currentCellData && currentCellData.vehicles.length > 0 && (
- Veicoli Assegnati ({selectedCell.data.vehicles.length}) + Veicoli Assegnati ({currentCellData.vehicles.length})
- {selectedCell.data.vehicles.map((vehicle, idx) => ( + {currentCellData.vehicles.map((vehicle, idx) => (

{vehicle.licensePlate}