2022-01-19 14:59:10 -08:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import DatePicker from 'react-datepicker';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import 'react-datepicker/dist/react-datepicker.css';
|
|
|
|
|
|
|
|
import { getFeatures } from 'soapbox/utils/features';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
2022-01-25 12:09:30 -08:00
|
|
|
birthdayPlaceholder: { id: 'edit_profile.fields.birthday_placeholder', defaultMessage: 'Your birth date' },
|
2022-01-19 14:59:10 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
const features = getFeatures(state.get('instance'));
|
|
|
|
|
|
|
|
return {
|
2022-01-25 12:09:30 -08:00
|
|
|
supportsBirthdays: features.birthdays,
|
2022-01-23 03:53:48 -08:00
|
|
|
minAge: state.getIn(['instance', 'pleroma', 'metadata', 'birthday_min_age']),
|
2022-01-19 14:59:10 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
@injectIntl
|
|
|
|
class EditProfile extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
hint: PropTypes.node,
|
|
|
|
required: PropTypes.bool,
|
2022-01-25 12:09:30 -08:00
|
|
|
supportsBirthdays: PropTypes.bool,
|
2022-01-19 14:59:10 -08:00
|
|
|
minAge: PropTypes.number,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
value: PropTypes.instanceOf(Date),
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2022-01-25 12:09:30 -08:00
|
|
|
const { intl, value, onChange, supportsBirthdays, hint, required, minAge } = this.props;
|
2022-01-19 14:59:10 -08:00
|
|
|
|
2022-01-25 12:09:30 -08:00
|
|
|
if (!supportsBirthdays) return null;
|
2022-01-19 14:59:10 -08:00
|
|
|
|
2022-01-25 23:37:40 -08:00
|
|
|
let maxDate = new Date();
|
|
|
|
maxDate = new Date(maxDate.getTime() - minAge * 1000 * 60 * 60 * 24 + maxDate.getTimezoneOffset() * 1000 * 60);
|
2022-01-25 07:51:15 -08:00
|
|
|
|
2022-01-19 14:59:10 -08:00
|
|
|
return (
|
|
|
|
<div className='datepicker'>
|
|
|
|
{hint && (
|
|
|
|
<div className='datepicker__hint'>
|
|
|
|
{hint}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className='datepicker__input'>
|
|
|
|
<DatePicker
|
|
|
|
selected={value}
|
|
|
|
dateFormat='d MMMM yyyy'
|
|
|
|
wrapperClassName='react-datepicker-wrapper'
|
|
|
|
onChange={onChange}
|
2022-01-25 12:09:30 -08:00
|
|
|
placeholderText={intl.formatMessage(messages.birthdayPlaceholder)}
|
2022-01-25 23:37:40 -08:00
|
|
|
minDate={new Date('1900-01-01')}
|
2022-01-25 07:51:15 -08:00
|
|
|
maxDate={maxDate}
|
2022-01-19 14:59:10 -08:00
|
|
|
required={required}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|