import PropTypes from 'prop-types'; import React from 'react'; import { HotKeys } from 'react-hotkeys'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { injectIntl, FormattedMessage } from 'react-intl'; import { connect } from 'react-redux'; import { Link } from 'react-router-dom'; import { fetchBirthdayReminders } from 'soapbox/actions/accounts'; import { openModal } from 'soapbox/actions/modals'; import Icon from 'soapbox/components/icon'; import { makeGetAccount } from 'soapbox/selectors'; const mapStateToProps = (state, props) => { const me = state.get('me'); const getAccount = makeGetAccount(); const birthdays = state.getIn(['user_lists', 'birthday_reminders', me]); if (birthdays?.size > 0) { return { birthdays, account: getAccount(state, birthdays.first()), }; } return { birthdays, }; }; export default @connect(mapStateToProps) @injectIntl class BirthdayReminders extends ImmutablePureComponent { static propTypes = { birthdays: ImmutablePropTypes.orderedSet, intl: PropTypes.object.isRequired, dispatch: PropTypes.func.isRequired, onMoveDown: PropTypes.func, }; componentDidMount() { const { dispatch } = this.props; const date = new Date(); const day = date.getDate(); const month = date.getMonth() + 1; dispatch(fetchBirthdayReminders(day, month)); } getHandlers() { return { open: this.handleOpenBirthdaysModal, moveDown: this.props.onMoveDown, }; } handleOpenBirthdaysModal = () => { const { dispatch } = this.props; dispatch(openModal('BIRTHDAYS')); } renderMessage() { const { birthdays, account } = this.props; const link = ( ); if (birthdays.size === 1) { return ; } return ( ), }} /> ); } renderMessageForScreenReader = () => { const { intl, birthdays, account } = this.props; if (birthdays.size === 1) { return intl.formatMessage({ id: 'notification.birthday', defaultMessage: '{name} has birthday today' }, { name: account.get('display_name') }); } return intl.formatMessage( { id: 'notification.birthday_plural', defaultMessage: '{name} and {more} have birthday today', }, { name: account.get('display_name'), more: intl.formatMessage( { id: 'notification.birthday.more', defaultMessage: '{count} more {count, plural, one {friend} other {friends}}', }, { count: birthdays.size - 1 }, ), }, ); } render() { const { birthdays } = this.props; if (!birthdays || birthdays.size === 0) return null; return (
{this.renderMessage()}
); } }