Improve planning duplication functionality with error handling and validation
Add validation for selected date and error handling for opening the duplicate dialog in the mobile planning view, also improve date display for scheduled routes. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e0b5b11c-5b75-4389-8ea9-5f3cd9332f88 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e0b5b11c-5b75-4389-8ea9-5f3cd9332f88/JYtd6x2
This commit is contained in:
parent
2b62d8ff4e
commit
3b3056f6b8
4
.replit
4
.replit
@ -19,6 +19,10 @@ externalPort = 80
|
|||||||
localPort = 33035
|
localPort = 33035
|
||||||
externalPort = 3001
|
externalPort = 3001
|
||||||
|
|
||||||
|
[[ports]]
|
||||||
|
localPort = 38905
|
||||||
|
externalPort = 6000
|
||||||
|
|
||||||
[[ports]]
|
[[ports]]
|
||||||
localPort = 41295
|
localPort = 41295
|
||||||
externalPort = 5173
|
externalPort = 5173
|
||||||
|
|||||||
@ -273,13 +273,33 @@ export default function PlanningMobile() {
|
|||||||
|
|
||||||
// Funzione per aprire dialog duplicazione sequenza
|
// Funzione per aprire dialog duplicazione sequenza
|
||||||
const handleOpenDuplicateDialog = (route: any) => {
|
const handleOpenDuplicateDialog = (route: any) => {
|
||||||
const nextDay = format(addDays(parseISO(selectedDate), 1), "yyyy-MM-dd");
|
try {
|
||||||
setDuplicateDialog({
|
// Validazione data selezionata
|
||||||
isOpen: true,
|
const parsedDate = parseISO(selectedDate);
|
||||||
sourceRoute: route,
|
if (!isValid(parsedDate)) {
|
||||||
targetDate: nextDay, // Default = giorno successivo
|
toast({
|
||||||
selectedDuplicateGuardId: route.guardId, // Pre-compilato con guardia attuale
|
title: "Errore data",
|
||||||
});
|
description: "La data selezionata non è valida",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextDay = format(addDays(parsedDate, 1), "yyyy-MM-dd");
|
||||||
|
setDuplicateDialog({
|
||||||
|
isOpen: true,
|
||||||
|
sourceRoute: route,
|
||||||
|
targetDate: nextDay, // Default = giorno successivo
|
||||||
|
selectedDuplicateGuardId: route.guardId || "", // Pre-compilato con guardia attuale
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
title: "Errore",
|
||||||
|
description: "Impossibile aprire il dialog di duplicazione",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
console.error("Error opening duplicate dialog:", error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handler submit dialog duplicazione
|
// Handler submit dialog duplicazione
|
||||||
@ -879,7 +899,9 @@ export default function PlanningMobile() {
|
|||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<span className="text-muted-foreground">Data:</span>
|
<span className="text-muted-foreground">Data:</span>
|
||||||
<span className="font-medium">
|
<span className="font-medium">
|
||||||
{format(parseISO(duplicateDialog.sourceRoute.scheduledDate), "dd/MM/yyyy", { locale: it })}
|
{duplicateDialog.sourceRoute.scheduledDate && isValid(parseISO(duplicateDialog.sourceRoute.scheduledDate))
|
||||||
|
? format(parseISO(duplicateDialog.sourceRoute.scheduledDate), "dd/MM/yyyy", { locale: it })
|
||||||
|
: "Data non valida"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
@ -901,7 +923,7 @@ export default function PlanningMobile() {
|
|||||||
data-testid="input-target-date"
|
data-testid="input-target-date"
|
||||||
/>
|
/>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
{duplicateDialog.sourceRoute && duplicateDialog.targetDate &&
|
{duplicateDialog.sourceRoute && duplicateDialog.targetDate && duplicateDialog.sourceRoute.scheduledDate && isValid(parseISO(duplicateDialog.sourceRoute.scheduledDate)) &&
|
||||||
format(parseISO(duplicateDialog.sourceRoute.scheduledDate), "yyyy-MM-dd") === duplicateDialog.targetDate
|
format(parseISO(duplicateDialog.sourceRoute.scheduledDate), "yyyy-MM-dd") === duplicateDialog.targetDate
|
||||||
? "⚠️ Stessa data: verrà modificata la guardia della sequenza esistente"
|
? "⚠️ Stessa data: verrà modificata la guardia della sequenza esistente"
|
||||||
: "✓ Data diversa: verrà creata una nuova sequenza con tutte le tappe"
|
: "✓ Data diversa: verrà creata una nuova sequenza con tutte le tappe"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user