Skip to content

Commit

Permalink
feat(monitoraggio-caricamenti): WIP validazione date 20241008
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrifantini committed Oct 8, 2024
1 parent 95166bf commit c0b4003
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,25 @@ const MonitoringSearchFilters: React.FC<MonitoringSearchFilterI> = () => {
dataFine: { ...prevValues.dataFine, minimum: formattedDate },
};
if (new Date(prevValues.dataFine.value) < new Date(formattedDate)) {
newForm.dataFine.value = '';
newDateValid.dataFine = true;
setIsDateValid(() => ({ dataInizio: false, dataFine: false }));
return prevValues;
} else {
newDateValid.dataFine = false;
setIsDateValid(() => ({ dataInizio: true, dataFine: true }));
}
} else if (field === 'dataFine') {
if (new Date(formattedDate) < new Date(prevValues.dataInizio.value)) {
console.error('La data di fine non può essere inferiore alla data di inizio');
newDateValid.dataFine = true
setIsDateValid(() => ({ dataFine: false, dataInizio: false }));
return prevValues;
} else {
newDateValid.dataFine = false;
setIsDateValid(() => ({ dataFine: true, dataInizio: true }));
}
newForm = {
...newForm,
dataFine: { ...prevValues.dataFine, value: formattedDate },
dataInizio: { ...prevValues.dataInizio, maximum: formattedDate },
};
}
setIsDateValid(newDateValid);
return newForm;
});
};
Expand All @@ -118,6 +117,7 @@ const MonitoringSearchFilters: React.FC<MonitoringSearchFilterI> = () => {

const handleClearForm = () => {
setFormValues(initialFormValues);
setIsDateValid({});
};

const renderSelect = (
Expand Down Expand Up @@ -194,9 +194,7 @@ const MonitoringSearchFilters: React.FC<MonitoringSearchFilterI> = () => {
onInputChange={(value) => handleDateInputChange(value, 'dataInizio')}
minimum={formValues.dataInizio.minimum}
maximum={formValues.dataInizio.maximum}
// className={isDateValid.dataInizio ? 'is-invalid' : 'is-valid'}
// valid = {isDateValid?.dataInizio}
{...(isDateValid.dataInizio ? { valid: false } : { valid: true })}
{...(isDateValid.dataInizio !== undefined ? { valid: isDateValid.dataInizio } : {})}
/>
<Input
value={formValues.dataFine.value}
Expand All @@ -206,9 +204,7 @@ const MonitoringSearchFilters: React.FC<MonitoringSearchFilterI> = () => {
onInputChange={(value) => handleDateInputChange(value, 'dataFine')}
minimum={formValues.dataFine.minimum}
maximum={formValues.dataFine.maximum}
{...(isDateValid.dataFine ? { valid: false } : { valid: true })}
// className= 'is-invalid'
// valid = {isDateValid?.dataFine}
{...(isDateValid.dataFine !== undefined ? { valid: isDateValid.dataFine } : {})}
/>
</Form.Row>

Expand Down

0 comments on commit c0b4003

Please sign in to comment.