Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only future date optional prop added to DatePicker #203

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/components/form/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const DatePicker = ({
withTime,
question,
onAnswer,
currentResponse
currentResponse,
onlyFutureTime
}) => {
const [startDate, setStartDate] = useState(
currentResponse ? currentResponse : null
Expand All @@ -36,6 +37,7 @@ export const DatePicker = ({
startDate={startDate}
maxDate={maxDate}
onChange={onChange}
onlyFutureTime={onlyFutureTime}
/>
);
} else {
Expand All @@ -44,6 +46,7 @@ export const DatePicker = ({
startDate={startDate}
maxDate={maxDate}
onChange={onChange}
onlyFutureTime={onlyFutureTime}
/>
);
}
Expand All @@ -57,7 +60,7 @@ export const DatePicker = ({
);
};

const DateOnlyPicker = ({ startDate, maxDate, onChange }) => {
const DateOnlyPicker = ({ startDate, maxDate, onChange, onlyFutureTime }) => {
Copy link
Member

@surdu surdu Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be more flexible to have it as a minDate prop instead ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used another field due to requirements. @aniri said that it should be a property set to true / false.
minDate should be a Date not a Bool by definition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that she meant the property in the question entry. This shouldn't be to different from what is already implemented for allowFuture in the previous link.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my mistake,. I will rework the code tonight.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, @surdu is right, sorry for the confusion. as I mentioned in #173 , the implementation should be similar to the one for allowFuture

return (
<ReactDatePicker
customInput={<CustomInput />}
Expand All @@ -67,11 +70,12 @@ const DateOnlyPicker = ({ startDate, maxDate, onChange }) => {
locale={ro}
dateFormat={"d MMMM yyyy"}
maxDate={maxDate}
minDate={onlyFutureTime ? new Date() : null}
/>
);
};

const DateTimePicker = ({ startDate, maxDate, onChange }) => {
const DateTimePicker = ({ startDate, maxDate, onChange, onlyFutureTime }) => {
const computeMinTime = (date) => {
if (!maxDate) {
return;
Expand Down Expand Up @@ -120,6 +124,7 @@ const DateTimePicker = ({ startDate, maxDate, onChange }) => {
maxDate={maxDate}
minTime={minTime}
maxTime={maxTime}
minDate={onlyFutureTime ? new Date() : null}
/>
);
};
Expand Down Expand Up @@ -152,17 +157,20 @@ DatePicker.propTypes = {
allowFuture: PropTypes.bool
}),
onAnswer: PropTypes.func,
currentResponse: PropTypes.object
currentResponse: PropTypes.object,
onlyFutureTime: PropTypes.bool
};

DateTimePicker.propTypes = {
startDate: PropTypes.object,
maxDate: PropTypes.instanceOf(Date),
onChange: PropTypes.func.isRequired
onChange: PropTypes.func.isRequired,
onlyFutureTime: PropTypes.bool
};

DateOnlyPicker.propTypes = {
startDate: PropTypes.object,
maxDate: PropTypes.instanceOf(Date),
onChange: PropTypes.func.isRequired
onChange: PropTypes.func.isRequired,
onlyFutureTime: PropTypes.bool
};