Birthdays: use maxDate

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
improve-ci
marcin mikołajczak 2022-01-25 16:51:15 +01:00
rodzic e0d7f2dd87
commit 980f5f8ae3
2 zmienionych plików z 6 dodań i 10 usunięć

Wyświetl plik

@ -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>

Wyświetl plik

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