Birthdays: use maxDate
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
e0d7f2dd87
commit
980f5f8ae3
2 changed files with 6 additions and 10 deletions
|
@ -34,18 +34,14 @@ class EditProfile extends ImmutablePureComponent {
|
|||
value: PropTypes.instanceOf(Date),
|
||||
};
|
||||
|
||||
isDateValid = date => {
|
||||
const { minAge } = this.props;
|
||||
const allowedDate = new Date();
|
||||
allowedDate.setDate(allowedDate.getDate() - minAge);
|
||||
return date && allowedDate.setHours(0, 0, 0, 0) >= new Date(date).setHours(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { intl, value, onChange, supportsBirthDates, hint, required } = this.props;
|
||||
const { intl, value, onChange, supportsBirthDates, hint, required, minAge } = this.props;
|
||||
|
||||
if (!supportsBirthDates) return null;
|
||||
|
||||
const maxDate = new Date();
|
||||
maxDate.setDate(maxDate.getDate() - minAge);
|
||||
|
||||
return (
|
||||
<div className='datepicker'>
|
||||
{hint && (
|
||||
|
@ -60,7 +56,7 @@ class EditProfile extends ImmutablePureComponent {
|
|||
wrapperClassName='react-datepicker-wrapper'
|
||||
onChange={onChange}
|
||||
placeholderText={intl.formatMessage(messages.birthDatePlaceholder)}
|
||||
filterDate={this.isDateValid}
|
||||
maxDate={maxDate}
|
||||
required={required}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -325,7 +325,7 @@ class RegistrationForm extends ImmutablePureComponent {
|
|||
error={passwordMismatch === true}
|
||||
required
|
||||
/>
|
||||
{!birthDateRequired &&
|
||||
{birthDateRequired &&
|
||||
<BirthDateInput
|
||||
value={birthDate}
|
||||
onChange={this.onBirthDateChange}
|
||||
|
|
Loading…
Reference in a new issue