Skip to content

Commit

Permalink
fix: adding max date prop to today on date inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaseta committed Aug 1, 2024
1 parent a4997e1 commit 4257042
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const CollectionStep = ({ isReview }: CollectionStepProps) => {
isFormSubmitted
} = useContext(ClassAContext);

const today = new Date();
const maxDate = today.toISOString().split('T')[0].replace(/-/g, '/');

const [isCalcWrong, setIsCalcWrong] = useState<boolean>(false);

const setAgencyAndCode = (
Expand Down Expand Up @@ -186,6 +189,7 @@ const CollectionStep = ({ isReview }: CollectionStepProps) => {
datePickerType="single"
dateFormat={DATE_FORMAT}
readOnly={isFormSubmitted && !isReview}
maxDate={maxDate}
value={state.startDate.value}
onChange={(_e: Array<Date>, selectedDate: string) => {
handleDateChange(true, selectedDate);
Expand All @@ -209,6 +213,7 @@ const CollectionStep = ({ isReview }: CollectionStepProps) => {
datePickerType="single"
dateFormat={DATE_FORMAT}
minDate={state.startDate.value}
maxDate={maxDate}
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 @@ -49,6 +49,9 @@ const ExtractionAndStorage = (
const [isExtractorHintOpen, setIsExtractorHintOpen] = useState<boolean>(true);
const [isStorageHintOpen, setIsStorageHintOpen] = useState<boolean>(true);

const today = new Date();
const maxDate = today.toISOString().split('T')[0].replace(/-/g, '/');

const setAgencyAndCode = (
isDefault: BooleanInputType,
agency: OptionsInputType,
Expand Down Expand Up @@ -133,6 +136,7 @@ const ExtractionAndStorage = (
datePickerType="single"
name="extractionStartDate"
dateFormat={DATE_FORMAT}
maxDate={maxDate}
value={state.extraction.startDate.value}
onChange={(_e: Array<Date>, selectedDate: string) => {
handleDates(true, 'extraction', selectedDate);
Expand All @@ -156,6 +160,7 @@ const ExtractionAndStorage = (
datePickerType="single"
name="extractionEndDate"
dateFormat={DATE_FORMAT}
maxDate={maxDate}
value={state.extraction.endDate.value}
onChange={(_e: Array<Date>, selectedDate: string) => {
handleDates(false, 'extraction', selectedDate);
Expand Down Expand Up @@ -222,6 +227,7 @@ const ExtractionAndStorage = (
datePickerType="single"
name="storageStartDate"
dateFormat={DATE_FORMAT}
maxDate={maxDate}
value={state.seedStorage.startDate.value}
onChange={(_e: Array<Date>, selectedDate: string) => {
handleDates(true, 'seedStorage', selectedDate);
Expand All @@ -245,6 +251,7 @@ const ExtractionAndStorage = (
datePickerType="single"
name="storageEndDate"
dateFormat={DATE_FORMAT}
maxDate={maxDate}
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,6 +48,9 @@ const InterimStep = ({ isReview }:InterimStepProps) => {

const [otherChecked, setOtherChecked] = useState(state.facilityType.value === 'OTH');

const today = new Date();
const maxDate = today.toISOString().split('T')[0].replace(/-/g, '/');

const setAgencyAndCode = (
agencyData: OptionsInputType,
locationCodeData: StringInputType,
Expand Down Expand Up @@ -178,6 +181,7 @@ const InterimStep = ({ isReview }:InterimStepProps) => {
datePickerType="single"
name="startDate"
dateFormat={DATE_FORMAT}
maxDate={maxDate}
value={state.startDate.value}
onChange={(_e: Array<Date>, selectedDate: string) => {
handleStorageDates(true, selectedDate);
Expand All @@ -202,6 +206,7 @@ const InterimStep = ({ isReview }:InterimStepProps) => {
name="endDate"
dateFormat={DATE_FORMAT}
minDate={state.startDate.value}
maxDate={maxDate}
value={state.endDate.value}
onChange={(_e: Array<Date>, selectedDate: string) => {
handleStorageDates(false, selectedDate);
Expand Down

0 comments on commit 4257042

Please sign in to comment.