Update planning to enforce daily guard hour limits and improve assignment logic
Add daily hour limit checks during guard assignment and ensure guards with completed ordinary hours are not displayed unless they have overtime. Refactor guard availability query to refetch immediately on assignment success and update staleTime to 0. 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/Jxn533V
This commit is contained in:
parent
1c34d3f79e
commit
b1b320ab69
@ -132,7 +132,7 @@ export default function GeneralPlanning() {
|
||||
};
|
||||
|
||||
// Query per guardie disponibili (solo quando dialog è aperto)
|
||||
const { data: availableGuards, isLoading: isLoadingGuards } = useQuery<GuardAvailability[]>({
|
||||
const { data: availableGuards, isLoading: isLoadingGuards, refetch: refetchGuards } = useQuery<GuardAvailability[]>({
|
||||
queryKey: ["/api/guards/availability", selectedCell?.siteId, selectedLocation, startTime, durationHours],
|
||||
queryFn: async () => {
|
||||
if (!selectedCell) return [];
|
||||
@ -144,6 +144,7 @@ export default function GeneralPlanning() {
|
||||
return response.json();
|
||||
},
|
||||
enabled: !!selectedCell, // Query attiva solo se dialog è aperto
|
||||
staleTime: 0, // Dati sempre considerati stale, refetch ad ogni apertura dialog
|
||||
});
|
||||
|
||||
// Mutation per eliminare assegnazione guardia
|
||||
@ -174,19 +175,21 @@ export default function GeneralPlanning() {
|
||||
mutationFn: async (data: { siteId: string; date: string; guardId: string; startTime: string; durationHours: number; consecutiveDays: number }) => {
|
||||
return apiRequest("POST", "/api/general-planning/assign-guard", data);
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSuccess: async () => {
|
||||
// Invalida cache planning generale
|
||||
queryClient.invalidateQueries({ queryKey: ["/api/general-planning"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["/api/guards/availability"] });
|
||||
await queryClient.invalidateQueries({ queryKey: ["/api/general-planning"] });
|
||||
await queryClient.invalidateQueries({ queryKey: ["/api/guards/availability"] });
|
||||
|
||||
// Refetch immediatamente guardie disponibili per aggiornare lista
|
||||
await refetchGuards();
|
||||
|
||||
toast({
|
||||
title: "Guardia assegnata",
|
||||
description: "La guardia è stata assegnata con successo",
|
||||
});
|
||||
|
||||
// Reset form
|
||||
// Reset solo guardia selezionata (NON chiudere dialog per vedere lista aggiornata)
|
||||
setSelectedGuardId("");
|
||||
setSelectedCell(null);
|
||||
},
|
||||
onError: (error: any) => {
|
||||
// Parse error message from API response
|
||||
|
||||
Loading…
Reference in New Issue
Block a user