Add a weekly guard schedule overview page
Add a new page to display a summarized weekly schedule for guards, divided by location, with detailed shift information accessible on click. Includes error handling for data fetching. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e0b5b11c-5b75-4389-8ea9-5f3cd9332f88 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e0b5b11c-5b75-4389-8ea9-5f3cd9332f88/EPTvOHB
This commit is contained in:
parent
d868c6ee31
commit
7b05c8cbce
4
.replit
4
.replit
@ -19,6 +19,10 @@ externalPort = 80
|
||||
localPort = 33035
|
||||
externalPort = 3001
|
||||
|
||||
[[ports]]
|
||||
localPort = 39861
|
||||
externalPort = 6000
|
||||
|
||||
[[ports]]
|
||||
localPort = 40417
|
||||
externalPort = 8000
|
||||
|
||||
@ -69,8 +69,18 @@ export default function WeeklyGuards() {
|
||||
);
|
||||
const [dialogData, setDialogData] = useState<DialogData>(null);
|
||||
|
||||
const { data: scheduleData, isLoading } = useQuery<WeeklyScheduleResponse>({
|
||||
const { data: scheduleData, isLoading, error } = useQuery<WeeklyScheduleResponse>({
|
||||
queryKey: ["/api/weekly-guards-schedule", selectedLocation, format(currentWeekStart, "yyyy-MM-dd")],
|
||||
queryFn: async () => {
|
||||
const startDate = format(currentWeekStart, "yyyy-MM-dd");
|
||||
const response = await fetch(
|
||||
`/api/weekly-guards-schedule?location=${selectedLocation}&startDate=${startDate}`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch weekly schedule");
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
enabled: !!selectedLocation,
|
||||
});
|
||||
|
||||
@ -237,6 +247,14 @@ export default function WeeklyGuards() {
|
||||
<p className="text-center text-muted-foreground">Caricamento...</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : error ? (
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<p className="text-center text-destructive">
|
||||
Errore nel caricamento della pianificazione. Riprova più tardi.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : scheduleData && scheduleData.guards.length > 0 ? (
|
||||
<Card>
|
||||
<CardContent className="p-0">
|
||||
@ -331,12 +349,12 @@ export default function WeeklyGuards() {
|
||||
{dialogData?.type === "fixed" ? (
|
||||
<>
|
||||
<MapPin className="h-5 w-5" />
|
||||
Turno Fisso - {dialogData.guardName}
|
||||
Turno Fisso - {dialogData?.guardName}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Navigation className="h-5 w-5" />
|
||||
Turno Mobile - {dialogData.guardName}
|
||||
Turno Mobile - {dialogData?.guardName}
|
||||
</>
|
||||
)}
|
||||
</DialogTitle>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user