mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 00:38:11 +00:00
Add minDate handling for vessel and departure dates across components
This commit is contained in:
@@ -67,9 +67,13 @@ export default function EditScheduleDateModal({
|
||||
);
|
||||
|
||||
const [value, setValue] = useState("");
|
||||
// Earliest selectable departure, refreshed each time the modal opens.
|
||||
const [minValue, setMinValue] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
if (opened) setValue(toLocalInputValue(currentDate));
|
||||
if (!opened) return;
|
||||
setValue(toLocalInputValue(currentDate));
|
||||
setMinValue(toLocalInputValue(new Date().toISOString()));
|
||||
}, [opened, currentDate]);
|
||||
|
||||
const handleSave = async () => {
|
||||
@@ -77,6 +81,13 @@ export default function EditScheduleDateModal({
|
||||
toast({ title: "Pick a departure date", variant: "destructive" });
|
||||
return;
|
||||
}
|
||||
if (new Date(value).getTime() < Date.now()) {
|
||||
toast({
|
||||
title: "Departure date must be in the future",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await save.mutateAsync({
|
||||
id: scheduleId,
|
||||
@@ -124,6 +135,7 @@ export default function EditScheduleDateModal({
|
||||
<TextInput
|
||||
label="Departure date"
|
||||
type="datetime-local"
|
||||
min={minValue}
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.currentTarget.value)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user