Birthdays: use maxDate

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-01-25 16:51:15 +01:00
parent e0d7f2dd87
commit 980f5f8ae3
2 changed files with 6 additions and 10 deletions

View file

@ -34,18 +34,14 @@ class EditProfile extends ImmutablePureComponent {
value: PropTypes.instanceOf(Date), 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() { render() {
const { intl, value, onChange, supportsBirthDates, hint, required } = this.props; const { intl, value, onChange, supportsBirthDates, hint, required, minAge } = this.props;
if (!supportsBirthDates) return null; if (!supportsBirthDates) return null;
const maxDate = new Date();
maxDate.setDate(maxDate.getDate() - minAge);
return ( return (
<div className='datepicker'> <div className='datepicker'>
{hint && ( {hint && (
@ -60,7 +56,7 @@ class EditProfile extends ImmutablePureComponent {
wrapperClassName='react-datepicker-wrapper' wrapperClassName='react-datepicker-wrapper'
onChange={onChange} onChange={onChange}
placeholderText={intl.formatMessage(messages.birthDatePlaceholder)} placeholderText={intl.formatMessage(messages.birthDatePlaceholder)}
filterDate={this.isDateValid} maxDate={maxDate}
required={required} required={required}
/> />
</div> </div>

View file

@ -325,7 +325,7 @@ class RegistrationForm extends ImmutablePureComponent {
error={passwordMismatch === true} error={passwordMismatch === true}
required required
/> />
{!birthDateRequired && {birthDateRequired &&
<BirthDateInput <BirthDateInput
value={birthDate} value={birthDate}
onChange={this.onBirthDateChange} onChange={this.onBirthDateChange}