Skip to content

Commit

Permalink
fix: removing the future date limitation for review
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaseta committed Aug 1, 2024
1 parent 83428b4 commit 5aa79b2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Date>, selectedDate: string) => {
handleDateChange(true, selectedDate);
Expand All @@ -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<Date>, selectedDate: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Date>, selectedDate: string) => {
handleDates(true, 'seedStorage', selectedDate);
Expand All @@ -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<Date>, selectedDate: string) => {
handleDates(false, 'seedStorage', selectedDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ const InterimStep = ({ isReview }:InterimStepProps) => {
} = useContext(ClassAContext);

const [otherChecked, setOtherChecked] = useState(state.facilityType.value === 'OTH');
const [endDateErrMessage, setEndDateErrMessage] = useState<string>(
pageTexts.storageDate.invalidText
);

const today = new Date();
const maxDate = today.toISOString().split('T')[0].replace(/-/g, '/');
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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<Date>, selectedDate: string) => {
handleStorageDates(true, selectedDate);
Expand All @@ -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<Date>, selectedDate: string) => {
handleStorageDates(false, selectedDate);
Expand All @@ -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"
/>
Expand Down

0 comments on commit 5aa79b2

Please sign in to comment.