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
This commit is contained in:
marco370 2025-10-23 07:40:31 +00:00
parent 153f272c15
commit fb99b5f738
2 changed files with 27 additions and 30 deletions

View File

@ -19,6 +19,10 @@ externalPort = 80
localPort = 33035
externalPort = 3001
[[ports]]
localPort = 40311
externalPort = 5173
[[ports]]
localPort = 41343
externalPort = 3000

View File

@ -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
// 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) {
if (!day) return selectedCell.data;
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]);
return updatedSite || selectedCell.data;
})();
// Mutation per eliminare assegnazione guardia
const deleteAssignmentMutation = useMutation({
@ -796,14 +789,14 @@ export default function GeneralPlanning() {
</div>
{/* Guardie già assegnate - fuori dal form box per evitare di nascondere il form */}
{selectedCell.data.guards.length > 0 && (
{currentCellData && currentCellData.guards.length > 0 && (
<div className="space-y-2">
<h3 className="text-sm font-semibold flex items-center gap-2">
<Users className="h-4 w-4" />
Guardie Già Assegnate ({selectedCell.data.guards.length})
Guardie Già Assegnate ({currentCellData.guards.length})
</h3>
<div className="grid gap-2">
{selectedCell.data.guards.map((guard, idx) => (
{currentCellData.guards.map((guard, idx) => (
<div key={idx} className="flex items-start justify-between gap-2 bg-muted/30 p-2.5 rounded border">
<div className="flex-1 space-y-1">
<div className="flex items-center gap-2">
@ -846,38 +839,38 @@ export default function GeneralPlanning() {
<div className="grid grid-cols-2 gap-4">
<div>
<p className="text-sm text-muted-foreground">Turni Pianificati</p>
<p className="text-2xl font-bold">{selectedCell.data.shiftsCount}</p>
<p className="text-2xl font-bold">{currentCellData?.shiftsCount || 0}</p>
</div>
<div>
<p className="text-sm text-muted-foreground">Ore Totali</p>
<p className="text-2xl font-bold">{selectedCell.data.totalShiftHours}h</p>
<p className="text-2xl font-bold">{currentCellData?.totalShiftHours || 0}h</p>
</div>
</div>
{/* Guardie mancanti */}
{selectedCell.data.missingGuards > 0 && (
{currentCellData && currentCellData.missingGuards > 0 && (
<div className="p-4 bg-destructive/10 border border-destructive/20 rounded-md">
<div className="flex items-center gap-2 text-destructive font-semibold mb-2">
<AlertTriangle className="h-5 w-5" />
Attenzione: Guardie Mancanti
</div>
<p className="text-sm">
Servono ancora <span className="font-bold">{selectedCell.data.missingGuards}</span>{" "}
{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 <span className="font-bold">{currentCellData.missingGuards}</span>{" "}
{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)
</p>
</div>
)}
{/* Veicoli */}
{selectedCell.data.vehicles.length > 0 && (
{currentCellData && currentCellData.vehicles.length > 0 && (
<div className="space-y-2">
<div className="flex items-center gap-2 text-sm font-semibold">
<Car className="h-4 w-4" />
Veicoli Assegnati ({selectedCell.data.vehicles.length})
Veicoli Assegnati ({currentCellData.vehicles.length})
</div>
<div className="grid gap-2">
{selectedCell.data.vehicles.map((vehicle, idx) => (
{currentCellData.vehicles.map((vehicle, idx) => (
<div key={idx} className="flex items-center gap-2 p-2 bg-accent/10 rounded-md">
<p className="font-medium">{vehicle.licensePlate}</p>
<p className="text-sm text-muted-foreground">