diff --git a/frontend/src/components/SeedlotRegistrationSteps/CollectionStep/index.tsx b/frontend/src/components/SeedlotRegistrationSteps/CollectionStep/index.tsx index 2fbee5926..4211cf912 100644 --- a/frontend/src/components/SeedlotRegistrationSteps/CollectionStep/index.tsx +++ b/frontend/src/components/SeedlotRegistrationSteps/CollectionStep/index.tsx @@ -189,7 +189,7 @@ const CollectionStep = ({ isReview }: CollectionStepProps) => { datePickerType="single" dateFormat={DATE_FORMAT} readOnly={isFormSubmitted && !isReview} - maxDate={maxDate} + maxDate={!isReview ? maxDate : null} value={state.startDate.value} onChange={(_e: Array, selectedDate: string) => { handleDateChange(true, selectedDate); @@ -213,7 +213,7 @@ const CollectionStep = ({ isReview }: CollectionStepProps) => { datePickerType="single" dateFormat={DATE_FORMAT} minDate={state.startDate.value} - maxDate={maxDate} + maxDate={!isReview ? maxDate : null} readOnly={isFormSubmitted && !isReview} value={state.endDate.value} onChange={(_e: Array, selectedDate: string) => { diff --git a/frontend/src/components/SeedlotRegistrationSteps/ExtractionAndStorageStep/index.tsx b/frontend/src/components/SeedlotRegistrationSteps/ExtractionAndStorageStep/index.tsx index ea966fdaf..9b0a5ccb9 100644 --- a/frontend/src/components/SeedlotRegistrationSteps/ExtractionAndStorageStep/index.tsx +++ b/frontend/src/components/SeedlotRegistrationSteps/ExtractionAndStorageStep/index.tsx @@ -227,7 +227,7 @@ const ExtractionAndStorage = ( datePickerType="single" name="storageStartDate" dateFormat={DATE_FORMAT} - maxDate={maxDate} + maxDate={!isReview ? maxDate : null} value={state.seedStorage.startDate.value} onChange={(_e: Array, selectedDate: string) => { handleDates(true, 'seedStorage', selectedDate); @@ -251,7 +251,7 @@ const ExtractionAndStorage = ( datePickerType="single" name="storageEndDate" dateFormat={DATE_FORMAT} - maxDate={maxDate} + maxDate={!isReview ? maxDate : null} value={state.seedStorage.endDate.value} onChange={(_e: Array, selectedDate: string) => { handleDates(false, 'seedStorage', selectedDate); diff --git a/frontend/src/components/SeedlotRegistrationSteps/InterimStep/index.tsx b/frontend/src/components/SeedlotRegistrationSteps/InterimStep/index.tsx index 5886c1429..6ead81ebb 100644 --- a/frontend/src/components/SeedlotRegistrationSteps/InterimStep/index.tsx +++ b/frontend/src/components/SeedlotRegistrationSteps/InterimStep/index.tsx @@ -48,9 +48,6 @@ const InterimStep = ({ isReview }:InterimStepProps) => { } = useContext(ClassAContext); const [otherChecked, setOtherChecked] = useState(state.facilityType.value === 'OTH'); - const [endDateErrMessage, setEndDateErrMessage] = useState( - pageTexts.storageDate.invalidText - ); const today = new Date(); const maxDate = today.toISOString().split('T')[0].replace(/-/g, '/'); @@ -89,20 +86,11 @@ const InterimStep = ({ isReview }:InterimStepProps) => { const isInvalid = validateStorageDates(clonedState); clonedState.startDate.isInvalid = isInvalid; clonedState.endDate.isInvalid = isInvalid; - if (clonedState.endDate.isInvalid - && endDateErrMessage === pageTexts.storageDate.invalidDateBeforeCollection - ) { - setEndDateErrMessage(pageTexts.storageDate.invalidText); - } + // Validate if end date is after collection end date if (!isStart && !isInvalid) { clonedState.endDate.isInvalid = moment(clonedState.endDate.value, 'YYYY/MM/DD') .isBefore(moment(endDate.value, 'YYYY/MM/DD')); - if (clonedState.endDate.isInvalid - && endDateErrMessage === pageTexts.storageDate.invalidText - ) { - setEndDateErrMessage(pageTexts.storageDate.invalidDateBeforeCollection); - } } setStepData('interimStep', clonedState); }; @@ -200,7 +188,7 @@ const InterimStep = ({ isReview }:InterimStepProps) => { datePickerType="single" name="startDate" dateFormat={DATE_FORMAT} - maxDate={maxDate} + maxDate={!isReview ? maxDate : null} value={state.startDate.value} onChange={(_e: Array, selectedDate: string) => { handleStorageDates(true, selectedDate); @@ -225,7 +213,7 @@ const InterimStep = ({ isReview }:InterimStepProps) => { name="endDate" dateFormat={DATE_FORMAT} minDate={state.startDate.value} - maxDate={maxDate} + maxDate={!isReview ? maxDate : null} value={state.endDate.value} onChange={(_e: Array, selectedDate: string) => { handleStorageDates(false, selectedDate); @@ -238,7 +226,14 @@ const InterimStep = ({ isReview }:InterimStepProps) => { helperText={pageTexts.storageDate.helperText} placeholder={pageTexts.storageDate.placeholder} invalid={state.endDate.isInvalid} - invalidText={endDateErrMessage} + // If start date field is invalid, it means that the end date is also + // invalid and the error message can stay the same, else, shows the + // exclusive end date error message + invalidText={ + state.startDate.isInvalid + ? pageTexts.storageDate.invalidText + : pageTexts.storageDate.invalidDateBeforeCollection + } readOnly={isFormSubmitted} autoComplete="off" />