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:
parent
153f272c15
commit
fb99b5f738
4
.replit
4
.replit
@ -19,6 +19,10 @@ externalPort = 80
|
|||||||
localPort = 33035
|
localPort = 33035
|
||||||
externalPort = 3001
|
externalPort = 3001
|
||||||
|
|
||||||
|
[[ports]]
|
||||||
|
localPort = 40311
|
||||||
|
externalPort = 5173
|
||||||
|
|
||||||
[[ports]]
|
[[ports]]
|
||||||
localPort = 41343
|
localPort = 41343
|
||||||
externalPort = 3000
|
externalPort = 3000
|
||||||
|
|||||||
@ -161,24 +161,17 @@ export default function GeneralPlanning() {
|
|||||||
staleTime: 0,
|
staleTime: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Effect per aggiornare selectedCell quando planningData cambia (per real-time update del dialog)
|
// Calcola dati aggiornati della cella selezionata (per auto-refresh dialog)
|
||||||
useEffect(() => {
|
const currentCellData = (() => {
|
||||||
if (selectedCell && planningData) {
|
if (!selectedCell || !planningData) return selectedCell?.data;
|
||||||
// Trova la cella aggiornata nei nuovi dati
|
|
||||||
|
// Trova i dati freschi da planningData
|
||||||
const day = planningData.days.find(d => d.date === selectedCell.date);
|
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);
|
const updatedSite = day.sites.find(s => s.siteId === selectedCell.siteId);
|
||||||
if (updatedSite) {
|
return updatedSite || selectedCell.data;
|
||||||
setSelectedCell({
|
})();
|
||||||
siteId: selectedCell.siteId,
|
|
||||||
siteName: selectedCell.siteName,
|
|
||||||
date: selectedCell.date,
|
|
||||||
data: updatedSite,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [planningData]);
|
|
||||||
|
|
||||||
// Mutation per eliminare assegnazione guardia
|
// Mutation per eliminare assegnazione guardia
|
||||||
const deleteAssignmentMutation = useMutation({
|
const deleteAssignmentMutation = useMutation({
|
||||||
@ -796,14 +789,14 @@ export default function GeneralPlanning() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Guardie già assegnate - fuori dal form box per evitare di nascondere il form */}
|
{/* 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">
|
<div className="space-y-2">
|
||||||
<h3 className="text-sm font-semibold flex items-center gap-2">
|
<h3 className="text-sm font-semibold flex items-center gap-2">
|
||||||
<Users className="h-4 w-4" />
|
<Users className="h-4 w-4" />
|
||||||
Guardie Già Assegnate ({selectedCell.data.guards.length})
|
Guardie Già Assegnate ({currentCellData.guards.length})
|
||||||
</h3>
|
</h3>
|
||||||
<div className="grid gap-2">
|
<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 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-1 space-y-1">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
@ -846,38 +839,38 @@ export default function GeneralPlanning() {
|
|||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm text-muted-foreground">Turni Pianificati</p>
|
<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>
|
||||||
<div>
|
<div>
|
||||||
<p className="text-sm text-muted-foreground">Ore Totali</p>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Guardie mancanti */}
|
{/* 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="p-4 bg-destructive/10 border border-destructive/20 rounded-md">
|
||||||
<div className="flex items-center gap-2 text-destructive font-semibold mb-2">
|
<div className="flex items-center gap-2 text-destructive font-semibold mb-2">
|
||||||
<AlertTriangle className="h-5 w-5" />
|
<AlertTriangle className="h-5 w-5" />
|
||||||
Attenzione: Guardie Mancanti
|
Attenzione: Guardie Mancanti
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm">
|
<p className="text-sm">
|
||||||
Servono ancora <span className="font-bold">{selectedCell.data.missingGuards}</span>{" "}
|
Servono ancora <span className="font-bold">{currentCellData.missingGuards}</span>{" "}
|
||||||
{selectedCell.data.missingGuards === 1 ? "guardia" : "guardie"} per coprire completamente il servizio
|
{currentCellData.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)
|
(calcolato su {currentCellData.totalShiftHours}h con max 9h per guardia e {currentCellData.minGuards} {currentCellData.minGuards === 1 ? "guardia minima" : "guardie minime"} contemporanee)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Veicoli */}
|
{/* Veicoli */}
|
||||||
{selectedCell.data.vehicles.length > 0 && (
|
{currentCellData && currentCellData.vehicles.length > 0 && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="flex items-center gap-2 text-sm font-semibold">
|
<div className="flex items-center gap-2 text-sm font-semibold">
|
||||||
<Car className="h-4 w-4" />
|
<Car className="h-4 w-4" />
|
||||||
Veicoli Assegnati ({selectedCell.data.vehicles.length})
|
Veicoli Assegnati ({currentCellData.vehicles.length})
|
||||||
</div>
|
</div>
|
||||||
<div className="grid gap-2">
|
<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">
|
<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="font-medium">{vehicle.licensePlate}</p>
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user